Consider removing bincode dependency?
Closed this issue ยท 4 comments
I landed on this crate after evaluating bincode
and found a bug in the version 2 beta that prevented me from using it for my use case. Whilst I don't think that bug applies to this crate I think the bincode
dependency could be removed and we could use the newer from_be_bytes
and to_be_bytes
for primitive types.
For example for u8
:
- https://doc.rust-lang.org/std/primitive.u8.html#method.from_be_bytes (reader)
- https://doc.rust-lang.org/std/primitive.u8.html#method.to_be_bytes (writer)
We should also support little endian with from_le_bytes
and to_le_bytes
. We could add an Endian
enum and pass it to BinaryWriter::new
and BinaryReader::new
which would be a breaking change and require a major version bump!
If this interests you let me know and I will look into it some more ๐
Hi! I have wanted and done some work the same thing, mostly because bincode is very overkill for what this crate is trying todo
main issue i stumbled upon is to_xx_bytes and from_xx_bytes not being traits making it hard to write a single generic function that just does all primitive types.
As for doing endianess I think this could be achieved without braking changes by adding new_with_endian(...) and just default endianess to little endian when calling new(). Not sure about that though
I agree not having a trait for those functions is a bit awkward but we can still just manually call them in the read_
and write_
methods.
Sure a new constructor flavor is a good idea ๐
I agree not having a trait for those functions is a bit awkward but we can still just manually call them in the
read_
andwrite_
methods.Sure a new constructor flavor is a good idea ๐
Calling them manually is a bit cumbersome when adding endianess too as it requires a branch for all of them, a lot of duplication, maybe a macro could achieve this. But my knowledge on macros is a bit limited.
My knowledge of macros is limited too but this is certainly a good candidate for a macro to remove some of the repetition. I will look into it.