Hacker News new | ask | show | jobs
by marcan_42 2374 days ago
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.
2 comments

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.