esa / asn1scc

ASN1SCC: An open source ASN.1 compiler for embedded systems
https://www.thanassis.space/asn1.html
Other
272 stars 58 forks source link

Efficient enum encodings #303

Closed usr3-1415 closed 7 months ago

usr3-1415 commented 7 months ago

Optimize Generated C Code for Enumerated Types

This PR introduces a new mode in asn1scc that optimizes the generated C code for ASN.1 Enumerated types, especially when there are multiple enumerants in the type (e.g., 50 or more).

When the -eee option is present, asn1scc generates more efficient and less verbose code. Instead of generating switch statements, asn1scc generates sorted arrays containing the possible values. Lookups, such as for validation or index retrieval in uPER encoding, are performed using an optimized binary search.

This results in more efficient code generation for large Enumerated types, improving performance and readability.

To use this mode, pass the minimum number of enumerants in an enumerated type to enable this mode as an argument to the -eee option. For example, -eee 50 will enable this mode for enumerated types with 50 or more enumerants.