Trait grin_core::ser::Reader

source ·
pub trait Reader {
    // Required methods
    fn deserialization_mode(&self) -> DeserializationMode;
    fn read_u8(&mut self) -> Result<u8, Error>;
    fn read_u16(&mut self) -> Result<u16, Error>;
    fn read_u32(&mut self) -> Result<u32, Error>;
    fn read_u64(&mut self) -> Result<u64, Error>;
    fn read_i32(&mut self) -> Result<i32, Error>;
    fn read_i64(&mut self) -> Result<i64, Error>;
    fn read_bytes_len_prefix(&mut self) -> Result<Vec<u8>, Error>;
    fn read_fixed_bytes(&mut self, length: usize) -> Result<Vec<u8>, Error>;
    fn expect_u8(&mut self, val: u8) -> Result<u8, Error>;
    fn protocol_version(&self) -> ProtocolVersion;

    // Provided method
    fn read_empty_bytes(&mut self, length: usize) -> Result<(), Error> { ... }
}
Expand description

Implementations defined how different numbers and binary structures are read from an underlying stream or container (depending on implementation).

Required Methods§

source

fn deserialization_mode(&self) -> DeserializationMode

The mode this reader is reading from

source

fn read_u8(&mut self) -> Result<u8, Error>

Read a u8 from the underlying Read

source

fn read_u16(&mut self) -> Result<u16, Error>

Read a u16 from the underlying Read

source

fn read_u32(&mut self) -> Result<u32, Error>

Read a u32 from the underlying Read

source

fn read_u64(&mut self) -> Result<u64, Error>

Read a u64 from the underlying Read

source

fn read_i32(&mut self) -> Result<i32, Error>

Read a i32 from the underlying Read

source

fn read_i64(&mut self) -> Result<i64, Error>

Read a i64 from the underlying Read

source

fn read_bytes_len_prefix(&mut self) -> Result<Vec<u8>, Error>

Read a u64 len prefix followed by that number of exact bytes.

source

fn read_fixed_bytes(&mut self, length: usize) -> Result<Vec<u8>, Error>

Read a fixed number of bytes from the underlying reader.

source

fn expect_u8(&mut self, val: u8) -> Result<u8, Error>

Consumes a byte from the reader, producing an error if it doesn’t have the expected value

source

fn protocol_version(&self) -> ProtocolVersion

Access to underlying protocol version to support version specific deserialization logic.

Provided Methods§

source

fn read_empty_bytes(&mut self, length: usize) -> Result<(), Error>

Read a fixed number of “empty” bytes from the underlying reader. It is an error if any non-empty bytes encountered.

Implementors§

source§

impl<'a> Reader for StreamingReader<'a>

Note: We use read_fixed_bytes() here to ensure our “async” I/O behaves as expected.

source§

impl<'a, B: Buf> Reader for BufReader<'a, B>

source§

impl<'a, R: Read> Reader for BinReader<'a, R>

Utility wrapper for an underlying byte Reader. Defines higher level methods to read numbers, byte vectors, hashes, etc.