How to calculate the length needed for buffer when encoding data

I am experimenting with using this library via a C application via FFI. My data types are pretty simple (no choices, unions, generics, and all arrays, byte strings and text strings are of fixed length).

My application will "allocate" some space when it needs to send some encoded data, and it would be more optimal if I only "allocate" exactly what I need. I am wondering if there is a way to calculate the amount of buffer I need when I want to encode my data types.

If I were more familiar with the spec I think I could probably use a derive macro to analyze the types and produce a constant to define the length I need. But I suspect the actual lengths can be implementation dependent, and there could be some useful utility in here that can make this task easier.

So this is not really an issue but more of a feature request / or how-to question...