Struct nbt::Blob [] [src]

pub struct Blob {
    // some fields omitted
}

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};

// Create a `Blob` from key/value pairs.
let mut nbt = Blob::new("".to_string());
nbt.insert("name".to_string(), "Herobrine").unwrap();
nbt.insert("health".to_string(), 100i8).unwrap();
nbt.insert("food".to_string(), 20.0f32).unwrap();

// Write a compressed binary representation to a byte array.
let mut dst = Vec::new();
nbt.write_zlib(&mut dst).unwrap();

Methods

impl Blob

fn new(title: String) -> Blob

Create a new NBT file format representation with the given name.

fn from_reader(src: &mut Read) -> Result<Blob>

Extracts an Blob object from an io::Read source.

fn from_gzip(src: &mut Read) -> Result<Blob>

Extracts an Blob object from an io::Read source that is compressed using the Gzip format.

fn from_zlib(src: &mut Read) -> Result<Blob>

Extracts an Blob object from an io::Read source that is compressed using the zlib format.

fn write(&self, dst: &mut Write) -> Result<()>

Writes the binary representation of this Blob to an io::Write destination.

fn write_gzip(&self, dst: &mut Write) -> Result<()>

Writes the binary representation of this Blob, compressed using the Gzip format, to an io::Write destination.

fn write_zlib(&self, dst: &mut Write) -> Result<()>

Writes the binary representation of this Blob, compressed using the Zlib format, to an io::Write dst.

fn insert<V>(&mut self, name: String, value: V) -> Result<()> where 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.

fn len(&self) -> usize

The uncompressed length of this Blob, in bytes.

Trait Implementations

impl<'a> Index<&'a str> for Blob

type Output = Value

fn index<'b>(&'b self, s: &'a str) -> &'b Value

impl Display for Blob

fn fmt(&self, f: &mut Formatter) -> Result

Derived Implementations

impl PartialEq for Blob

fn eq(&self, __arg_0: &Blob) -> bool

fn ne(&self, __arg_0: &Blob) -> bool

impl Debug for Blob

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for Blob

fn clone(&self) -> Blob

fn clone_from(&mut self, source: &Self)