Skip to content

Struct encoding::Writer

zaun_community_protocol::encoding::Writer · Struct

pub struct Writer { … }

Appends canonical encodings to a buffer. Variable fields take their limit and fail above it, mirroring super::Reader.

pub fn new() -> Self

An empty writer.

pub fn into_bytes(self) -> Vec<u8>

The encoding so far.

pub fn u8(&mut self, value: u8)

u8.

pub fn u16(&mut self, value: u16)

u16, big-endian.

pub fn u32(&mut self, value: u32)

u32, big-endian.

pub fn u64(&mut self, value: u64)

u64, big-endian.

pub fn bool(&mut self, value: bool)

bool: 0x00 or 0x01.

pub fn fixed(&mut self, bytes: &[u8])

bytes[N]: the bytes, no prefix.

pub fn bytes(&mut self, bytes: &[u8], max: usize) -> Result<(), EncodeError>

Variable bytes: u32 length, then the bytes.

EncodeError::OverLimit when longer than max.

pub fn string(&mut self, text: &str, max: usize) -> Result<(), EncodeError>

string: u32 byte length, then UTF-8. max is in bytes.

EncodeError::OverLimit when longer than max bytes.

pub fn option<T, impl FnOnce(&mut Self, &T) -> Result<(), EncodeError>>(&mut self, value: Option<&T>, f: impl FnOnce(&mut Self, &T) -> Result<(), EncodeError>) -> Result<(), EncodeError>

option<T>: 0x00, or 0x01 then the value written by f.

Whatever f returns.

pub fn list<T, impl FnMut(&mut Self, &T) -> Result<(), EncodeError>>(&mut self, items: &[T], max: usize, f: impl FnMut(&mut Self, &T) -> Result<(), EncodeError>) -> Result<(), EncodeError>

list<T>: u32 count, then each element written by f.

EncodeError::OverLimit when more than max elements, or whatever f returns.

pub fn put<T>(&mut self, value: &T) -> Result<(), EncodeError>

Writes a value with a canonical encoding.

Whatever the value’s encoder returns.

Clone, Debug, Default

Full rustdoc page