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

Implement the `$next` keyword for convenient packed structures. #36

Closed reventlov closed 2 years ago

reventlov commented 2 years ago

This change adds a new keyword, $next, which may be used in the offset expression of a physical field, and which translates to "the offset of the first byte after the end of the syntactically previous physical field."

Essentially, it allows structs or bits like:

struct Foo:
  0     [+4]  UInt  a
  $next [+2]  UInt  b
  $next [+1]  UInt  c
  $next [+4]  UInt  d

... where each field is packed directly after the previous one. See the updated documentation in doc/language-reference.md for details.

This also contains a few incidental changes: