Closed bkolligs closed 1 year ago
https://github.com/bincode-org/bincode#why-does-bincode-not-respect-repru8
#[repr(u8)]
?Bincode will encode enum variants as a u32
. If you're worried about storage size, we can recommend enabling Configuration::with_variable_int_encoding()
. This option is enabled by default with the standard
configuration. In this case enum variants will almost always be encoded as a u8
.
Currently we have not found a compelling case to respect #[repr(...)]
. You're most likely trying to interop with a format that is similar-but-not-quite-bincode. We only support our own protocol (spec).
If you really want to use bincode to encode/decode a different protocol, consider implementing Encode
and Decode
yourself. bincode-derive
will output the generated implementation in target/generated/bincode/<name>_Encode.rs
and target/generated/bincode/<name>_Decode.rs
which should get you started.
I'd like to be able to do this:
This is often required when interfacing with any C code or operating system level data, which is most of what I have been using
bincode
for. I know there is https://github.com/dtolnay/serde-repr, but it'd be nice if this worked with the newEncode, Decode
traits.