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

Id128 has broken compact serde implementation #78

Open
vilgotf opened this issue Aug 11, 2021 · 1 comment
Open

Id128 has broken compact serde implementation #78

vilgotf opened this issue Aug 11, 2021 · 1 comment

Comments

@vilgotf
Copy link
Contributor

vilgotf commented Aug 11, 2021

Adding the following test shows it clearly:

    #[test]
    fn test_ser_de() {
        let id = Id128::parse_str("1071334a-9324-4511-adcc-b8d8b70eb1c2").unwrap();

        assert_tokens(
            &id.readable(),
            &[Token::Str("1071334a93244511adccb8d8b70eb1c2")],
        );

        // expected bytes but serialized as Str
        /*assert_tokens(
            &id.compact(),
            &[Token::Bytes(&[
                16, 113, 51, 74, 147, 36, 69, 17, 173, 204, 184, 216, 183, 14, 177, 194,
            ])],
        );/*

        // invalid type string, expected bytes
        /*assert_tokens(
            &id.compact(),
            &[Token::Str("1071334a93244511adccb8d8b70eb1c2")],
        );*/

I'm working on a fix which will serialize compact to Token::Tuple which should be fine since the code is already broken

@lucab
Copy link
Owner

lucab commented Aug 11, 2021

Thanks for the report. I think I may have initially overlooked the ser/de codepath, which resulted in this mixup.

Taking a step back here and thinking aloud, to what format should this type encode/decode to? The original C type is a union of byte-slices, but going in that direction doesn't sound very ergonomic.
Trying to retro-guess myself, I think that here I originally wanted to go in the direction of https://en.wikipedia.org/wiki/Universally_unique_identifier#Format. If so, it needs to be stated explicitly and enforced by tests, as you highlighted.

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

Successfully merging a pull request may close this issue.

2 participants