pub struct TtcReader<'a> { /* private fields */ }Implementations§
Source§impl<'a> TtcReader<'a>
impl<'a> TtcReader<'a>
pub fn new(bytes: &'a [u8]) -> Self
pub fn remaining(&self) -> usize
pub fn position(&self) -> usize
pub fn remaining_slice(&self) -> &[u8] ⓘ
pub fn peek_u8(&self) -> Result<u8>
pub fn read_u8(&mut self) -> Result<u8>
pub fn read_i8(&mut self) -> Result<i8>
pub fn read_u16be(&mut self) -> Result<u16>
pub fn read_u16le(&mut self) -> Result<u16>
pub fn read_u32be(&mut self) -> Result<u32>
pub fn read_raw(&mut self, len: usize) -> Result<&'a [u8]>
pub fn skip(&mut self, len: usize) -> Result<()>
pub fn read_ub2(&mut self) -> Result<u16>
pub fn read_ub4(&mut self) -> Result<u32>
pub fn read_sb4(&mut self) -> Result<i32>
pub fn read_sb8(&mut self) -> Result<i64>
pub fn read_ub8(&mut self) -> Result<u64>
Sourcepub fn read_bytes_borrowed(&mut self) -> Result<BorrowedBytes<'a>>
pub fn read_bytes_borrowed(&mut self) -> Result<BorrowedBytes<'a>>
Zero-copy companion to read_bytes for the borrowed
fetch path. The common short-value form (length byte 1..=253) is a single
contiguous run in the buffer, so it is returned as a borrowed slice with
no allocation. The chunked long form (0xfe) is not contiguous on the
wire (it is a sequence of length-prefixed chunks), so it cannot be
borrowed and falls back to an owned Vec — the rare path. 0/0xff
signal SQL NULL.
Consumes exactly the same number of bytes as read_bytes for every
input, so the two are interchangeable mid-stream.
Sourcepub fn skip_bytes_field(&mut self) -> Result<()>
pub fn skip_bytes_field(&mut self) -> Result<()>
Advance past one length-prefixed TTC byte field (short, NULL, or chunked
long form) without allocating — the zero-copy skip used by the
borrowed fetch offset-capture pass. Consumes exactly the bytes
read_bytes would.
pub fn read_bytes(&mut self) -> Result<Option<Vec<u8>>>
pub fn read_bytes_with_length(&mut self) -> Result<Option<Vec<u8>>>
pub fn read_string_with_length(&mut self) -> Result<Option<String>>
pub fn read_string(&mut self) -> Result<Option<String>>
Trait Implementations§
Source§impl BoundedReader for TtcReader<'_>
impl BoundedReader for TtcReader<'_>
Source§fn remaining(&self) -> usize
fn remaining(&self) -> usize
Bytes still unread in the current message buffer. The ceiling on any
count-driven allocation.
Source§fn alloc_count_checked(
&self,
count: usize,
min_bytes_per_elem: usize,
) -> Result<usize>
fn alloc_count_checked( &self, count: usize, min_bytes_per_elem: usize, ) -> Result<usize>
Validate a server-declared element
count against the buffer: a run of
count elements must carry at least count * min_bytes_per_elem bytes,
so a count whose minimum byte footprint exceeds [remaining] is a lie.
Returns the (unchanged) count when it fits, or a fail-closed
ProtocolError::TtcDecode otherwise — never a panic, never an OOM. Read moreSource§fn with_capacity_bounded<T>(
&self,
count: usize,
min_bytes_per_elem: usize,
) -> Vec<T>
fn with_capacity_bounded<T>( &self, count: usize, min_bytes_per_elem: usize, ) -> Vec<T>
Pre-size a
Vec for count elements without trusting count: the
reserved capacity is capped at remaining() / min_bytes_per_elem, the
largest number of elements the buffer could actually hold. The returned
Vec is a normal growable Vec, so a legitimately large payload (where
count really fits) is pre-sized to the honest count, and a streamed /
chunked field that grows past the initial buffer still appends correctly
— the cap only governs the speculative up-front reservation.Auto Trait Implementations§
impl<'a> Freeze for TtcReader<'a>
impl<'a> RefUnwindSafe for TtcReader<'a>
impl<'a> Send for TtcReader<'a>
impl<'a> Sync for TtcReader<'a>
impl<'a> Unpin for TtcReader<'a>
impl<'a> UnsafeUnpin for TtcReader<'a>
impl<'a> UnwindSafe for TtcReader<'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
Mutably borrows from an owned value. Read more