-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
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").
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels