Skip to content

Deserialization of Blobs using serde confuses types #45

@cevans-uk

Description

@cevans-uk

Consider:

use nbt::{Blob, Value}; 

fn main() {
    let mut blob = Blob::new();
    blob.insert("test", Value::Int(123)).unwrap();

    let mut bytes = Vec::new();
    nbt::to_writer(&mut bytes, &blob, None).unwrap();
    println!("{:?}", bytes);

    let de_blob: Blob = nbt::from_reader(&bytes[..]).unwrap();
    println!("{:?}", de_blob);
}

Output:

[10, 0, 0, 3, 0, 4, 116, 101, 115, 116, 0, 0, 0, 123, 0]
Blob { title: "", content: {"test": Byte(123)} }

Serialization seems to work -- that 3 in the 4th position is TAG_Int as you'd expect, but it gets deserialized into a Value::Byte (using larger values will give Shorts and then Ints).

Using Blob::from_reader works, and gives Blob { title: "", content: {"test": Int(123)} }.

I think this is caused by using serde(untagged) for the Value enum, but I really don't understand serde well enough to know how to fix this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions