Open elpiel opened 2 weeks ago
I somewhat plan to rework MaxSize as part of postcard-schema
, as I believe it is possible to calculate this as a const fn. See https://github.com/jamesmunns/postcard/pull/179 for an example of this.
One edge case I can think of is how to handle "infinite" cases, as ()
is serialized as zero bytes on the wire, so your function needs to be careful not to divide by zero :)
If you'd like to copy and paste what I did in #179 and switch it to min instead of max, I'd accept that PR.
Hmm that's an interesting case actually heh. Well I do have a "protocol" level crate although I only (currently) use it with 1 enum that hosts all the messages and it doesn't have a unit type.
Apart from the MaxSize experimental feature I'd love to see a MinSize as well. This can be useful if you want to have a "counter" buffer which keeps track of the maximum number of items that might be able to fit in a given buffer.
E.g. I have a buffer of 4 KiB and I'd like to know what's the maximum number of messages that can fit inside. This buffer contains
embedded_sdmmc::Block
s inside so it's not a continues buffer of bytes and I'm using a second buffer to keep track of how much each block is filled.