I need to ensure that the results of serialization and deserialization are consistent each time. However, HashMap salts the hash process, resulting in inconsistent serialization and deserialization outcomes. I think replacing HashMap with BTreeMap should work, as the latter maintains the lexicographical order of keys. I'd like to ask how this can be implemented.
I've tried to use a customed enum:
enum BTreeMapValue {
Byte(i8),
Short(i16),
Int(i32),
Long(i64),
Float(f32),
Double(f64),
String(String),
ByteArray(ByteArray),
IntArray(IntArray),
LongArray(LongArray),
List(Vec<BTreeMapValue>),
Compound(BTreeMap<String, BTreeMapValue>),
}
let x = BTreeMapValue::Compound(BTreeMap::from([(
"key1".to_string(),
BTreeMapValue::String("value1".to_string()),
)]));
let y = fastnbt::to_bytes(&x)?;
println!("{:?}", y);
But when I call .to_bytes, it always raise Error: Error("invalid nbt: no root compound").
I need to ensure that the results of serialization and deserialization are consistent each time. However,
HashMapsalts the hash process, resulting in inconsistent serialization and deserialization outcomes. I think replacingHashMapwithBTreeMapshould work, as the latter maintains the lexicographical order of keys. I'd like to ask how this can be implemented.I've tried to use a customed enum:
But when I call
.to_bytes, it always raiseError: Error("invalid nbt: no root compound").