Recursive Structures in protobuffers

11,708 views
Skip to first unread message

pbjson

unread,
Jul 19, 2013, 7:41:30 PM7/19/13
to prot...@googlegroups.com

Hello,

Has anyone seen the following structure in protobuffer?


message KeyValue{

 required string key=1;
 optional string  value=2;
 optional KeyValue key_value=10;

}

this is a circular reference and how would you resolve this if you have convert this to a flat structure of primitives for eg: to be converted to a hive schema.

eg: keyvalue<key:string,value string, key_value:string>

Has anyone come across such a situation and any better way to do this?

Thanks in advance.

Marc Gravell

unread,
Jul 20, 2013, 3:49:37 AM7/20/13
to pbjson, prot...@googlegroups.com
Protobuf supports recursive schemes - but note that each object is separate (it is a tree, not a graph). For example, descriptor.proto includes the self-referential "DescriptorProto" (which is a "message" in language terms)

// Describes a message type.
message DescriptorProto {
  optional string name = 1;

  repeated FieldDescriptorProto field = 2;
  repeated FieldDescriptorProto extension = 6;

  repeated DescriptorProto nested_type = 3;
  repeated EnumDescriptorProto enum_type = 4;

  message ExtensionRange {
    optional int32 start = 1;
    optional int32 end = 2;
  }
  repeated ExtensionRange extension_range = 5;

  optional MessageOptions options = 7;
}

Marc
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages