3 ms·
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.
by CoolGuySteve 7y ago
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.
- marcan_42 7y agoC 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.
- doublement 7y agoYou can put variable length data into a struct: https://en.wikipedia.org/wiki/Flexible_array_member https://en.wikipedia.org/wiki/Flexible_array_member
- xyzzyz 7y agoOnly one field can be variable length, and it must be last. I'll pass.
- CoolGuySteve 7y agoYou 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.