Struct SbeCursor
pub struct SbeCursor<'a> { /* private fields */ }Expand description
Zero-copy SBE byte cursor for sequential decoding.
Wraps a byte slice and tracks position, providing typed read methods that automatically advance the cursor.
Implementations§
§impl<'a> SbeCursor<'a>
impl<'a> SbeCursor<'a>
pub const fn new_at(buf: &'a [u8], pos: usize) -> SbeCursor<'a>
pub const fn new_at(buf: &'a [u8], pos: usize) -> SbeCursor<'a>
Creates a cursor starting at a specific offset.
pub fn require(&self, n: usize) -> Result<(), SbeDecodeError>
pub fn require(&self, n: usize) -> Result<(), SbeDecodeError>
pub fn advance(&mut self, n: usize) -> Result<(), SbeDecodeError>
pub fn advance(&mut self, n: usize) -> Result<(), SbeDecodeError>
pub fn skip(&mut self, n: usize)
pub fn skip(&mut self, n: usize)
Skips n bytes without bounds checking.
Caller must ensure n bytes are available.
pub fn reset(&mut self)
pub fn reset(&mut self)
Resets cursor to start of buffer.
pub fn read_u8(&mut self) -> Result<u8, SbeDecodeError>
pub fn read_u8(&mut self) -> Result<u8, SbeDecodeError>
pub fn read_i8(&mut self) -> Result<i8, SbeDecodeError>
pub fn read_i8(&mut self) -> Result<i8, SbeDecodeError>
pub fn read_u16_le(&mut self) -> Result<u16, SbeDecodeError>
pub fn read_u16_le(&mut self) -> Result<u16, SbeDecodeError>
Reads a u16 little-endian and advances by 2 bytes.
§Errors
Returns BufferTooShort if fewer than 2 bytes remain.
pub fn read_i16_le(&mut self) -> Result<i16, SbeDecodeError>
pub fn read_i16_le(&mut self) -> Result<i16, SbeDecodeError>
Reads an i16 little-endian and advances by 2 bytes.
§Errors
Returns BufferTooShort if fewer than 2 bytes remain.
pub fn read_u32_le(&mut self) -> Result<u32, SbeDecodeError>
pub fn read_u32_le(&mut self) -> Result<u32, SbeDecodeError>
Reads a u32 little-endian and advances by 4 bytes.
§Errors
Returns BufferTooShort if fewer than 4 bytes remain.
pub fn read_i32_le(&mut self) -> Result<i32, SbeDecodeError>
pub fn read_i32_le(&mut self) -> Result<i32, SbeDecodeError>
Reads an i32 little-endian and advances by 4 bytes.
§Errors
Returns BufferTooShort if fewer than 4 bytes remain.
pub fn read_u64_le(&mut self) -> Result<u64, SbeDecodeError>
pub fn read_u64_le(&mut self) -> Result<u64, SbeDecodeError>
Reads a u64 little-endian and advances by 8 bytes.
§Errors
Returns BufferTooShort if fewer than 8 bytes remain.
pub fn read_i64_le(&mut self) -> Result<i64, SbeDecodeError>
pub fn read_i64_le(&mut self) -> Result<i64, SbeDecodeError>
Reads an i64 little-endian and advances by 8 bytes.
§Errors
Returns BufferTooShort if fewer than 8 bytes remain.
pub fn read_u128_le(&mut self) -> Result<u128, SbeDecodeError>
pub fn read_u128_le(&mut self) -> Result<u128, SbeDecodeError>
Reads a u128 little-endian and advances by 16 bytes.
§Errors
Returns BufferTooShort if fewer than 16 bytes remain.
pub fn read_i128_le(&mut self) -> Result<i128, SbeDecodeError>
pub fn read_i128_le(&mut self) -> Result<i128, SbeDecodeError>
Reads an i128 little-endian and advances by 16 bytes.
§Errors
Returns BufferTooShort if fewer than 16 bytes remain.
pub fn read_optional_i64_le(&mut self) -> Result<Option<i64>, SbeDecodeError>
pub fn read_optional_i64_le(&mut self) -> Result<Option<i64>, SbeDecodeError>
Reads an optional i64 where i64::MIN represents None.
§Errors
Returns BufferTooShort if fewer than 8 bytes remain.
pub fn read_bytes(&mut self, n: usize) -> Result<&'a [u8], SbeDecodeError>
pub fn read_bytes(&mut self, n: usize) -> Result<&'a [u8], SbeDecodeError>
pub fn read_var_string8(&mut self) -> Result<String, SbeDecodeError>
pub fn read_var_string8(&mut self) -> Result<String, SbeDecodeError>
Reads a varString8 (1-byte length prefix + UTF-8 data).
Returns empty string if length is 0.
§Errors
Returns BufferTooShort if the buffer is too short, or InvalidUtf8 if the data
is not valid UTF-8.
pub fn read_var_string8_ref(&mut self) -> Result<&'a str, SbeDecodeError>
pub fn read_var_string8_ref(&mut self) -> Result<&'a str, SbeDecodeError>
Reads a varString8 as a &str (zero-copy).
§Errors
Returns BufferTooShort if the buffer is too short, or InvalidUtf8 if the data
is not valid UTF-8.
pub fn read_var_string16(&mut self) -> Result<String, SbeDecodeError>
pub fn read_var_string16(&mut self) -> Result<String, SbeDecodeError>
Reads a varString16 (2-byte length prefix + UTF-8 data).
Returns empty string if length is 0.
§Errors
Returns BufferTooShort if the buffer is too short, or InvalidUtf8 if the data
is not valid UTF-8.
pub fn read_var_string16_ref(&mut self) -> Result<&'a str, SbeDecodeError>
pub fn read_var_string16_ref(&mut self) -> Result<&'a str, SbeDecodeError>
Reads a varString16 as a &str (zero-copy).
§Errors
Returns BufferTooShort if the buffer is too short, or InvalidUtf8 if the data
is not valid UTF-8.
pub fn skip_var_data8(&mut self) -> Result<(), SbeDecodeError>
pub fn skip_var_data8(&mut self) -> Result<(), SbeDecodeError>
Skips a varData8 field (1-byte length prefix + binary data).
Used for skipping binary fields that should not be decoded as UTF-8.
§Errors
Returns BufferTooShort if the buffer is too short.
pub fn read_var_bytes8(&mut self) -> Result<Vec<u8>, SbeDecodeError>
pub fn read_var_bytes8(&mut self) -> Result<Vec<u8>, SbeDecodeError>
Reads a varData8 field (1-byte length prefix + binary data).
Returns the raw bytes without UTF-8 decoding.
§Errors
Returns BufferTooShort if the buffer is too short.
pub fn skip_var_data16(&mut self) -> Result<(), SbeDecodeError>
pub fn skip_var_data16(&mut self) -> Result<(), SbeDecodeError>
Skips a varData16 field (2-byte length prefix + binary data).
§Errors
Returns BufferTooShort if the buffer is too short.
pub fn read_var_bytes16(&mut self) -> Result<Vec<u8>, SbeDecodeError>
pub fn read_var_bytes16(&mut self) -> Result<Vec<u8>, SbeDecodeError>
Reads a varData16 field (2-byte length prefix + binary data).
Returns the raw bytes without UTF-8 decoding.
§Errors
Returns BufferTooShort if the buffer is too short.
pub fn read_group_header(&mut self) -> Result<(u16, u32), SbeDecodeError>
pub fn read_group_header(&mut self) -> Result<(u16, u32), SbeDecodeError>
Reads group header (u16 block_length + u32 num_in_group).
Returns (block_length, num_in_group).
§Errors
Returns BufferTooShort if fewer than 6 bytes are available and
GroupSizeTooLarge if num_in_group exceeds MAX_GROUP_SIZE.
pub fn read_group_header_16(&mut self) -> Result<(u16, u16), SbeDecodeError>
pub fn read_group_header_16(&mut self) -> Result<(u16, u16), SbeDecodeError>
Reads compact group header (u16 block_length + u16 num_in_group).
Returns (block_length, num_in_group).
§Errors
Returns BufferTooShort if fewer than 4 bytes are available and
GroupSizeTooLarge if num_in_group exceeds MAX_GROUP_SIZE.
pub fn read_group<T, F>(
&mut self,
block_length: u16,
num_in_group: u32,
decode_item: F,
) -> Result<Vec<T>, SbeDecodeError>
pub fn read_group<T, F>( &mut self, block_length: u16, num_in_group: u32, decode_item: F, ) -> Result<Vec<T>, SbeDecodeError>
Iterates over a group, calling decode_item for each element.
The decoder function receives a cursor positioned at the start of each item
and should decode the item without advancing past block_length bytes.
§Errors
Returns BufferTooShort if the buffer does not contain all group entries,
or any error returned by decode_item.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for SbeCursor<'a>
impl<'a> RefUnwindSafe for SbeCursor<'a>
impl<'a> Send for SbeCursor<'a>
impl<'a> Sync for SbeCursor<'a>
impl<'a> Unpin for SbeCursor<'a>
impl<'a> UnsafeUnpin for SbeCursor<'a>
impl<'a> UnwindSafe for SbeCursor<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more