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.
Methods
Section titled “Methods”pub fn new() -> SelfAn empty writer.
into_bytes
Section titled “into_bytes”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.
Errors
Section titled “Errors”EncodeError::OverLimit when longer than max.
string
Section titled “string”pub fn string(&mut self, text: &str, max: usize) -> Result<(), EncodeError>string: u32 byte length, then UTF-8. max is in bytes.
Errors
Section titled “Errors”EncodeError::OverLimit when longer than max bytes.
option
Section titled “option”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.
Errors
Section titled “Errors”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.
Errors
Section titled “Errors”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.
Errors
Section titled “Errors”Whatever the value’s encoder returns.
Trait implementations
Section titled “Trait implementations”Clone, Debug, Default