pub fn i8_array<T, S>(array: T, serializer: S) -> Result<S::Ok, S::Error>Expand description
This function provides serde serialization support for NBT type ByteArray.
It should be used in conjunction with serde’s field annotation serialize_with.
In the following example byte_data will be serialized as a ByteArray
instead of a List of Bytes:
extern crate serde;
use nbt::to_writer;
use serde::Serialize;
let mut serialized = Vec::new();
// Declare your struct
#[derive(Serialize)]
struct Sheep {
#[serde(serialize_with="nbt::i8_array")]
byte_data: Vec<i8>,
}
// Serialize to NBT!
to_writer(
&mut serialized,
&Sheep {
byte_data: vec![0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0x20, 0x73, 0x68, 0x65, 0x65, 0x70],
},
None
).unwrap();
print!("Serialized: {:?}", serialized);