Struct chain_ser::packer::Codec

source ·
pub struct Codec<I> {
    inner: I,
}
Expand description

The structure to support (de)serialization of binary data format used by jormungandr.

Reading data

The structure is generally intended to read from any implementor of std::io::Read. On top of that it supports specialized methods for &[u8] (which is also std::io::Read) to facilitate zero-copy operations.

Writing data

Data can be written into any std::io::Write implementor.

Fields§

§inner: I

Implementations§

source§

impl<I> Codec<I>

source

pub fn new(inner: I) -> Self

source

pub fn into_inner(self) -> I

source§

impl Codec<()>

source

pub const fn u8_size() -> usize

source

pub const fn u16_size() -> usize

source

pub const fn u32_size() -> usize

source

pub const fn u64_size() -> usize

source

pub const fn u128_size() -> usize

source

pub const fn i8_size() -> usize

source

pub const fn i16_size() -> usize

source

pub const fn i32_size() -> usize

source

pub const fn i64_size() -> usize

source

pub const fn i128_size() -> usize

source§

impl Codec<&[u8]>

source

pub fn get_slice(&mut self, n: usize) -> Result<&[u8], ReadError>

source

pub fn skip_bytes(&mut self, pos: usize)

source

pub fn bytes_left(&self) -> usize

source

pub fn has_bytes_left(&self) -> bool

source§

impl<R: Read> Codec<R>

source

pub fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, ReadError>

source

pub fn get_u8(&mut self) -> Result<u8, ReadError>

source

pub fn get_be_u16(&mut self) -> Result<u16, ReadError>

source

pub fn get_le_u16(&mut self) -> Result<u16, ReadError>

source

pub fn get_be_u32(&mut self) -> Result<u32, ReadError>

source

pub fn get_le_u32(&mut self) -> Result<u32, ReadError>

source

pub fn get_be_u64(&mut self) -> Result<u64, ReadError>

source

pub fn get_le_u64(&mut self) -> Result<u64, ReadError>

source

pub fn get_be_u128(&mut self) -> Result<u128, ReadError>

source

pub fn get_le_u128(&mut self) -> Result<u128, ReadError>

source

pub fn get_nz_u32(&mut self) -> Result<NonZeroU32, ReadError>

source

pub fn get_nz_u64(&mut self) -> Result<NonZeroU64, ReadError>

source

pub fn get_bytes(&mut self, n: usize) -> Result<Vec<u8>, ReadError>

source

pub fn copy_to_slice(&mut self, slice: &mut [u8]) -> Result<(), ReadError>

source§

impl<W: Write> Codec<W>

source

pub fn put_u8(&mut self, v: u8) -> Result<(), WriteError>

source

pub fn put_be_u16(&mut self, v: u16) -> Result<(), WriteError>

source

pub fn put_le_u16(&mut self, v: u16) -> Result<(), WriteError>

source

pub fn put_be_u32(&mut self, v: u32) -> Result<(), WriteError>

source

pub fn put_le_u32(&mut self, v: u32) -> Result<(), WriteError>

source

pub fn put_be_u64(&mut self, v: u64) -> Result<(), WriteError>

source

pub fn put_le_u64(&mut self, v: u64) -> Result<(), WriteError>

source

pub fn put_be_u128(&mut self, v: u128) -> Result<(), WriteError>

source

pub fn put_le_u128(&mut self, v: u128) -> Result<(), WriteError>

source

pub fn put_bytes(&mut self, v: &[u8]) -> Result<(), WriteError>

source§

impl<T> Codec<Cursor<T>>

source

pub fn position(&mut self) -> usize

source

pub fn set_position(&mut self, pos: usize)

Auto Trait Implementations§

§

impl<I> RefUnwindSafe for Codec<I>where I: RefUnwindSafe,

§

impl<I> Send for Codec<I>where I: Send,

§

impl<I> Sync for Codec<I>where I: Sync,

§

impl<I> Unpin for Codec<I>where I: Unpin,

§

impl<I> UnwindSafe for Codec<I>where I: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.