bincode-org / bincode

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

Bincode v2, serde functions do not match naming and arguments of bincode functions #654

Closed spaolacci closed 11 months ago

spaolacci commented 1 year ago

Hi,

On top of being more symmetrical with decode_from_slice, this is very handy for cases where that information is not easily available decoding side.

Use case that I'm having is where the slice host a collection of bincode-encoded items. The overall size is know (through a specific header) but not individual item encoded sizes. A representative example could be a list of &str.

That’s obviously fixable through a per item extra usize header but make encoding/decoding slower, and serialized size larger, than need to be.

I might have missed something but it seem decoder's reader is having that information which could gain from being exposed (as for decode_from_slice).

And thanks a lot for the very nice crate!

Seb

VictorKoenders commented 1 year ago

Do you mean borrow_decode_from_slice? This returns (D, usize) where the usize is the amount of bytes read.

spaolacci commented 1 year ago

Well, I obviously feel embarrassed. Was only looking into bincode::serde since.. using serde :/..

Layout might gain from having the function on the two locations, or all of them in just one location, but anyway this is clearly what I was looking for.

Thanks a lot.

seb

VictorKoenders commented 1 year ago

I'm going to reopen this as the serde functions ideally would be the same as the standard bincode functions

VictorKoenders commented 11 months ago

Should be fixed in the next version, please re-open this if any of the names do not match