Trait pod::code::Encode [] [src]

pub trait Encode {
    type Options: Default;
    fn encode<W: Write>(&self, w: &mut W) -> Result<()> { ... }
    fn encode_options<W: Write>(&self, w: &mut W, _options: Self::Options) -> Result<()> { ... }
    fn encode_vec(&self) -> Result<Vec<u8>> { ... }
    fn encode_vec_options(&self, options: Self::Options) -> Result<Vec<u8>> { ... }
}

Encodes an value's binary representation to a Write.

Note that this is not serialization, and some data may be lost. It is left up to the implementation to decide what its representation is.

Provided Implementations

String, str

Strings are encoded as their raw UTF-8 representation. Length is not encoded, and must be provided when decoding (or reads to end of stream). Will error upon invalid UTF-8 sequences, nul bytes, etc.

CString, CStr

CStrings are encoded with a trailing nul byte. Decoding runs until the first nul byte reached.

Vec<T>, [T]

Vectors are encoded in sequence as packed raw values. Length is not encoded.

Option<T>

Some(T) is encoded as T, None writes 0 bytes. Decoding will always produce Some(T)

Pod

Pod types are encoded as their raw in-memory representation. Use EndianPrimitive members to control the byte order.

Associated Types

type Options: Default

Options that may be provided to affect how the value is encoded

Provided Methods

fn encode<W: Write>(&self, w: &mut W) -> Result<()>

Encodes to the Write with default options

fn encode_options<W: Write>(&self, w: &mut W, _options: Self::Options) -> Result<()>

Encodes to the Write with the provided options

fn encode_vec(&self) -> Result<Vec<u8>>

Encodes to a new byte vector

fn encode_vec_options(&self, options: Self::Options) -> Result<Vec<u8>>

Encodes to a new byte vector with the provided options

Implementors