Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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...

[2] https://github.com/acg/lwpb

[3] https://github.com/haberman/upb




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: