sharksforarms / deku

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Apache License 2.0
1.14k stars 55 forks source link

Add trait to get binary size of messages #307

Open wucke13 opened 1 year ago

wucke13 commented 1 year ago

If a message contains only known size types (e.g. arrays and primitives, but no Vec etc.) it would be cool to have a const helper function that determines the size of a buffer that is guaranteed to fit the serialized message. This greatly improves the usability in environments without alloc.

sempervictus commented 10 months ago

Finding this to be somewhat necessary rather than a convenience when using typed enums getting their type from outside their own byte range (typed body getting type passed as ctx from the header) - can't convert those to bytes for measurement conveniently and need to edit them destructured which then has to update the header length.