3 ms·
IMO the advantages of protos are mostly related to having firmer typing on your data e.g. instead of writing myJsonPayload["magic string foo"][["magic string b
by Rebelgecko 4y ago
IMO the advantages of protos are mostly related to having firmer typing on your data
e.g. instead of writing myJsonPayload["magic string foo"][["magic string bae"], you call methods that actually exist like myMsg.getFoo().getBar(). This is especially helpful if someone who isn't you personally is also writing code that interacts with the data. I suppose that can slow down iteration, but for a decent sized project IMO it's a worthy tradeoff.
Another benefit is having nonhacky representations of numbers that don't exist in standard-compliant JSON, like 0 and infinity. It's also handy to be able to embed comments in your data, which wasn't doable last time I used JSON.
- chii 4y agohow do you embed comments in protocolbuf data? It's binary! And if you are adding a field specifically for comments, you could do the same in json. For example, a field that has a question mark as the prefix is a comment field (a convention i like). The advantage of protocol buf is, i think, the version being built in. You can make it backwards compatible to older clients. While the same could be done in json, it's manual and requires work and careful design.
- Rebelgecko 4y ago>how do you embed comments in protocolbuf data? It's binary! In addition to the binary format, every proto message can also be represented in a human readable form[1]. This is not as efficient and probably not a good idea for data being sent over the wire as-is.. especially if it is only being written and read by computers. However if you have small amounts of data at rest (like input for a unit test) it can be handy to add some comments explaining anything non-obvious. On top of that, the proto's schema itself can have comments, and those comments can trickle down into the code generation for a given language so that you can read them when working with your messages. Maybe that's also possible with JSON schemas but idk what their tooling ecosystem is like [1]: https://developers.google.com/protocol-buffers/docs/text-format-spec https://developers.google.com/protocol-buffers/docs/text-for...
- 8n4vidtmkvmk 4y agoprototext supports comments. useful for test data and configurations
- bee_rider 4y agoI haven't worked with JSON, so this is probably a dumb question, but... 0 is not a number in standard-compliant JSON? Who what where when why how?
- Rebelgecko 4y agoWhoops, that was a brainfart on my part. I was thinking of NaN, not 0.
- 8n4vidtmkvmk 4y ago0 is valid, it works fine. maybe not negative 0 (which exists in js)