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

Enums are always generated as [u]int64_t in C++ #24

Closed fsareshwala closed 2 years ago

fsareshwala commented 2 years ago

Emboss generates enums declared as uint64_t regardless of how many enum members are present or their ranges. When writing into structure fields, Emboss checks whether there are enough bytes to write without any loss of data.

For example, take the following enum definition:

enum OpCodeGroup:
  FOO = 0x08

Emboss generates the following code for the above definition:

enum class OpCodeGroup : ::std::uint64_t;

enum class OpCodeGroup : ::std::uint64_t {
  FOO = static_cast</**/::std::int32_t>(8LL),

};

There is only a single element in the enum and its range should easily fall within the range limits of a uint8_t. There is seemingly no way to control the generated size of an enum.

Potential Implementation The .emb language syntax is updated to accept the maximum size in bytes for an enum in the generated code.