Recursive data structures in Protocol Buffers, Apache Thrift or any other Data structure serialization protocol?

3.1k views Asked by At

I have enough theoretical knowledge about the Protocol Buffers, Apache Thrift and about other Data Structure serialization protocols. My questionis that if i need to define a recursive data structure(Linked Lists, Search Trees etc..) or some relationship between different objects, is there any built in standard way Protocol Buffers or Apache Thrift provides to set a link between different structures (we use pointers in normal programming practice)? or we have to continue like using pointers to make a link between different Data structure objects ?

I want to do it with C++ API

Thank you in Advance! :)

2

There are 2 answers

1
Alan Stokes On BEST ANSWER

Both allow a message of type X to contain other messages of type X, neither allows a message to contain itself (unlike, say, Java serialisation). Doing otherwise would be very expensive for an unusual case.

But don't send your actual data model over either; instead work out your own efficient wire representation and use the serialisation protocol to transport it.

0
wvxvw On

I know this is million years old, but here's something: AMF (ActionScript Message Format). And, before you run away screaming into the night... It's not really that bad. And, unlike the more popular ones it can do circular references, no problem there. Many moons ago I wrote a decoder for this format. In the heydays of Flash there used to be implementations for some other languages, if memory serves, there were two or three Java libraries, a Python library, a PHP one, a .NET one, maybe more. There also was one written in C.

The format itself may be seen as a superset of JSON, even though it appeared long before it. It was intended for serializing a language derived from JavaScrip, but with some type annotations, so it had some sort of typing constraints. Its human-readable form is the ActionScript code (very similar to JavaScript with some extra keywords related to type annotations). The specification is open and can be found here: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/amf/pdf/amf-file-format-spec.pdf