Eliminate redundant residual re-read in optimized Ok() switch arms (#272) Lever A of the Ok() rework: in a conditional-switch arm whose field carries a residual predicate beyond the discriminant equality (e.g. `if tag == K && outer == 1`), gate the field's Ok() check on the residual alone rather than re-deriving the full has_<field>() existence condition. Inside `case K:` the switch has already decoded and (provably, or via the emitted Known() guard) established the discriminant, so `has_<field>() <=> residual`. The prior form re-invoked has_<field>(), which redundantly re-reads and re-compares the discriminant on every arm; the residual (a single hoisted, shared subexpression) drops that per-arm work. Implementation: preserve the residual conjunct list through _generate_optimized_ok_method_body instead of collapsing it to a bool, thread (ir, subexpressions) into _emit_switch_block/_render_case_body, and render the residual at emit time (so demoted groups leak no dead subexpression). Multiple conjuncts fold into one synthesized boolean AND so the residual renders once. The gate is required for correctness, not just size: <field>() returns a null view when absent, so an unguarded <field>().Ok() would wrongly fail when the residual is false; we also bail when the residual is not Known. Adds testdata OuterGuardedUnion (100 tag arms each guarded by a shared `outer == 1` residual) to exercise and measure the change; flat LargeConditionals (all bare arms) is the unaffected control. Measured OuterGuardedUnion::Ok() reader symbol @ -Os vs the pre-Lever-A generator (schema held fixed): MicroBlaze LE/Vitis (authoritative) -18.7%, MicroBlaze BE -21.5%, ARM Cortex-M4 -17.0%, x86-64 gcc -9.5% / clang -50.7%. Retired guest instructions (OuterGuardedUnion hot loop): MicroBlaze BE -3.2%, MicroBlaze LE -1.6%, ARM -1.1%. Flat LargeConditionals codegen is byte-identical (0 symbol delta on every target); x86 wall-clock unchanged. Golden diff is confined to the residual-arm schemas (condition.emb.h, many_conditionals.emb.h); every pre-existing struct is byte-identical. Full compiler+runtime suite (205 tests) and the #266 condition_test oracle stay green.
Emboss is a tool for generating code that reads and writes binary data structures. It is designed to help write code that communicates with hardware devices such as GPS receivers, LIDAR scanners, or actuators.
Emboss takes specifications of binary data structures, and produces code that will efficiently and safely read and write those structures.
Currently, Emboss only generates C++ code, but the compiler is structured so that writing new back ends is relatively easy -- contact emboss-dev@google.com if you think Emboss would be useful, but your project uses a different language.
If you're sitting down with a manual that looks something like this or this, Emboss is meant for you.
Emboss is not designed to handle text-based protocols; if you can use minicom or telnet to connect to your device, and manually enter commands and see responses, Emboss probably won't help you.
Emboss is intended for cases where you do not control the data format. If you are defining your own format, you may be better off using Protocol Buffers or Cap'n Proto or BSON or some similar system.
In C++, packed structs are most common method of dealing with these kinds of structures; however, they have a number of drawbacks compared to Emboss views:
Emboss does not help you transmit data over a wire -- you must use something else to actually transmit bytes back and forth. This is partly because there are too many possible ways of communicating with devices, but also because it allows you to manipulate structures independently of where they came from or where they are going.
Emboss does not help you interpret your data, or implement any kind of higher-level logic. It is strictly meant to help you turn bit patterns into something suitable for your programming language to handle.
Emboss is currently under development. While it should be entirely ready for many data formats, it may still be missing features. If you find something that Emboss can't handle, please contact emboss-dev@google.com to see if and when support can be added.
Emboss is not an officially supported Google product: while the Emboss authors will try to answer feature requests, bug reports, and questions, there is no SLA (service level agreement).
Head over to the User Guide to get started.