Commit d30d7bfe authored by Dan McArdle's avatar Dan McArdle Committed by Commit Bot

Make json_proto::JsonObject contain arbitrary number of fields

Change-Id: I7c6ea9c7742d67d0e2eb0d365757558818001a3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418987
Commit-Queue: Dan McArdle <dmcardle@chromium.org>
Reviewed-by: default avatarJonathan Metzman <metzman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810218}
parent a456ad8d
...@@ -9,11 +9,15 @@ syntax = "proto2"; ...@@ -9,11 +9,15 @@ syntax = "proto2";
package json_proto; package json_proto;
message JsonObject { message JsonObjectField {
required string name = 1; required string name = 1;
required JsonValue value = 2; required JsonValue value = 2;
} }
message JsonObject {
repeated JsonObjectField field = 3;
}
message JsonValue { message JsonValue {
oneof value { oneof value {
// Json value types: // Json value types:
......
...@@ -40,8 +40,16 @@ void JsonProtoConverter::AppendNumber(const NumberValue& number_value) { ...@@ -40,8 +40,16 @@ void JsonProtoConverter::AppendNumber(const NumberValue& number_value) {
} }
void JsonProtoConverter::AppendObject(const JsonObject& json_object) { void JsonProtoConverter::AppendObject(const JsonObject& json_object) {
data_ << '{' << '"' << json_object.name() << '"' << ':'; data_ << '{';
AppendValue(json_object.value()); bool leading_comma = false;
for (const auto& field : json_object.field()) {
if (leading_comma) {
data_ << ",";
}
leading_comma = true;
data_ << '"' << field.name() << '"' << ':';
AppendValue(field.value());
}
data_ << '}'; data_ << '}';
} }
......
...@@ -14,6 +14,7 @@ namespace json_proto { ...@@ -14,6 +14,7 @@ namespace json_proto {
class JsonProtoConverter { class JsonProtoConverter {
public: public:
std::string Convert(const JsonValue& json_value);
std::string Convert(const json_proto::JsonObject&); std::string Convert(const json_proto::JsonObject&);
std::string Convert(const json_proto::ArrayValue&); std::string Convert(const json_proto::ArrayValue&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment