Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when decoding a simple Enum with no member values. #695

Open
nuno1212s opened this issue Feb 2, 2024 · 0 comments
Open

Issue when decoding a simple Enum with no member values. #695

nuno1212s opened this issue Feb 2, 2024 · 0 comments

Comments

@nuno1212s
Copy link

nuno1212s commented Feb 2, 2024

Bincode version: 2.0.0-rc3

I'm facing an issue when using bincode's serde facing serialization/deserialization with simple Enums.
Namely I always get UnexpectedEnd { additional: 1 } error when trying to decode the enum.

The enum in question:

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum MessageModule {
    Reconfiguration,
    Protocol,
    StateProtocol,
    Application,
}

The unit test used to verify this behaviour:

#[test]
    pub fn test_message_mod_serialization() -> Result<()> {

        let msg_mod = MessageModule::Protocol;

        let vec = bincode::serde::encode_to_vec(&msg_mod, bincode::config::standard())?;

        let mod_bytes = Bytes::from(vec);

        println!("Mod bytes {:x?}", mod_bytes);

        let (de_ser_msg_mod, msg_mod_size): (MessageModule, usize) = bincode::serde::decode_borrowed_from_slice(mod_bytes.as_ref(), bincode::config::standard())?;

        assert_eq!(de_ser_msg_mod, msg_mod);

        Ok(())
 }

Bytes::from is using the bytes crate.

Expected behaviour: The decoded message module should match the encoded one.
Observed behaviour: Error: UnexpectedEnd { additional: 1 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants