pub struct Reader<'a> { /* private fields */ }Expand description
Bounds-checked read cursor over a Bytes buffer.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn rest_slice(&self) -> &'a [u8] ⓘ
pub fn rest_slice(&self) -> &'a [u8] ⓘ
The unread bytes, without consuming them.
Sourcepub fn finish(&self) -> DecodeResult<()>
pub fn finish(&self) -> DecodeResult<()>
Fails with DecodeError::TrailingBytes unless the input is fully consumed.
Sourcepub fn take(&mut self, n: usize) -> DecodeResult<&'a [u8]>
pub fn take(&mut self, n: usize) -> DecodeResult<&'a [u8]>
Consumes n bytes and returns them as a borrowed slice.
Sourcepub fn skip(&mut self, n: usize) -> DecodeResult<()>
pub fn skip(&mut self, n: usize) -> DecodeResult<()>
Advances past n bytes.
Sourcepub fn read_bytes(&mut self, n: usize) -> DecodeResult<Bytes>
pub fn read_bytes(&mut self, n: usize) -> DecodeResult<Bytes>
Consumes n bytes and returns them as a zero-copy Bytes slice.
Sourcepub fn bytes_since(&self, start: usize) -> Bytes
pub fn bytes_since(&self, start: usize) -> Bytes
Zero-copy slice of everything read since offset start (from Reader::position).
Sourcepub fn read_rest(&mut self) -> Bytes
pub fn read_rest(&mut self) -> Bytes
Consumes and returns everything that is left (protodef restBuffer).
Sourcepub fn peek_u8(&self) -> DecodeResult<u8>
pub fn peek_u8(&self) -> DecodeResult<u8>
Returns the next byte without consuming it.
Sourcepub fn read_u8(&mut self) -> DecodeResult<u8>
pub fn read_u8(&mut self) -> DecodeResult<u8>
Reads an unsigned byte.
Sourcepub fn read_i8(&mut self) -> DecodeResult<i8>
pub fn read_i8(&mut self) -> DecodeResult<i8>
Reads a signed byte.
Sourcepub fn read_bool(&mut self) -> DecodeResult<bool>
pub fn read_bool(&mut self) -> DecodeResult<bool>
Reads a boolean. Like vanilla, any non-zero byte is true.
Sourcepub fn read_u16(&mut self) -> DecodeResult<u16>
pub fn read_u16(&mut self) -> DecodeResult<u16>
Reads a big-endian u16.
Sourcepub fn read_i16(&mut self) -> DecodeResult<i16>
pub fn read_i16(&mut self) -> DecodeResult<i16>
Reads a big-endian i16.
Sourcepub fn read_i32(&mut self) -> DecodeResult<i32>
pub fn read_i32(&mut self) -> DecodeResult<i32>
Reads a big-endian i32.
Sourcepub fn read_i64(&mut self) -> DecodeResult<i64>
pub fn read_i64(&mut self) -> DecodeResult<i64>
Reads a big-endian i64.
Sourcepub fn read_u64(&mut self) -> DecodeResult<u64>
pub fn read_u64(&mut self) -> DecodeResult<u64>
Reads a big-endian u64.
Sourcepub fn read_f32(&mut self) -> DecodeResult<f32>
pub fn read_f32(&mut self) -> DecodeResult<f32>
Reads a big-endian IEEE-754 f32.
Sourcepub fn read_f64(&mut self) -> DecodeResult<f64>
pub fn read_f64(&mut self) -> DecodeResult<f64>
Reads a big-endian IEEE-754 f64.
Sourcepub fn read_uuid(&mut self) -> DecodeResult<Uuid>
pub fn read_uuid(&mut self) -> DecodeResult<Uuid>
Reads a UUID (two big-endian 64-bit halves).
Sourcepub fn read_varint(&mut self) -> DecodeResult<i32>
pub fn read_varint(&mut self) -> DecodeResult<i32>
Reads a VarInt (at most 5 bytes).
Like vanilla, the unused high bits of a 5th byte are ignored; a 6th byte is an
error (DecodeError::VarIntTooLong).
Sourcepub fn read_varlong(&mut self) -> DecodeResult<i64>
pub fn read_varlong(&mut self) -> DecodeResult<i64>
Reads a VarLong (at most 10 bytes).
Sourcepub fn read_len_varint(&mut self, limit: usize) -> DecodeResult<usize>
pub fn read_len_varint(&mut self, limit: usize) -> DecodeResult<usize>
Reads a VarInt length prefix and checks it is non-negative and at most limit.
Sourcepub fn check_count(
&self,
count: i64,
min_elem_size: usize,
) -> DecodeResult<usize>
pub fn check_count( &self, count: i64, min_elem_size: usize, ) -> DecodeResult<usize>
Reads an array count of the given prefix width and validates it.
min_elem_size is the smallest number of bytes one element can occupy; when it is
non-zero the count is bounded by the remaining input, so a hostile count can never
cause a large allocation or a long loop.
Sourcepub fn read_byte_array(&mut self) -> DecodeResult<Bytes>
pub fn read_byte_array(&mut self) -> DecodeResult<Bytes>
Reads a VarInt-prefixed byte array as a zero-copy slice.
Sourcepub fn read_string(&mut self) -> DecodeResult<ByteString>
pub fn read_string(&mut self) -> DecodeResult<ByteString>
Reads a VarInt-prefixed UTF-8 string as a zero-copy ByteString.