ReadBuffer

Struct ReadBuffer 

Source
pub struct ReadBuffer { /* private fields */ }
Expand description

A buffer for reading TNS protocol data

Implementations§

Source§

impl ReadBuffer

Source

pub fn new(data: Bytes) -> Self

Create a new ReadBuffer from bytes

Source

pub fn from_slice(data: &[u8]) -> Self

Create a new ReadBuffer from a byte slice

Source

pub fn from_vec(data: Vec<u8>) -> Self

Create a new ReadBuffer from a Vec

Source

pub fn position(&self) -> usize

Get the current position in the buffer

Source

pub fn len(&self) -> usize

Get the total length of the buffer

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty

Source

pub fn remaining(&self) -> usize

Get the number of bytes remaining to be read

Source

pub fn remaining_bytes(&self) -> &[u8]

Get a slice of the remaining bytes (without advancing position)

Source

pub fn has_remaining(&self, n: usize) -> bool

Check if there are at least n bytes remaining

Source

pub fn skip(&mut self, n: usize) -> Result<()>

Skip n bytes in the buffer

Source

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.

Source

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.

Source

pub fn reset(&mut self)

Reset the buffer position to the beginning

Source

pub fn set_position(&mut self, pos: usize) -> Result<()>

Set the buffer position

Source

pub fn remaining_slice(&self) -> &[u8]

Get a slice of the remaining data

Source

pub fn as_bytes(&self) -> &Bytes

Get the underlying bytes

Source

pub fn read_u8(&mut self) -> Result<u8>

Read a single byte

Source

pub fn read_bytes(&mut self, buf: &mut [u8]) -> Result<()>

Read raw bytes into a slice

Source

pub fn read_bytes_owned(&mut self, n: usize) -> Result<Bytes>

Read raw bytes and return as a new Bytes

Source

pub fn read_bytes_vec(&mut self, n: usize) -> Result<Vec<u8>>

Read raw bytes and return as a Vec

Source

pub fn read_u16_be(&mut self) -> Result<u16>

Read a 16-bit unsigned integer in big-endian format

Source

pub fn read_i16_be(&mut self) -> Result<i16>

Read a 16-bit signed integer in big-endian format

Source

pub fn read_u16_le(&mut self) -> Result<u16>

Read a 16-bit unsigned integer in little-endian format

Source

pub fn read_u32_be(&mut self) -> Result<u32>

Read a 32-bit unsigned integer in big-endian format

Source

pub fn read_u64_be(&mut self) -> Result<u64>

Read a 64-bit unsigned integer in big-endian format

Source

pub fn read_ub1(&mut self) -> Result<u8>

Read a TNS UB1 (unsigned byte)

Source

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
Source

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

Source

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
Source

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
Source

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
Source

pub fn read_string_with_length(&mut self) -> Result<Option<String>>

Read a TNS length-prefixed string (UTF-8)

Source

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:

  1. UB4 (length-prefixed u32) giving the byte count as an indicator
  2. If > 0, a TNS length-prefixed byte sequence (another length prefix + data)

Python’s read_str_with_length uses this format.

Source

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.

Source

pub fn read_oracle_uint(&mut self) -> Result<u64>

Read an Oracle unsigned integer

Source

pub fn skip_ub1(&mut self) -> Result<()>

Skip a UB1

Source

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

Source

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

Source

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

Source

pub fn peek_u8(&self) -> Result<u8>

Peek at the next byte without consuming it

Source

pub fn peek_bytes(&self, n: usize) -> Result<&[u8]>

Peek at the next n bytes without consuming them

Trait Implementations§

Source§

impl Debug for ReadBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&[u8]> for ReadBuffer

Source§

fn from(data: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for ReadBuffer

Source§

fn from(data: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for ReadBuffer

Source§

fn from(data: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more