pub struct ReadBuffer { /* private fields */ }Expand description
A buffer for reading TNS protocol data
Implementations§
Source§impl ReadBuffer
impl ReadBuffer
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Create a new ReadBuffer from a byte slice
Sourcepub fn remaining_bytes(&self) -> &[u8] ⓘ
pub fn remaining_bytes(&self) -> &[u8] ⓘ
Get a slice of the remaining bytes (without advancing position)
Sourcepub fn has_remaining(&self, n: usize) -> bool
pub fn has_remaining(&self, n: usize) -> bool
Check if there are at least n bytes remaining
Sourcepub fn skip_raw_bytes_chunked(&mut self) -> Result<()>
pub fn skip_raw_bytes_chunked(&mut self) -> Result<()>
Skip raw bytes that may be chunked
This is used for skipping variable-length data in Oracle’s TTC protocol. The first byte gives the length. If the length is TNS_LONG_LENGTH_INDICATOR (254), then chunks are read and discarded until a chunk with length 0 is found.
Sourcepub fn read_raw_bytes_chunked(&mut self) -> Result<Vec<u8>>
pub fn read_raw_bytes_chunked(&mut self) -> Result<Vec<u8>>
Read raw bytes that may be chunked
This is used for reading variable-length data in Oracle’s TTC protocol. The first byte gives the length. If the length is TNS_LONG_LENGTH_INDICATOR (254), then chunks are read and concatenated until a chunk with length 0 is found.
Sourcepub fn set_position(&mut self, pos: usize) -> Result<()>
pub fn set_position(&mut self, pos: usize) -> Result<()>
Set the buffer position
Sourcepub fn remaining_slice(&self) -> &[u8] ⓘ
pub fn remaining_slice(&self) -> &[u8] ⓘ
Get a slice of the remaining data
Sourcepub fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
pub fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>
Read raw bytes into a slice
Sourcepub fn read_bytes_owned(&mut self, n: usize) -> Result<Bytes>
pub fn read_bytes_owned(&mut self, n: usize) -> Result<Bytes>
Read raw bytes and return as a new Bytes
Sourcepub fn read_bytes_vec(&mut self, n: usize) -> Result<Vec<u8>>
pub fn read_bytes_vec(&mut self, n: usize) -> Result<Vec<u8>>
Read raw bytes and return as a Vec
Sourcepub fn read_u16_be(&mut self) -> Result<u16>
pub fn read_u16_be(&mut self) -> Result<u16>
Read a 16-bit unsigned integer in big-endian format
Sourcepub fn read_i16_be(&mut self) -> Result<i16>
pub fn read_i16_be(&mut self) -> Result<i16>
Read a 16-bit signed integer in big-endian format
Sourcepub fn read_u16_le(&mut self) -> Result<u16>
pub fn read_u16_le(&mut self) -> Result<u16>
Read a 16-bit unsigned integer in little-endian format
Sourcepub fn read_u32_be(&mut self) -> Result<u32>
pub fn read_u32_be(&mut self) -> Result<u32>
Read a 32-bit unsigned integer in big-endian format
Sourcepub fn read_u64_be(&mut self) -> Result<u64>
pub fn read_u64_be(&mut self) -> Result<u64>
Read a 64-bit unsigned integer in big-endian format
Sourcepub fn read_ub2(&mut self) -> Result<u16>
pub fn read_ub2(&mut self) -> Result<u16>
Read a TNS UB2 (unsigned 2-byte, variable length encoded)
TNS UB2 uses a length-prefixed encoding where:
- First byte is the length (0, 1, or 2)
- If length is 0: value is 0
- If length is 1: read 1 byte
- If length is 2: read 2 bytes as big-endian u16
Sourcepub fn read_sb2(&mut self) -> Result<i16>
pub fn read_sb2(&mut self) -> Result<i16>
Read a TNS SB2 (signed 2-byte, variable length encoded)
Same encoding as UB2 but returns signed i16
Sourcepub fn read_ub4(&mut self) -> Result<u32>
pub fn read_ub4(&mut self) -> Result<u32>
Read a TNS UB4 (unsigned 4-byte, variable length encoded)
TNS UB4 uses a length-prefixed encoding where:
- First byte is the length (0, 1, 2, 3, or 4)
- If length is 0: value is 0
- If length is 1: read 1 byte
- If length is 2: read 2 bytes as big-endian u16
- If length is 3: read 3 bytes
- If length is 4: read 4 bytes as big-endian u32
Sourcepub fn read_ub8(&mut self) -> Result<u64>
pub fn read_ub8(&mut self) -> Result<u64>
Read a TNS UB8 (unsigned 8-byte, variable length encoded)
TNS UB8 uses a length-prefixed encoding where:
- First byte is the length (0-8)
- Read that many bytes and interpret as big-endian integer
Sourcepub fn read_bytes_with_length(&mut self) -> Result<Option<Vec<u8>>>
pub fn read_bytes_with_length(&mut self) -> Result<Option<Vec<u8>>>
Read a TNS length-prefixed byte sequence
Returns None if the length indicator is NULL_INDICATOR (255). For data > 252 bytes, uses chunked decoding:
- Read LONG_INDICATOR (254)
- Read chunks: ub4(chunk_len) + raw bytes, until chunk_len is 0
Sourcepub fn read_string_with_length(&mut self) -> Result<Option<String>>
pub fn read_string_with_length(&mut self) -> Result<Option<String>>
Read a TNS length-prefixed string (UTF-8)
Sourcepub fn read_string_with_ub4_length(&mut self) -> Result<Option<String>>
pub fn read_string_with_ub4_length(&mut self) -> Result<Option<String>>
Read a string with UB4 outer length prefix (used for metadata strings)
This is the format used by Oracle for column names, schema names, etc. The format is:
- UB4 (length-prefixed u32) giving the byte count as an indicator
- If > 0, a TNS length-prefixed byte sequence (another length prefix + data)
Python’s read_str_with_length uses this format.
Sourcepub fn read_oracle_int(&mut self) -> Result<i64>
pub fn read_oracle_int(&mut self) -> Result<i64>
Read a fixed-size Oracle integer (used in various places)
Oracle encodes integers with a length prefix indicating the number of bytes. The actual bytes follow in big-endian order.
Sourcepub fn read_oracle_uint(&mut self) -> Result<u64>
pub fn read_oracle_uint(&mut self) -> Result<u64>
Read an Oracle unsigned integer
Sourcepub fn skip_ub2(&mut self) -> Result<()>
pub fn skip_ub2(&mut self) -> Result<()>
Skip a UB2 (length-prefixed 2-byte integer)
Format: first byte is length (0-2), followed by that many bytes
Sourcepub fn skip_ub4(&mut self) -> Result<()>
pub fn skip_ub4(&mut self) -> Result<()>
Skip a UB4 (length-prefixed 4-byte integer)
Format: first byte is length (0-4), followed by that many bytes
Sourcepub fn skip_ub8(&mut self) -> Result<()>
pub fn skip_ub8(&mut self) -> Result<()>
Skip a UB8 (length-prefixed 8-byte integer)
Format: first byte is length (0-8), followed by that many bytes
Sourcepub fn peek_bytes(&self, n: usize) -> Result<&[u8]>
pub fn peek_bytes(&self, n: usize) -> Result<&[u8]>
Peek at the next n bytes without consuming them