Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Unified Diff: dbus/property.cc

Issue 2421713002: arc: bluetooth: Expose missing advertise data. (Closed)
Patch Set: Add BlueZ unittests / more comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/property.h ('k') | dbus/property_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/property.cc
diff --git a/dbus/property.cc b/dbus/property.cc
index 0ac65ef6991641d523fdd7f8b43ca045b44844e5..0351c4a59ac2ae79d747853a241483bf6d74745d 100644
--- a/dbus/property.cc
+++ b/dbus/property.cc
@@ -662,7 +662,7 @@ void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>::
}
//
-// Property<std::map<std::string, std::vector<uint8_t>>>
+// Property<std::unordered_map<std::string, std::vector<uint8_t>>>
// specialization.
//
@@ -725,6 +725,70 @@ void Property<std::unordered_map<std::string, std::vector<uint8_t>>>::
writer->CloseContainer(&variant_writer);
}
+//
+// Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>
+// specialization.
+//
+
+template <>
+bool Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ PopValueFromReader(MessageReader* reader) {
+ MessageReader variant_reader(nullptr);
+ MessageReader dict_reader(nullptr);
+ if (!reader->PopVariant(&variant_reader) ||
+ !variant_reader.PopArray(&dict_reader))
+ return false;
+
+ value_.clear();
+ while (dict_reader.HasMoreData()) {
+ MessageReader entry_reader(nullptr);
+ if (!dict_reader.PopDictEntry(&entry_reader))
+ return false;
+
+ uint16_t key;
+ MessageReader value_varient_reader(nullptr);
+ if (!entry_reader.PopUint16(&key) ||
+ !entry_reader.PopVariant(&value_varient_reader))
+ return false;
+
+ const uint8_t* bytes = nullptr;
+ 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::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ AppendSetValueToWriter(MessageWriter* writer) {
+ MessageWriter variant_writer(nullptr);
+ MessageWriter dict_writer(nullptr);
+
+ writer->OpenVariant("a{qv}", &variant_writer);
+ variant_writer.OpenArray("{qv}", &dict_writer);
+
+ for (const auto& pair : set_value_) {
+ MessageWriter entry_writer(nullptr);
+ dict_writer.OpenDictEntry(&entry_writer);
+
+ entry_writer.AppendUint16(pair.first);
+
+ MessageWriter value_varient_writer(nullptr);
+ 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>;
@@ -742,5 +806,6 @@ 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::unordered_map<std::string, std::vector<uint8_t>>>;
+template class Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>;
} // namespace dbus
« no previous file with comments | « dbus/property.h ('k') | dbus/property_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698