OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "dbus/property.h" | 5 #include "dbus/property.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), | 655 struct_writer.AppendArrayOfBytes(std::get<0>(pair).data(), |
656 std::get<0>(pair).size()); | 656 std::get<0>(pair).size()); |
657 struct_writer.AppendUint16(std::get<1>(pair)); | 657 struct_writer.AppendUint16(std::get<1>(pair)); |
658 array_writer.CloseContainer(&struct_writer); | 658 array_writer.CloseContainer(&struct_writer); |
659 } | 659 } |
660 variant_writer.CloseContainer(&array_writer); | 660 variant_writer.CloseContainer(&array_writer); |
661 writer->CloseContainer(&variant_writer); | 661 writer->CloseContainer(&variant_writer); |
662 } | 662 } |
663 | 663 |
664 // | 664 // |
665 // Property<std::map<std::string, std::vector<uint8_t>>> | 665 // Property<std::unordered_map<std::string, std::vector<uint8_t>>> |
666 // specialization. | 666 // specialization. |
667 // | 667 // |
668 | 668 |
669 template <> | 669 template <> |
670 bool Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: | 670 bool Property<std::unordered_map<std::string, std::vector<uint8_t>>>:: |
671 PopValueFromReader(MessageReader* reader) { | 671 PopValueFromReader(MessageReader* reader) { |
672 MessageReader variant_reader(nullptr); | 672 MessageReader variant_reader(nullptr); |
673 MessageReader dict_reader(nullptr); | 673 MessageReader dict_reader(nullptr); |
674 if (!reader->PopVariant(&variant_reader) || | 674 if (!reader->PopVariant(&variant_reader) || |
675 !variant_reader.PopArray(&dict_reader)) | 675 !variant_reader.PopArray(&dict_reader)) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 pair.second.size()); | 718 pair.second.size()); |
719 entry_writer.CloseContainer(&value_varient_writer); | 719 entry_writer.CloseContainer(&value_varient_writer); |
720 | 720 |
721 dict_writer.CloseContainer(&entry_writer); | 721 dict_writer.CloseContainer(&entry_writer); |
722 } | 722 } |
723 | 723 |
724 variant_writer.CloseContainer(&dict_writer); | 724 variant_writer.CloseContainer(&dict_writer); |
725 writer->CloseContainer(&variant_writer); | 725 writer->CloseContainer(&variant_writer); |
726 } | 726 } |
727 | 727 |
| 728 // |
| 729 // Property<std::unordered_map<uint16_t, std::vector<uint8_t>>> |
| 730 // specialization. |
| 731 // |
| 732 |
| 733 template <> |
| 734 bool Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>:: |
| 735 PopValueFromReader(MessageReader* reader) { |
| 736 MessageReader variant_reader(nullptr); |
| 737 MessageReader dict_reader(nullptr); |
| 738 if (!reader->PopVariant(&variant_reader) || |
| 739 !variant_reader.PopArray(&dict_reader)) |
| 740 return false; |
| 741 |
| 742 value_.clear(); |
| 743 while (dict_reader.HasMoreData()) { |
| 744 MessageReader entry_reader(nullptr); |
| 745 if (!dict_reader.PopDictEntry(&entry_reader)) |
| 746 return false; |
| 747 |
| 748 uint16_t key; |
| 749 MessageReader value_varient_reader(nullptr); |
| 750 if (!entry_reader.PopUint16(&key) || |
| 751 !entry_reader.PopVariant(&value_varient_reader)) |
| 752 return false; |
| 753 |
| 754 const uint8_t* bytes = nullptr; |
| 755 size_t length = 0; |
| 756 if (!value_varient_reader.PopArrayOfBytes(&bytes, &length)) |
| 757 return false; |
| 758 |
| 759 value_[key].assign(bytes, bytes + length); |
| 760 } |
| 761 return true; |
| 762 } |
| 763 |
| 764 template <> |
| 765 void Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>:: |
| 766 AppendSetValueToWriter(MessageWriter* writer) { |
| 767 MessageWriter variant_writer(nullptr); |
| 768 MessageWriter dict_writer(nullptr); |
| 769 |
| 770 writer->OpenVariant("a{qv}", &variant_writer); |
| 771 variant_writer.OpenArray("{qv}", &dict_writer); |
| 772 |
| 773 for (const auto& pair : set_value_) { |
| 774 MessageWriter entry_writer(nullptr); |
| 775 dict_writer.OpenDictEntry(&entry_writer); |
| 776 |
| 777 entry_writer.AppendUint16(pair.first); |
| 778 |
| 779 MessageWriter value_varient_writer(nullptr); |
| 780 entry_writer.OpenVariant("ay", &value_varient_writer); |
| 781 value_varient_writer.AppendArrayOfBytes(pair.second.data(), |
| 782 pair.second.size()); |
| 783 entry_writer.CloseContainer(&value_varient_writer); |
| 784 |
| 785 dict_writer.CloseContainer(&entry_writer); |
| 786 } |
| 787 |
| 788 variant_writer.CloseContainer(&dict_writer); |
| 789 writer->CloseContainer(&variant_writer); |
| 790 } |
| 791 |
728 template class Property<uint8_t>; | 792 template class Property<uint8_t>; |
729 template class Property<bool>; | 793 template class Property<bool>; |
730 template class Property<int16_t>; | 794 template class Property<int16_t>; |
731 template class Property<uint16_t>; | 795 template class Property<uint16_t>; |
732 template class Property<int32_t>; | 796 template class Property<int32_t>; |
733 template class Property<uint32_t>; | 797 template class Property<uint32_t>; |
734 template class Property<int64_t>; | 798 template class Property<int64_t>; |
735 template class Property<uint64_t>; | 799 template class Property<uint64_t>; |
736 template class Property<double>; | 800 template class Property<double>; |
737 template class Property<std::string>; | 801 template class Property<std::string>; |
738 template class Property<ObjectPath>; | 802 template class Property<ObjectPath>; |
739 template class Property<std::vector<std::string> >; | 803 template class Property<std::vector<std::string> >; |
740 template class Property<std::vector<ObjectPath> >; | 804 template class Property<std::vector<ObjectPath> >; |
741 template class Property<std::vector<uint8_t>>; | 805 template class Property<std::vector<uint8_t>>; |
742 template class Property<std::map<std::string, std::string>>; | 806 template class Property<std::map<std::string, std::string>>; |
743 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; | 807 template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
744 template class Property<std::unordered_map<std::string, std::vector<uint8_t>>>; | 808 template class Property<std::unordered_map<std::string, std::vector<uint8_t>>>; |
| 809 template class Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>; |
745 | 810 |
746 } // namespace dbus | 811 } // namespace dbus |
OLD | NEW |