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 · 1 comment
Open

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

nuno1212s opened this issue Feb 2, 2024 · 1 comment

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 }

@Cr4shd3v
Copy link

I am experiencing the same issue, is there any workaround?

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

3 participants