Skip to main content

PayloadWriter

Struct PayloadWriter 

pub struct PayloadWriter { /* private fields */ }
Expand description

A payload body being written, bounded in bytes. The first failure is kept and every later write is skipped, so a codec need not check each one.

Implementations§

§

impl PayloadWriter

pub fn new(limit: usize) -> PayloadWriter

A writer that accepts at most limit bytes.

pub fn finish(self) -> Result<Vec<u8>, PayloadEncodeError>

The encoded body, or the first failure.

pub fn fail(&mut self, error: PayloadEncodeError)

Records a failure of the value’s own codec; the first one is kept.

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

Appends bytes as they are, with no length before them. The limit is checked before the buffer grows.

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

One unsigned byte.

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

One signed byte.

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

A big-endian 16-bit integer.

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

A big-endian unsigned 16-bit integer.

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

A big-endian 32-bit integer.

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

A big-endian 64-bit integer.

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

A big-endian 32-bit float.

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

A big-endian 64-bit float.

pub fn uuid(&mut self, value: u128)

A UUID: 16 bytes, most significant first.

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

A boolean: one byte, 0 or 1.

pub fn finite_f32(&mut self, value: f32)

A 32-bit float that must be finite.

pub fn finite_f64(&mut self, value: f64)

A 64-bit float that must be finite.

pub fn var_int(&mut self, value: i32)

A VarInt.

pub fn var_long(&mut self, value: i64)

A VarLong.

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

A byte array of at most limit bytes: its VarInt length, then the bytes.

pub fn str_within(&mut self, text: &str, limit: usize)

A string of at most limit UTF-8 bytes: its VarInt byte length, then the bytes.

pub fn string(&mut self, text: &str)

A string of at most PAYLOAD_MAX_STRING_BYTES UTF-8 bytes.

pub fn nested(&mut self, write: impl FnOnce(&mut PayloadWriter))

Writes one level down, refusing past PAYLOAD_MAX_DEPTH.

pub fn list<T>( &mut self, items: &[T], limit: usize, write: impl FnMut(&mut PayloadWriter, &T), )

A list of at most limit entries: its VarInt count, then each entry written by write, one level down.

pub fn option<T>( &mut self, value: Option<&T>, write: impl FnOnce(&mut PayloadWriter, &T), )

An optional value: a boolean, then the value one level down when there is one.

Trait Implementations§

§

impl Debug for PayloadWriter

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.