4 ms·
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 ea
by jleader 15y ago
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.html#self-description http://code.google.com/apis/protocolbuffers/docs/techniques.... for details.
- sigil 15y agoIndeed. 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/google/protobuf/descriptor.proto http://code.google.com/p/protobuf/source/browse/trunk/src/go... [2] https://github.com/acg/lwpb https://github.com/acg/lwpb [3] https://github.com/haberman/upb https://github.com/haberman/upb