views:

83

answers:

1

I am looking into thrift for serialization of data. But Document says

cyclic structs - Structs can only contain structs that have been declared before it. A struct also cannot contain itself

One of our requirement is

  • Struct A
    • List of Child items
      • Items(Items are Struct A )

So reading requirement i can't have Struct within itself at any level? can i have it in cyclic model as i have it above. Struct is not member of Struct directly but it has some other member and it contains struct.

Their document is not so well descriptive.

Is it possible in Thrift? Does protobuf supports it?

+1  A: 

According to this discussion, it's not possible in Thrift. However, there is a workaround of using integers to index into a master list. Essentially, this is a form of poor man's pointers.

struct A 
{ 
1: list<i32> subitems; 
}

struct AllAs 
{ 
1: list<A> items; 
} 

subitems is essentially a list of pointers into AllAs.items

In Protocol Buffers, it's trivial:

message A {
    repeated A subitems = 1; 
}
Matthew Flaschen

related questions