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

Seq serialization is ambiguous #2

Open
freopen opened this issue Mar 31, 2023 · 0 comments · May be fixed by #9
Open

Seq serialization is ambiguous #2

freopen opened this issue Mar 31, 2023 · 0 comments · May be fixed by #9

Comments

@freopen
Copy link

freopen commented Mar 31, 2023

Looks like seq can't distinguish between 0x01 at the end of a sequence and 0x01 as the first byte of an element:

fn test(vec: Vec<u8>) {
    let ser = storekey::serialize(&vec).unwrap();
    let ser_de: Vec<u8> = storekey::deserialize(&ser).unwrap();
    println!("Init: {vec:?}, serialized: {ser:?}, deserialized: {ser_de:?}");
}

fn main() {
    test(vec![0x00u8]);
    test(vec![0x01u8]);
    test(vec![0x02u8]);
}
Init: [0], serialized: [0, 1], deserialized: [0]
Init: [1], serialized: [1, 1], deserialized: []
Init: [2], serialized: [2, 1], deserialized: [2]

I think every element of a seq should be appended prepended by 0x00 so the move_on() function will skip a byte in both cases, but only return true if the byte is 0x01

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.

1 participant