buffet: Added PropValue <-> DBus Variant (Any) conversion
GCD object schema has been used predominantly with JSON values.
Now in order to make it easier to enable GCD data transfer over
D-Bus, we need to have more comprehensive utilities to marshal
GCD data over D-Bus. Specifically, GCD Object type should be sent
over D-Bus as "a{sv}".
Added PropValueToDBusVariant() and PropValueFromDBusVariant() to
convert between D-Bus types and GCD object schema types.
BUG=chromium:415364
TEST=FEATURES=test emerge-link buffet
Change-Id: Ib9feae3a12b499e6a196cb22d2f9736bb824afbe
Reviewed-on: https://chromium-review.googlesource.com/219136
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/schema_utils.h b/buffet/commands/schema_utils.h
index 3f84b19..a05d080 100644
--- a/buffet/commands/schema_utils.h
+++ b/buffet/commands/schema_utils.h
@@ -13,10 +13,12 @@
#include <vector>
#include <base/values.h>
+#include <chromeos/any.h>
#include <chromeos/errors/error.h>
namespace buffet {
+class PropType;
class PropValue;
class ObjectSchema;
@@ -70,7 +72,7 @@
return std::move(list);
}
-// Similarly to CreateTypedValue() function above, the following overloaded
+// Similarly to TypedValueToJson() function above, the following overloaded
// helper methods allow to extract specific C++ data types from base::Value.
// Also used in template classes below to simplify specialization logic.
bool TypedValueFromJson(const base::Value* value_in,
@@ -116,6 +118,18 @@
return std::abs(v1 - v2) <= std::numeric_limits<T>::epsilon();
}
+// Converts PropValue to Any in a format understood by D-Bus data serialization.
+// Has special handling for Object types where native_types::Object are
+// converted to chromeos::dbus_utils::Dictionary.
+chromeos::Any PropValueToDBusVariant(const PropValue* value);
+// Converts D-Bus variant to PropValue.
+// Has special handling for Object types where chromeos::dbus_utils::Dictionary
+// is converted to native_types::Object.
+std::shared_ptr<const PropValue> PropValueFromDBusVariant(
+ const PropType* type,
+ const chromeos::Any& value,
+ chromeos::ErrorPtr* error);
+
} // namespace buffet
#endif // BUFFET_COMMANDS_SCHEMA_UTILS_H_