4 ms·
I like to use Protobuf in my server code, but then support JSON _or_ Protobuf as the encoding. So browsers can continue to use JSON, but the server gets strong
by justinsb 11y ago
I like to use Protobuf in my server code, but then support JSON _or_ Protobuf as the encoding. So browsers can continue to use JSON, but the server gets strongly-typed Protobuf structures.
- PaulHoule 11y agoYeah, if you are using a statically typed language, binary formats like Protobuf are a big win, but if you are going to have the dynamic language overheard that comes with JS, there isn't much gain to be had from binary formats.
- edgarvm 11y agoWhich library do you use to support both?
- justinsb 11y agoOne I rolled myself (https://github.com/fathomdb/cloud/tree/master/fathomcloud-common/src/main/java/io/fathom/cloud/protobuf https://github.com/fathomdb/cloud/tree/master/fathomcloud-co...), but I'm switching to proto3.
- haberman 11y agoWhat you describe is exactly how proto3, the latest version of protobuf, will work! proto3 supports both binary protobuf encoding and JSON natively, so you can switch between them as desired. https://developers.google.com/protocol-buffers/docs/proto3 https://developers.google.com/protocol-buffers/docs/proto3 proto3 is currently in alpha, but we are working to bring it closer to release (I work on the protobuf team at Google).
- hesdeadjim 11y agoOh cool, didn't know there was a new version of protocol buffers. I ended up choosing Thrift for my current project due to wider language support, but I have been frustrated with some the limitations of the IDL (primarily no recursive data structures, so no generic storage of JSON-like objects).
- haberman 11y agoAnother one of the goals of proto3 is to increase language support a lot. Just this year we have added Ruby, Objective C, and C#, and keep your eyes peeled for more. proto3 is still alpha, but this is the direction things are going. proto3 is especially designed to be paired with gRPC, which is also in alpha but also going for wide language support: http://www.grpc.io/ http://www.grpc.io/