google / emboss

Emboss is a tool for generating code that reads and writes binary data structures.
Apache License 2.0
70 stars 21 forks source link

Support Lists of Variable-Length Structures. #51

Open reventlov opened 2 years ago

reventlov commented 2 years ago

It is currently possible to (somewhat hackily) support lists by modeling them as recursive structures, like so:

struct Repeated(remaining_size : UInt:32):
  0 [+4]  UInt  length
  # ... other fields ...
  if remaining_size > length:
    length [+remaining_size - length]  Repeated  next

However, there should be a nicer syntax for specifying that there is a list of Repeated elements, with a C++ API that supports iteration (but not random access).

AaronWebster commented 2 years ago

Would the structures need to have the same type or could this include TLV (type-length-value) messages?