> A standard protocol buffer message type ptr_B from which a "flat" Java
> class will be generated does not seem adequat to to so.
> Instead some new abstract Class "RefMessage<T extends Message>" with a
> method "<T> getReferencedObject()" would be the solution. ptr_X
> messages simply had to be transformed to Java classes extending this
> superclass.
> My questions so far:
> I could write my own code generator for that purpose, right?
> Has anybody tried to implement some similar techniques for reference
> types on top of protocol buffer?
> Is there a completely different approach for this "problem"?
> Am i getting the design and purpose of protobuf wrong when I need/want
> such a solution?

When I've seen a similar thing done, it's generally been done like this:

message A {
  required int32 ownvalue = 1;
  required int32 bref = 2;

message B {
  required int32 othervalue = 1;

message Overall {
  repeated B b = 1;
  repeated A a = 2;

And then you do

Overall overall;
A a;
B b = overall.getB(a.getBref());

Basically, you first send a lookup table, then you send the remaining
items, with references as indexes into the table.  To serialize a
graph using that technique, you could send a list of nodes and then a
list of edges.  I don't know that it's the best way of doing it, but
it's worked out well where I've seen it.

- Adam


You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to