Re:Protocol Buffers, Avro, Thrift & MessagePack
by jleader on Monday August 01, 2011 @05:35PM
(#2834601)
There's a way to encode a protobuf schema in a protobuf message, making it possible to send self-describing messages (i.e. include a serialized schema before each message). I'm not sure if anyone actually does this. See http://code.google.com/apis/protocolbuffers/docs/techniques.... for details.
[ Parent
| on HN ]
Re:Protocol Buffers, Avro, Thrift & MessagePack
by sigil on Monday August 01, 2011 @06:04PM
(#2834726)
Indeed. Here's how from the command line:
protoc -o schema.pb schema.proto
The meta-schema for compiled .proto files can be found here [1]. In fact, I know of several protobuf implementations [2] [3] that avoid parsing .proto files by working with their compiled message form.I use protobuf as a storage format for record streams. It's nice for binary data (documents, images, thumbnails, etc) where JSON string escaping would be wasteful. Each protobuf record in the file is preceded by a length and a magic number specifying record type, and the first record in the file embeds the compiled .proto schema.
This means it's possible to read and work with a record stream without specifying the schema separately, and without generating any code.
Disclaimer: I'm the author of the lwpb Python protobuf library.
[1] http://code.google.com/p/protobuf/source/browse/trunk/src/go...