Skip to main content

ArchiveSerializer

Struct ArchiveSerializer 

Source
pub struct ArchiveSerializer { /* private fields */ }
Available on crate feature archive only.
Expand description

Serializer that produces the flat archive payload.

Implementations§

Source§

impl ArchiveSerializer

Source

pub fn new() -> Self

Creates an empty serializer.

Source

pub fn len(&self) -> usize

The current length of the output buffer.

Source

pub fn is_empty(&self) -> bool

Whether the output buffer is empty.

Source

pub fn begin(&mut self) -> usize

Starts a fresh payload (root at offset 0).

Source

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

Writes a fixed-width u8.

Source

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

Writes a fixed-width u16.

Source

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

Writes a fixed-width u32.

Source

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

Writes a fixed-width u64.

Source

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

Writes a fixed-width i8.

Source

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

Writes a fixed-width i16.

Source

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

Writes a fixed-width i32.

Source

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

Writes a fixed-width i64.

Source

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

Writes a fixed-width f32.

Source

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

Writes a fixed-width f64.

Source

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

Writes a fixed-width bool.

Source

pub fn reserve_ptr(&mut self) -> usize

Reserves a 4-byte placeholder for a RelPtr and returns the absolute position of the placeholder.

Source

pub fn align_to(&mut self, align: usize)

Pads the output with zero bytes until the length is a multiple of align.

The archived mirrors are #[repr(C)] structs, so the writer inserts the same padding between fields (and before Vec<T> element arrays) that the C ABI does. A zero align would divide by zero; the derive only ever passes real type alignments (1, 2, 4, or 8).

Source

pub fn write_string_at( &mut self, field_pos: usize, value: &str, ) -> Result<(), String>

Appends a String body and patches the placeholder at field_pos.

Source

pub fn write_vec_at<T: Pod>( &mut self, field_pos: usize, values: &[T], ) -> Result<(), String>

Appends a Vec<T> body (count + alignment padding + elements) and patches the placeholder.

Source

pub fn patch_ptr( &mut self, field_pos: usize, data_pos: usize, ) -> Result<(), String>

Patches the placeholder at field_pos with the offset from field_pos to data_pos.

Source

pub fn finish(self) -> Vec<u8> ⓘ

Returns the complete payload.

Trait Implementations§

Source§

impl Default for ArchiveSerializer

Source§

fn default() -> Self

Returns the “default value” for a type. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.