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.
Consider:
Output:
Serialization seems to work -- that
3in the 4th position isTAG_Intas you'd expect, but it gets deserialized into aValue::Byte(using larger values will giveShorts and thenInts).Using
Blob::from_readerworks, and givesBlob { title: "", content: {"test": Int(123)} }.I think this is caused by using
serde(untagged)for theValueenum, but I really don't understand serde well enough to know how to fix this.