pub struct Blob { /* private fields */ }Expand description
A generic, complete object in Named Binary Tag format.
This is essentially a map of names to Values, with an optional top-level
name of its own. It can be created in a similar way to a HashMap, or read
from an io::Read source, and its binary representation can be written to
an io::Write destination.
These read and write methods support both uncompressed and compressed (through Gzip or zlib compression) methods.
use nbt::{Blob, Value, Endianness};
// Create a `Blob` from key/value pairs.
let mut nbt = Blob::new();
nbt.insert("name", "Herobrine").unwrap();
nbt.insert("health", 100i8).unwrap();
nbt.insert("food", 20.0f32).unwrap();
// Write a compressed binary representation to a byte array.
let mut dst = Vec::new();
nbt.to_zlib_writer(&mut dst, Endianness::BigEndian).unwrap();Implementations§
Source§impl Blob
impl Blob
Sourcepub fn named<S>(name: S) -> Blob
pub fn named<S>(name: S) -> Blob
Create a new NBT file format representation with the given name.
Sourcepub fn from_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
pub fn from_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
Extracts an Blob object from an io::Read source.
Sourcepub fn from_gzip_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
pub fn from_gzip_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
Extracts an Blob object from an io::Read source that is
compressed using the Gzip format.
Sourcepub fn from_zlib_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
pub fn from_zlib_reader<R>(src: &mut R, endian: Endianness) -> Result<Blob>where
R: Read,
Extracts an Blob object from an io::Read source that is
compressed using the zlib format.
Sourcepub fn to_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
pub fn to_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
Writes the binary representation of this Blob to an io::Write
destination.
Sourcepub fn to_gzip_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
pub fn to_gzip_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
Writes the binary representation of this Blob, compressed using
the Gzip format, to an io::Write destination.
Sourcepub fn to_zlib_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
pub fn to_zlib_writer<W>(&self, dst: &mut W, endian: Endianness) -> Result<()>where
W: Write,
Writes the binary representation of this Blob, compressed using
the Zlib format, to an io::Write dst.
Sourcepub fn insert<S, V>(&mut self, name: S, value: V) -> Result<()>
pub fn insert<S, V>(&mut self, name: S, value: V) -> Result<()>
Insert an Value with a given name into this Blob object. This
method is just a thin wrapper around the underlying HashMap method of
the same name.
This method will also return an error if a Value::List with
heterogeneous elements is passed in, because this is illegal in the NBT
file format.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Blob
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Blob
serde only.