Chromium Code Reviews| Index: dbus/property.cc |
| diff --git a/dbus/property.cc b/dbus/property.cc |
| index faca4a0a1d76dd1d902c9da4353a2580d7bc524d..8b451f7c1d46038f0d8038edb395626cda7ab2f1 100644 |
| --- a/dbus/property.cc |
| +++ b/dbus/property.cc |
| @@ -6,6 +6,8 @@ |
| #include <stddef.h> |
| +#include <memory> |
| + |
| #include "base/bind.h" |
| #include "base/logging.h" |
| @@ -659,6 +661,70 @@ void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>:: |
| writer->CloseContainer(&variant_writer); |
| } |
| +// |
| +// Property<std::map<std::string, std::vector<uint8_t>>> |
| +// specialization. |
| +// |
| + |
| +template <> |
| +bool Property<std::map<std::string, std::vector<uint8_t>>>::PopValueFromReader( |
| + MessageReader* reader) { |
| + MessageReader variant_reader(NULL); |
|
hashimoto
2016/09/28 04:22:56
Please use nullptr instead of NULL.
The same goes
puthik_chromium
2016/10/05 00:11:33
Done.
I saw the existing code above use NULL and I
|
| + MessageReader dict_reader(NULL); |
| + if (!reader->PopVariant(&variant_reader) || |
| + !variant_reader.PopArray(&dict_reader)) |
| + return false; |
| + |
| + value_.clear(); |
| + while (dict_reader.HasMoreData()) { |
| + MessageReader entry_reader(NULL); |
| + if (!dict_reader.PopDictEntry(&entry_reader)) |
| + return false; |
| + |
| + std::string key; |
| + MessageReader value_varient_reader(NULL); |
| + if (!entry_reader.PopString(&key) || |
| + !entry_reader.PopVariant(&value_varient_reader)) |
| + return false; |
| + |
| + const uint8_t* bytes = NULL; |
| + size_t length = 0; |
| + if (!value_varient_reader.PopArrayOfBytes(&bytes, &length)) |
| + return false; |
| + |
| + value_[key].assign(bytes, bytes + length); |
| + } |
| + return true; |
| +} |
| + |
| +template <> |
| +void Property<std::map<std::string, std::vector<uint8_t>>>:: |
| + AppendSetValueToWriter(MessageWriter* writer) { |
| + MessageWriter variant_writer(NULL); |
| + MessageWriter dict_writer(NULL); |
| + |
| + writer->OpenVariant("a{sv}", &variant_writer); |
| + variant_writer.OpenArray("{sv}", &dict_writer); |
| + |
| + for (const auto& pair : set_value_) { |
| + MessageWriter entry_writer(NULL); |
| + dict_writer.OpenDictEntry(&entry_writer); |
| + |
| + entry_writer.AppendString(pair.first); |
| + |
| + MessageWriter value_varient_writer(NULL); |
| + entry_writer.OpenVariant("ay", &value_varient_writer); |
| + value_varient_writer.AppendArrayOfBytes(pair.second.data(), |
| + pair.second.size()); |
| + entry_writer.CloseContainer(&value_varient_writer); |
| + |
| + dict_writer.CloseContainer(&entry_writer); |
| + } |
| + |
| + variant_writer.CloseContainer(&dict_writer); |
| + writer->CloseContainer(&variant_writer); |
| +} |
| + |
| template class Property<uint8_t>; |
| template class Property<bool>; |
| template class Property<int16_t>; |
| @@ -675,5 +741,6 @@ template class Property<std::vector<ObjectPath> >; |
| template class Property<std::vector<uint8_t>>; |
| template class Property<std::map<std::string, std::string>>; |
| template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>; |
| +template class Property<std::map<std::string, std::vector<uint8_t>>>; |
| } // namespace dbus |