xref: /aosp_15_r20/external/emboss/README.md (revision 99e0aae7469b87d12f0ad23e61142c2d74c1ef70)
1*99e0aae7SDavid Rees# Emboss
2*99e0aae7SDavid Rees
3*99e0aae7SDavid ReesEmboss is a tool for generating code that reads and writes binary data
4*99e0aae7SDavid Reesstructures.  It is designed to help write code that communicates with hardware
5*99e0aae7SDavid Reesdevices such as GPS receivers, LIDAR scanners, or actuators.
6*99e0aae7SDavid Rees
7*99e0aae7SDavid Rees## What does Emboss *do*?
8*99e0aae7SDavid Rees
9*99e0aae7SDavid ReesEmboss takes specifications of binary data structures, and produces code that
10*99e0aae7SDavid Reeswill efficiently and safely read and write those structures.
11*99e0aae7SDavid Rees
12*99e0aae7SDavid ReesCurrently, Emboss only generates C++ code, but the compiler is structured so
13*99e0aae7SDavid Reesthat writing new back ends is relatively easy -- contact [email protected]
14*99e0aae7SDavid Reesif you think Emboss would be useful, but your project uses a different language.
15*99e0aae7SDavid Rees
16*99e0aae7SDavid Rees
17*99e0aae7SDavid Rees## When should I use Emboss?
18*99e0aae7SDavid Rees
19*99e0aae7SDavid ReesIf you're sitting down with a manual that looks something like
20*99e0aae7SDavid Rees[this](https://hexagondownloads.blob.core.windows.net/public/Novatel/assets/Documents/Manuals/om-20000094/om-20000094.pdf) or
21*99e0aae7SDavid Rees[this](https://www.u-blox.com/sites/default/files/products/documents/u-blox6_ReceiverDescrProtSpec_%28GPS.G6-SW-10018%29_Public.pdf),
22*99e0aae7SDavid ReesEmboss is meant for you.
23*99e0aae7SDavid Rees
24*99e0aae7SDavid Rees
25*99e0aae7SDavid Rees## When should I not use Emboss?
26*99e0aae7SDavid Rees
27*99e0aae7SDavid ReesEmboss is not designed to handle text-based protocols; if you can use minicom or
28*99e0aae7SDavid Reestelnet to connect to your device, and manually enter commands and see responses,
29*99e0aae7SDavid ReesEmboss probably won't help you.
30*99e0aae7SDavid Rees
31*99e0aae7SDavid ReesEmboss is intended for cases where you do not control the data format.  If you
32*99e0aae7SDavid Reesare defining your own format, you may be better off using [Protocol
33*99e0aae7SDavid ReesBuffers](https://developers.google.com/protocol-buffers/) or [Cap'n
34*99e0aae7SDavid ReesProto](https://capnproto.org/) or [BSON](http://bsonspec.org/) or some similar
35*99e0aae7SDavid Reessystem.
36*99e0aae7SDavid Rees
37*99e0aae7SDavid Rees
38*99e0aae7SDavid Rees## Why not just use packed structs?
39*99e0aae7SDavid Rees
40*99e0aae7SDavid ReesIn C++, packed structs are most common method of dealing with these kinds of
41*99e0aae7SDavid Reesstructures; however, they have a number of drawbacks compared to Emboss views:
42*99e0aae7SDavid Rees
43*99e0aae7SDavid Rees1.  Access to packed structs is not checked.  Emboss (by default) ensures that
44*99e0aae7SDavid Rees    you do not read or write out of bounds.
45*99e0aae7SDavid Rees2.  It is easy to accidentally trigger C++ undefined behavior using packed
46*99e0aae7SDavid Rees    structs, for example by not respecting the struct's alignment restrictions
47*99e0aae7SDavid Rees    or by running afoul of strict aliasing rules.  Emboss is designed to work
48*99e0aae7SDavid Rees    with misaligned data, and is careful to use strict-aliasing-safe constructs.
49*99e0aae7SDavid Rees3.  Packed structs do not handle variable-size arrays, nor arrays of
50*99e0aae7SDavid Rees    sub-byte-size fields, such as boolean flags.
51*99e0aae7SDavid Rees4.  Packed structs do not handle endianness; your code must be very careful to
52*99e0aae7SDavid Rees    correctly convert stored endianness to native.
53*99e0aae7SDavid Rees5.  Packed structs do not handle variable-sized fields, such as embedded
54*99e0aae7SDavid Rees    substructs with variable length.
55*99e0aae7SDavid Rees6.  Although unions can sometimes help, packed structs do not handle overlapping
56*99e0aae7SDavid Rees    fields well.
57*99e0aae7SDavid Rees7.  Although unions can sometimes help, packed structs do not handle optional
58*99e0aae7SDavid Rees    fields well.
59*99e0aae7SDavid Rees8.  Certain aspects of bitfields in C++, such as their exact placement within
60*99e0aae7SDavid Rees    the larger containing block, are implementation-defined.  Emboss always
61*99e0aae7SDavid Rees    reads and writes bitfields in a portable way.
62*99e0aae7SDavid Rees9.  Packed structs do not have support for conversion to human-readable text
63*99e0aae7SDavid Rees    format.
64*99e0aae7SDavid Rees10. It is difficult to read the definition of a packed struct in order to
65*99e0aae7SDavid Rees    generate documentation, alternate representations, or support in languages
66*99e0aae7SDavid Rees    other than C and C++.
67*99e0aae7SDavid Rees
68*99e0aae7SDavid Rees
69*99e0aae7SDavid Rees## What does Emboss *not* do?
70*99e0aae7SDavid Rees
71*99e0aae7SDavid ReesEmboss does not help you transmit data over a wire -- you must use something
72*99e0aae7SDavid Reeselse to actually transmit bytes back and forth.  This is partly because there
73*99e0aae7SDavid Reesare too many possible ways of communicating with devices, but also because it
74*99e0aae7SDavid Reesallows you to manipulate structures independently of where they came from or
75*99e0aae7SDavid Reeswhere they are going.
76*99e0aae7SDavid Rees
77*99e0aae7SDavid ReesEmboss does not help you interpret your data, or implement any kind of
78*99e0aae7SDavid Reeshigher-level logic.  It is strictly meant to help you turn bit patterns into
79*99e0aae7SDavid Reessomething suitable for your programming language to handle.
80*99e0aae7SDavid Rees
81*99e0aae7SDavid Rees
82*99e0aae7SDavid Rees## What state is Emboss in?
83*99e0aae7SDavid Rees
84*99e0aae7SDavid ReesEmboss is currently under development.  While it should be entirely ready for
85*99e0aae7SDavid Reesmany data formats, it may still be missing features.  If you find something that
86*99e0aae7SDavid ReesEmboss can't handle, please contact `[email protected]` to see if and when
87*99e0aae7SDavid Reessupport can be added.
88*99e0aae7SDavid Rees
89*99e0aae7SDavid ReesEmboss is not an officially supported Google product: while the Emboss authors
90*99e0aae7SDavid Reeswill try to answer feature requests, bug reports, and questions, there is no SLA
91*99e0aae7SDavid Rees(service level agreement).
92*99e0aae7SDavid Rees
93*99e0aae7SDavid Rees
94*99e0aae7SDavid Rees## Getting Started
95*99e0aae7SDavid Rees
96*99e0aae7SDavid ReesHead over to the [User Guide](doc/guide.md) to get started.
97