To store a DAG (or a cyclic graph, for that matter) you would need to come
up with some sort of identifier system for objects and then refer to objects
by their identifier instead, so that multiple locations can refer to the
same object without copying it.  Example:
  message Graph {
    repeated Node node = 1;

  message Node {
    // Indexes of children within the containing graph.
    repeated int32 child = 1;

Or maybe:

  message Node {
    required int32 id = 1;
    repeated int32 child_id = 2;

Using ids like this makes it easier to remove nodes from the graph but makes
it harder to look up children (you'd need to maintain a separate lookup

To store multiple types, you'd either have to make Node extendable or you'd
have to have a separate repeated field in Graph for each type.

Yeah, it's not as easy as Java serialization, but it will be much faster and

On Wed, Mar 25, 2009 at 3:04 PM, <> wrote:

> I have an application in which I serialise graphs of Java objects and
> store them to disk.
> These graphs can be quite deep.  However, they will never contain
> cycles and all the objects in them will always be pure value
> objects.
> The set of classes that need to be stored does have to be able to grow
> over the lifetime of the persistence storage.  However its not a
> requirement for existing graph types to be able to support new subnode
> types via polymorphism.  That is, the set of types that can be stored
> beneath a particular root object type are fixed, new types of value
> objects will only ever be added under new root types.
> The application needs to store these graphs quickly and compactly.
> Currently it's using Java serialisation.  However because Java
> serialisation is intended to support full polymorphism it uses a lot
> of space storing classname information, which for this application is
> redundant.  It seems like Protocol Buffers might be useful here but
> storing complex graphs of objects using protocol buffers looks
> unwieldy and error prone.
> I was just wondering whether anyone has had experience using PB for
> storing complex graphs of objects.
> Thanks,
> Paul
> >

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

Reply via email to