Hacker News new | ask | show | jobs
by pantalaimon 2374 days ago
This gets hairy the moment you want to add new fields.
2 comments

Both protobuf and plain C structs are append only formats if you put the message-type and size at the start of the C-struct.
C structs do not compose extensively. Protobufs do. You can't put variable length data into a struct, and hence you can't put extensible structs into it either.
You can put variable length data into a struct:

https://en.wikipedia.org/wiki/Flexible_array_member

Only one field can be variable length, and it must be last. I'll pass.
You definitely can but it's not as obvious, make a separate message type for list elements and append them on the wire. If you only have one list at the tail, you can use a flexible array[] at the end but it's finicky to deal with if you need more than one.

You can build large hierarchical structures of messages with lists contained therein. It's pretty much how .mov/.mp4/many, many media container formats work. The technique dates back to the Amiga days.

Yeah I know that pain, there needs to be a consistent header with a version in all the messages.