Keep in mind that protobufs describe serialized data, and there's no 
concept of an object reference like Java uses.  In your example, if A 
and B are neighbors, then in your proto, the data representing A 
contains the data representing B, and the data representing B contains 
the data representing A!

One way around this is to implement your own form of references, perhaps 
using the node ids like this:

package graph;

option java_package = "graph";
option java_outer_classname = "UndirectedGraph";
option optimize_for = CODE_SIZE;

message UndirectedGraphNodeReference {
   required string id = 0;
}

message UndirectedGraphNode {
   required string id = 0;
   repeated UndirectedGraphNodeReference neighbors;
}

message UndirectedGraph {
   repeated UndirectedGraphNode nodes;
}

-- 
Jeremy Leader
[EMAIL PROTECTED]

GDR wrote:
> Hi,
> 
> I'm wondering how would one go about implementing self-referential
> data structures?  As an exercise, I tried to implement a PB version of
> the adjacency list representation of a graph. I'm having a hard time
> getting it work. Any suggestions?
> 
> Thanks!
> 
> --- graph.proto ---
> 
> package graph;
> 
> option java_package = "graph";
> option java_outer_classname = "UndirectedGraph";
> option optimize_for = CODE_SIZE;
> 
> message UndirectedGraphNode {
>   required string id = 0;
>   repeated UndirectedGraphNode neighbors;
> }
> 
> message UndirectedGraph {
>   repeated UndirectedGraphNode nodes;
> }
> 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to