Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor

...

Option 1: Struct encoding

Protobuf ships with a file, described Struct message, defined in struct.proto, that can be recursively nested to encode JSON.

...

Code Block
class User {
  String name;
  int age;
}

value = new User("Amy", 4464);

would encode as (using a pseudo-static initializer syntax):

...

Code Block
languagejava
collapsetrue
class User {
  String name;
  int age;
}

value = new User("Amy", 4464);

the client would send the following messages to register the type (definitions below):

Code Block
TypeRegistrationRequest{
  typeDefinition: ValueTypeDefinition{
    typeName: "User",
    definition: [
      ValueTypeFieldDefinition{
        fieldName: "name",
        fieldType: stringField
      },
      ValueTypeFieldDefinition{
        fieldName: "age",
        fieldType: intField
      },
    ]
  }
}
    

which might get a `TypeRegistrationResponse` with an ID of 42.

...

Code Block
GetRequest{
  key: EncodedValue{intValue: 111},
  value: EncodedValue{
    structValue: Value{
      id: 42,
      fields: [
        ValueField{stringField: "Amy"},
        ValueField{intField: 4464}
      ]
    }
  }
}

Message Definitions 
Anchor
message-definitions
message-definitions

...