Thanks Jeremy. That worked!
But we now have information about the same node being replicated. For
instance, let's say we have a field 'weight' attached to each node as
shown below. This setup will replicate the weight information of a
node as many times as its degree. If the weight of a node changes, I
will have update all it's occurrences in the PB. Any way I can avoid
it?
package graph;
option java_package = "graph";
option java_outer_classname = "UndirectedGraphType";
option optimize_for = CODE_SIZE;
message UndirectedGraphNodeReference {
required string id = 1;
required double weight = 2;
}
message UndirectedGraphNode {
required string id = 1;
repeated UndirectedGraphNodeReference neighbors = 2;
}
message UndirectedGraph {
repeated UndirectedGraphNode nodes = 1;
}
On Oct 21, 6:37 pm, Jeremy Leader <
jlea...@oversee.net> wrote:
> 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
>
jlea...@oversee.net