SoftbearStudios / bitcode

A binary encoder/decoder for Rust
https://crates.io/crates/bitcode/
MIT License
369 stars 19 forks source link

Implement Encode/Decode for &'a [u8] #23

Open DrSloth opened 7 months ago

DrSloth commented 7 months ago

This would allow bitcode to serialize/deserialize arbitrary bytes (like non utf-8 strings) to be serialized/deserialized without the serde feature

caibear commented 7 months ago

It's a bit tricky since u8s may be packed as u1 u2 u4 which can't be borrowed as u8 from input. It would require borrowing from a bitcode::Buffer after the u8s are unpacked.

DrSloth commented 7 months ago

Good point, would it be possible to provide some wrapper type that gets serialized as raw bytes? My specific use case actually is that of non UTF-8 text. I kind of need str encoding but not UTF-8.

In my case i could also implement the traits by hand but that doesn't seem to be documented.

finnbear commented 7 months ago

And your use-case requires zero-copy for some reason? Otherwise you can use Vec<u8> or Box<[u8]>.

myrgy commented 2 months ago

Hi guys,

Thank you for great framework! Would be nice to see that feature!

Thank you!