WriteBuffer

Struct WriteBuffer 

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

A buffer for writing TNS protocol data

Implementations§

Source§

impl WriteBuffer

Source

pub fn new() -> Self

Create a new WriteBuffer with default capacity

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new WriteBuffer with specified capacity

Source

pub fn with_max_capacity(capacity: usize, max_capacity: usize) -> Self

Create a new WriteBuffer with a maximum capacity limit

Source

pub fn len(&self) -> usize

Get the current length of data in the buffer

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty

Source

pub fn capacity(&self) -> usize

Get the capacity of the buffer

Source

pub fn remaining_capacity(&self) -> usize

Get the remaining writable space

Source

pub fn clear(&mut self)

Clear the buffer

Source

pub fn reserve(&mut self, additional: usize)

Reserve additional capacity

Source

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

Get the buffer contents as a byte slice

Source

pub fn into_inner(self) -> BytesMut

Consume the buffer and return the underlying BytesMut

Source

pub fn freeze(self) -> Bytes

Freeze the buffer into immutable Bytes

Source

pub fn inner_mut(&mut self) -> &mut BytesMut

Get mutable access to the underlying BytesMut

Source

pub fn write_u8(&mut self, value: u8) -> Result<()>

Write a single byte

Source

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

Write raw bytes

Source

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

Write zeros

Source

pub fn write_u16_be(&mut self, value: u16) -> Result<()>

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

Source

pub fn write_u16_le(&mut self, value: u16) -> Result<()>

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

Source

pub fn write_u32_be(&mut self, value: u32) -> Result<()>

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

Source

pub fn write_u64_be(&mut self, value: u64) -> Result<()>

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

Source

pub fn write_ub1(&mut self, value: u8) -> Result<()>

Write a TNS UB1 (unsigned byte)

Source

pub fn write_ub2(&mut self, value: u16) -> Result<()>

Write a TNS UB2 (unsigned 2-byte, variable length encoded)

TNS UB2 uses a length-prefixed encoding where:

  • 0: write 0x00
  • 1-255: write 0x01 + 1 byte
  • 256-65535: write 0x02 + 2 bytes (big-endian)
Source

pub fn write_ub4(&mut self, value: u32) -> Result<()>

Write a TNS UB4 (unsigned 4-byte, variable length encoded)

TNS UB4 uses a variable-length encoding where:

  • 0: write 0x00
  • 1-255: write 0x01 + 1 byte
  • 256-65535: write 0x02 + 2 bytes (big-endian)
  • 65535: write 0x04 + 4 bytes (big-endian)

Source

pub fn write_ub8(&mut self, value: u64) -> Result<()>

Write a TNS UB8 (unsigned 8-byte, variable length encoded)

TNS UB8 uses a variable-length encoding where:

  • 0: write 0x00
  • 1-255: write 0x01 + 1 byte
  • 256-65535: write 0x02 + 2 bytes (big-endian)
  • 65536-4294967295: write 0x04 + 4 bytes (big-endian)
  • 4294967295: write 0x08 + 8 bytes (big-endian)

Source

pub fn write_bytes_with_length(&mut self, bytes: Option<&[u8]>) -> Result<()>

Write a TNS length-prefixed byte sequence

If bytes is None, writes NULL_INDICATOR (255). For data > 252 bytes, uses chunked encoding:

  • Write LONG_INDICATOR (254)
  • For each chunk up to 32767 bytes: write ub4(chunk_len) + raw bytes
  • Write ub4(0) to terminate
Source

pub fn write_string_with_length(&mut self, s: Option<&str>) -> Result<()>

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

Source

pub fn write_oracle_int(&mut self, value: i64) -> Result<()>

Write an Oracle-encoded integer

Oracle encodes integers with a length prefix indicating the number of bytes. Negative numbers have the high bit set in the length byte.

Source

pub fn write_oracle_uint(&mut self, value: u64) -> Result<()>

Write an Oracle-encoded unsigned integer

Source

pub fn truncate(&mut self, len: usize)

Set the current position (for patching previously written data)

Note: This truncates the buffer to the given position

Source

pub fn patch_u16_be(&mut self, pos: usize, value: u16) -> Result<()>

Patch a u16 at a specific position (big-endian)

This allows writing a placeholder and then patching it later (e.g., for packet length fields)

Source

pub fn patch_u32_be(&mut self, pos: usize, value: u32) -> Result<()>

Patch a u32 at a specific position (big-endian)

Trait Implementations§

Source§

impl AsRef<[u8]> for WriteBuffer

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for WriteBuffer

Source§

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

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

impl Default for WriteBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
§

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