Skip to main content

BufferWriter

Struct BufferWriter 

Source
pub struct BufferWriter { /* private fields */ }
Expand description

Write buffer with alignment tracking and configurable endianness.

Phase 0 uses Vec<u8> as backing — a growing alloc feature.

Implementations§

Source§

impl BufferWriter

Source

pub fn new(endianness: Endianness) -> Self

Creates an empty writer with the given endianness (XCDR1 alignment, cap 8 — default + backward-compat).

Source

pub fn with_capacity(endianness: Endianness, cap: usize) -> Self

Creates a writer with pre-allocated capacity (XCDR1 cap 8).

Source

pub fn with_align_origin(self, origin: usize) -> Self

Builder: sets the virtual Self::align origin (default 0). For GIOP 1.2 = 12 (header size), see the align_origin field doc.

Source

pub fn with_max_alignment(self, max_alignment: usize) -> Self

Builder: sets the alignment cap (XCDR1=8, XCDR2=4). Inherited by nested member writers (see struct_enc).

Source

pub fn xcdr2(self) -> Self

Builder: switches to XCDR2 alignment (cap 4, §7.4.1.1.1).

Source

pub fn max_alignment(&self) -> usize

The current alignment cap (8 = XCDR1, 4 = XCDR2).

Source

pub fn endianness(&self) -> Endianness

Returns the current endianness.

Source

pub fn position(&self) -> usize

Current position (== number of bytes written so far).

Source

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

Consumes the writer and returns the written buffer.

Source

pub fn as_bytes(&self) -> &[u8]

Read-only view of the buffer written so far.

Source

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

Inserts null padding until the current position is a multiple of alignment. Alignment must be a power of two (1, 2, 4, 8); other values are undefined in XCDR.

Source

pub fn write_bytes(&mut self, data: &[u8]) -> Result<(), EncodeError>

Writes raw bytes without alignment.

§Errors

Never returns an error with Vec-based backing — the signature is symmetric to the slice-based writer (Phase 1).

Source

pub fn write_u8(&mut self, value: u8) -> Result<(), EncodeError>

Writes a single byte (1-byte alignment).

§Errors

As write_bytes.

Source

pub fn write_u16(&mut self, value: u16) -> Result<(), EncodeError>

Aligns + writes u16.

§Errors

As write_bytes.

Source

pub fn write_u32(&mut self, value: u32) -> Result<(), EncodeError>

Aligns + writes u32.

§Errors

As write_bytes.

Source

pub fn write_u64(&mut self, value: u64) -> Result<(), EncodeError>

Aligns + writes u64.

§Errors

As write_bytes.

Source

pub fn write_string(&mut self, s: &str) -> Result<(), EncodeError>

Writes a CDR string (§9.3.2.7): 4-byte length (incl. null terminator) + UTF-8 bytes + 1 null byte. No trailing padding — the next field aligns itself.

§Errors

As write_bytes.

Trait Implementations§

Source§

impl Clone for BufferWriter

Source§

fn clone(&self) -> BufferWriter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BufferWriter

Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.