pub struct Blob { /* private fields */ }
Expand description
A generic, complete object in Named Binary Tag format.
This is essentially a map of names to Value
s, 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) -> Blobwhere
S: Into<String>,
pub fn named<S>(name: S) -> Blobwhere
S: Into<String>,
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<()>where
S: Into<String>,
V: Into<Value>,
pub fn insert<S, V>(&mut self, name: S, value: V) -> Result<()>where
S: Into<String>,
V: Into<Value>,
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.