Struct chain_core::packer::Codec
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§
§impl<I> Codec<I>
impl<I> Codec<I>
pub fn new(inner: I) -> Codec<I>
pub fn into_inner(self) -> I
§impl Codec<()>
impl Codec<()>
pub const fn u8_size() -> usize
pub const fn u16_size() -> usize
pub const fn u32_size() -> usize
pub const fn u64_size() -> usize
pub const fn u128_size() -> usize
pub const fn i8_size() -> usize
pub const fn i16_size() -> usize
pub const fn i32_size() -> usize
pub const fn i64_size() -> usize
pub const fn i128_size() -> usize
§impl Codec<&[u8]>
impl Codec<&[u8]>
pub fn get_slice(&mut self, n: usize) -> Result<&[u8], ReadError>
pub fn skip_bytes(&mut self, pos: usize)
pub fn bytes_left(&self) -> usize
pub fn has_bytes_left(&self) -> bool
§impl<R> Codec<R>where
R: Read,
impl<R> Codec<R>where R: Read,
pub fn read_to_end( &mut self, buf: &mut Vec<u8, Global> ) -> Result<usize, ReadError>
pub fn get_u8(&mut self) -> Result<u8, ReadError>
pub fn get_be_u16(&mut self) -> Result<u16, ReadError>
pub fn get_le_u16(&mut self) -> Result<u16, ReadError>
pub fn get_be_u32(&mut self) -> Result<u32, ReadError>
pub fn get_le_u32(&mut self) -> Result<u32, ReadError>
pub fn get_be_u64(&mut self) -> Result<u64, ReadError>
pub fn get_le_u64(&mut self) -> Result<u64, ReadError>
pub fn get_be_u128(&mut self) -> Result<u128, ReadError>
pub fn get_le_u128(&mut self) -> Result<u128, ReadError>
pub fn get_nz_u32(&mut self) -> Result<NonZeroU32, ReadError>
pub fn get_nz_u64(&mut self) -> Result<NonZeroU64, ReadError>
pub fn get_bytes(&mut self, n: usize) -> Result<Vec<u8, Global>, ReadError>
pub fn copy_to_slice(&mut self, slice: &mut [u8]) -> Result<(), ReadError>
§impl<W> Codec<W>where
W: Write,
impl<W> Codec<W>where W: Write,
pub fn put_u8(&mut self, v: u8) -> Result<(), WriteError>
pub fn put_be_u16(&mut self, v: u16) -> Result<(), WriteError>
pub fn put_le_u16(&mut self, v: u16) -> Result<(), WriteError>
pub fn put_be_u32(&mut self, v: u32) -> Result<(), WriteError>
pub fn put_le_u32(&mut self, v: u32) -> Result<(), WriteError>
pub fn put_be_u64(&mut self, v: u64) -> Result<(), WriteError>
pub fn put_le_u64(&mut self, v: u64) -> Result<(), WriteError>
pub fn put_be_u128(&mut self, v: u128) -> Result<(), WriteError>
pub fn put_le_u128(&mut self, v: u128) -> Result<(), WriteError>
pub fn put_bytes(&mut self, v: &[u8]) -> Result<(), WriteError>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more