pub struct Chisel<S> { /* private fields */ }Expand description
An object providing structured access to an underlying byte-stream.
A Chisel is an abstraction over some “source” of bytes that allows reading
data in a structured manner.
See the crate documentation for more information.
Implementations§
Source§impl<'a> Chisel<&'a [u8]>
impl<'a> Chisel<&'a [u8]>
Sourcepub fn from_array(buf: &'a [u8]) -> Self
pub fn from_array(buf: &'a [u8]) -> Self
Create a new Chisel, with its source being an array of bytes.
Source§impl<'a, T: Read> Chisel<ChiselSourceRead<'a, T>>
impl<'a, T: Read> Chisel<ChiselSourceRead<'a, T>>
Sourcepub fn from_read(read: &'a mut T) -> Self
pub fn from_read(read: &'a mut T) -> Self
Create a new Chisel, with its source being a Read implementation.
Note that typical chiseling operations involve a lot of individual calls to read.
As such, it is recommended to instead use from_buf_read
whenever possible.
Only use this constructor in the rare circumstance in which it is absolutely necessary to perform direct, unbuffered reads from an I/O source.
Source§impl<'a, T: BufRead> Chisel<ChiselSourceBufRead<'a, T>>
impl<'a, T: BufRead> Chisel<ChiselSourceBufRead<'a, T>>
Sourcepub fn from_buf_read(read: &'a mut T) -> Self
pub fn from_buf_read(read: &'a mut T) -> Self
Create a new Chisel, with its source being a BufRead implementation.
Source§impl<S: ChiselSource> Chisel<S>
impl<S: ChiselSource> Chisel<S>
Sourcepub fn error<E>(&self, err: E, backstep: usize) -> ChiselError<E, S::Error>
pub fn error<E>(&self, err: E, backstep: usize) -> ChiselError<E, S::Error>
Returns a format error that occurred backstep bytes ago.
This is a convenience method for manually determining the appropriate byte offset and calling ChiselError::format.
Sourcepub fn little_endian(&mut self) -> ChiselLittleEndian<'_, S>
pub fn little_endian(&mut self) -> ChiselLittleEndian<'_, S>
Returns an Endianness::Little-wrapper around this chisel. The wrapper reads values in the little-endian byte order.
Sourcepub fn big_endian(&mut self) -> ChiselBigEndian<'_, S>
pub fn big_endian(&mut self) -> ChiselBigEndian<'_, S>
Returns an Endianness::Big-wrapper around this chisel. The wrapper reads values in the big-endian byte order.
Sourcepub fn read_buf(&mut self, buf: &mut [u8]) -> InfallibleFormatResult<(), S>
pub fn read_buf(&mut self, buf: &mut [u8]) -> InfallibleFormatResult<(), S>
Fills a provided buffer with bytes from the source.
§Errors
This function returns an ChiselErrorData::EndOfInput if the end of the input is encountered
before the buffer is completely filled.
If an error is returned, the contents of buf are unspecified and the chisel breaks.
Sourcepub fn u8(&mut self) -> InfallibleFormatResult<u8, S>
pub fn u8(&mut self) -> InfallibleFormatResult<u8, S>
Reads a single byte u8.
As this function only reads a single byte, no endianness is required.
Sourcepub fn u16(&mut self, endian: Endianness) -> InfallibleFormatResult<u16, S>
pub fn u16(&mut self, endian: Endianness) -> InfallibleFormatResult<u16, S>
Sourcepub fn u32(&mut self, endian: Endianness) -> InfallibleFormatResult<u32, S>
pub fn u32(&mut self, endian: Endianness) -> InfallibleFormatResult<u32, S>
Sourcepub fn u64(&mut self, endian: Endianness) -> InfallibleFormatResult<u64, S>
pub fn u64(&mut self, endian: Endianness) -> InfallibleFormatResult<u64, S>
Sourcepub fn i8(&mut self) -> InfallibleFormatResult<i8, S>
pub fn i8(&mut self) -> InfallibleFormatResult<i8, S>
Reads a single signed byte i8.
As this function only reads a single byte, no endianness is required.
Sourcepub fn i16(&mut self, endian: Endianness) -> InfallibleFormatResult<i16, S>
pub fn i16(&mut self, endian: Endianness) -> InfallibleFormatResult<i16, S>
Sourcepub fn i32(&mut self, endian: Endianness) -> InfallibleFormatResult<i32, S>
pub fn i32(&mut self, endian: Endianness) -> InfallibleFormatResult<i32, S>
Sourcepub fn i64(&mut self, endian: Endianness) -> InfallibleFormatResult<i64, S>
pub fn i64(&mut self, endian: Endianness) -> InfallibleFormatResult<i64, S>
Sourcepub fn f32(&mut self, endian: Endianness) -> InfallibleFormatResult<f32, S>
pub fn f32(&mut self, endian: Endianness) -> InfallibleFormatResult<f32, S>
Sourcepub fn f64(&mut self, endian: Endianness) -> InfallibleFormatResult<f64, S>
pub fn f64(&mut self, endian: Endianness) -> InfallibleFormatResult<f64, S>
Sourcepub fn skip(&mut self, how_many: usize) -> InfallibleFormatResult<(), S>
pub fn skip(&mut self, how_many: usize) -> InfallibleFormatResult<(), S>
Skips how_many bytes of the underlying source.
This is provided for optimization reasons. This hint is forwarded to the source.
Exactly how_many bytes are skipped, as-if read_buf were called with a buffer
of appropriate size, with the buffer being discarded.
§Errors
If an end-of-input condition occurs before how_many bytes are skipped, an ChiselErrorData::EndOfInput error is returned.
If an error is returned, the chisel breaks.
Sourcepub fn read_until(
&mut self,
delimiter: u8,
dest: &mut Vec<u8>,
) -> InfallibleFormatResult<(), S>
pub fn read_until( &mut self, delimiter: u8, dest: &mut Vec<u8>, ) -> InfallibleFormatResult<(), S>
Reads bytes into the provided dest Vec until the delimiter byte is encountered.
§Errors
If the end of the input is encountered before the delimiter is found, ChiselErrorData::EndOfInput is returned.
If an error is returned, the chisel breaks.