Struct Marshaller

Source
pub struct Marshaller<'a, C, D>
where C: AsRef<[u8]>, D: AsRef<[u8]>, Self: 'a,
{ /* private fields */ }
Expand description

Marshals instructions to and from bytecode representation.

Implementations§

Source§

impl<'a> Marshaller<'a, Vec<u8>, Vec<u8>>
where Self: 'a,

Source

pub fn new(libs: &'a LibsSeg) -> Self

Creates a new marshaller using provided set of libraries.

Source

pub fn finish(self) -> (SmallBlob, SmallBlob)

Completes marshalling, returning produced data segment.

§Panics

If marshaller position is not at byte margin.

Source§

impl<'a, C, D> Marshaller<'a, C, D>
where C: AsRef<[u8]>, D: AsRef<[u8]>, Self: 'a,

Source

pub fn with(bytecode: C, data: D, libs: &'a LibsSeg) -> Self

Create marshaller from byte string utilizing existing bytecode.

§Panics

If the length of the bytecode or data segment exceeds 0xFF.

Source

pub const fn offset(&self) -> (u16, u3)

Returns the current offset of the marshaller

Trait Implementations§

Source§

impl<'a, C, D> BytecodeRead<LibId> for Marshaller<'a, C, D>
where C: AsRef<[u8]>, D: AsRef<[u8]>, Self: 'a,

Source§

fn pos(&self) -> u16

Return the current byte offset of the cursor. Does not account for bits. If the position is exactly at EOF, returns None.
Source§

fn seek(&mut self, byte_pos: u16) -> Result<u16, CodeEofError>

Set the current cursor byte offset to the provided value if it is less than the underlying buffer length. Read more
Source§

fn is_eof(&self) -> bool

Return whether end of the bytecode is reached.
Source§

fn peek_byte(&self) -> Result<u8, CodeEofError>

Peek a single byte without moving cursor.
Source§

fn read_bool(&mut self) -> Result<bool, CodeEofError>

Read single bit as a bool value.
Source§

fn read_1bit(&mut self) -> Result<u1, CodeEofError>

Read single bit.
Source§

fn read_2bits(&mut self) -> Result<u2, CodeEofError>

Read two bits.
Source§

fn read_3bits(&mut self) -> Result<u3, CodeEofError>

Read three bits.
Source§

fn read_4bits(&mut self) -> Result<u4, CodeEofError>

Read four bits.
Source§

fn read_5bits(&mut self) -> Result<u5, CodeEofError>

Read five bits.
Source§

fn read_6bits(&mut self) -> Result<u6, CodeEofError>

Read six bits.
Source§

fn read_7bits(&mut self) -> Result<u7, CodeEofError>

Read seven bits.
Source§

fn read_byte(&mut self) -> Result<u8, CodeEofError>

Read byte.
Source§

fn read_word(&mut self) -> Result<u16, CodeEofError>

Read word.
Source§

fn read_fixed<N, const LEN: usize>( &mut self, f: impl FnOnce([u8; LEN]) -> N, ) -> Result<N, CodeEofError>

Read the fixed number of bytes and convert it into a result type. Read more
Source§

fn read_bytes(&mut self) -> Result<(SmallBlob, bool), CodeEofError>

Read variable-length byte string. Read more
Source§

fn read_ref(&mut self) -> Result<LibId, CodeEofError>
where LibId: Sized,

Read external reference id.
Source§

fn check_aligned(&self)

Check if the current cursor position is aligned to the next byte. Read more
Source§

impl<'a, C, D> BytecodeWrite<LibId> for Marshaller<'a, C, D>
where C: AsRef<[u8]> + AsMut<[u8]> + Extend<u8>, D: AsRef<[u8]> + AsMut<[u8]> + Extend<u8>, Self: 'a,

Source§

type Error = MarshallError

Error type returned during writing procedures.
Source§

fn write_1bit(&mut self, data: u1) -> Result<(), MarshallError>

Write a single bit.
Source§

fn write_2bits(&mut self, data: u2) -> Result<(), MarshallError>

Write two bits.
Source§

fn write_3bits(&mut self, data: u3) -> Result<(), MarshallError>

Write three bits.
Source§

fn write_4bits(&mut self, data: u4) -> Result<(), MarshallError>

Write four bits.
Source§

fn write_5bits(&mut self, data: u5) -> Result<(), MarshallError>

Write five bits.
Source§

fn write_6bits(&mut self, data: u6) -> Result<(), MarshallError>

Write six bits.
Source§

fn write_7bits(&mut self, data: u7) -> Result<(), MarshallError>

Write seven bits.
Source§

fn write_byte(&mut self, data: u8) -> Result<(), MarshallError>

Write byte.
Source§

fn write_word(&mut self, data: u16) -> Result<(), MarshallError>

Write word.
Source§

fn write_fixed<const LEN: usize>( &mut self, data: [u8; LEN], ) -> Result<(), Self::Error>

Write data representable as a fixed-length byte array.
Source§

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

Write variable-length byte string.
Source§

fn write_ref(&mut self, id: LibId) -> Result<(), Self::Error>

Write external reference id.
Source§

fn check_aligned(&self)

Check if the current cursor position is aligned to the next byte. Read more
Source§

fn write_bool(&mut self, data: bool) -> Result<(), Self::Error>

Write a single bit from a bool value.
Source§

impl<'a, C, D> Debug for Marshaller<'a, C, D>
where C: AsRef<[u8]>, D: AsRef<[u8]>, Self: 'a,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, C, D> Freeze for Marshaller<'a, C, D>
where C: Freeze, D: Freeze,

§

impl<'a, C, D> RefUnwindSafe for Marshaller<'a, C, D>

§

impl<'a, C, D> Send for Marshaller<'a, C, D>
where C: Send, D: Send,

§

impl<'a, C, D> Sync for Marshaller<'a, C, D>
where C: Sync, D: Sync,

§

impl<'a, C, D> Unpin for Marshaller<'a, C, D>
where C: Unpin, D: Unpin,

§

impl<'a, C, D> UnwindSafe for Marshaller<'a, C, D>
where C: UnwindSafe, D: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.