bincode-org / bincode

A binary encoder / decoder implementation in Rust.
MIT License
2.69k stars 272 forks source link

Add (optional) smallvec decode/encode support #705

Closed freqmod closed 5 months ago

freqmod commented 7 months ago

I added optional support for the smallvec crate which supports vectors inside a struct without a separate memory allocation. I tried implementing this with the newtype pattern, but i could not figure out a way to deserialise a without going via a vector (and thus allocating the memory that the crate was designed to avoid).

The code is 90% copy paste from the code for (De)coding vectors. However I had to remove the optimisation for deserialising u8 as SmallVec don't use generics for the array size.

I hope that this change can be merged, and am happy to work with you if there are any changes that are needed in order to do so.

We probably also need to update the list of features in the docs. I can do that if necessary.

adamreichold commented 7 months ago

SmallVec don't use generics for the array size.

They do have a const_generics feature.

VictorKoenders commented 7 months ago

See https://github.com/bincode-org/bincode/pull/612 for previous work and discussion on this

freqmod commented 7 months ago

I see, thanks for linking the issue for me. It is a bit strange that I didn't see this issue when I searched in github. I guess I will have to keep a fork around for now then until bincode v2 is released.

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.