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

Feature request - payload size calculation #276

Closed dsabala closed 1 year ago

dsabala commented 1 year ago

Hi

Although this is not a key feature, it would be nice to be able to calculate how much memory space should be allocated before encoding the frame. Currently, only the maximum possible area is known and you have to allocate whole <name>_REQUIRED_BYTES_FOR_ACN_ENCODING before you call encode function.

Best regards

usr3-1415 commented 1 year ago

Thank you for your suggestion. However, the memory requirement for encoding a message is inherently dependent on the specific message content. For instance, when encoding a message like

MyArray ::= SEQUENCE (SIZE(0 .. 1024) OF INTEGER(0..255)

the exact memory needed can't be determined beforehand, only the maximum size can be precalculated. This design choice aligns with ASN1SCC's focus on embedded systems, ensuring predictable memory usage by precalculating the maximum encoding buffer size at compile time for each ASN.1 message.