bluetooth_gatt_attribute_helpers.cc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "device/bluetooth/dbus/bluetooth_gatt_attribute_helpers.h"
  5. #include <string>
  6. #include "dbus/message.h"
  7. #include "dbus/object_path.h"
  8. namespace bluez {
  9. bool ReadOptions(dbus::MessageReader* reader,
  10. std::map<std::string, dbus::MessageReader>* options) {
  11. dbus::MessageReader array_reader(nullptr);
  12. if (!reader->PopArray(&array_reader) || options == nullptr)
  13. return false;
  14. dbus::MessageReader dict_entry_reader(nullptr);
  15. std::string key;
  16. while (array_reader.HasMoreData()) {
  17. if (!array_reader.PopDictEntry(&dict_entry_reader) ||
  18. !dict_entry_reader.PopString(&key)) {
  19. options->clear();
  20. return false;
  21. }
  22. options->emplace(key, nullptr);
  23. if (!dict_entry_reader.PopVariant(&options->at(key))) {
  24. options->clear();
  25. return false;
  26. }
  27. }
  28. return true;
  29. }
  30. } // namespace bluez