pub struct WriteBuffer { /* private fields */ }Expand description
A buffer for writing TNS protocol data
Implementations§
Source§impl WriteBuffer
impl WriteBuffer
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new WriteBuffer with specified capacity
Sourcepub fn with_max_capacity(capacity: usize, max_capacity: usize) -> Self
pub fn with_max_capacity(capacity: usize, max_capacity: usize) -> Self
Create a new WriteBuffer with a maximum capacity limit
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Get the remaining writable space
Sourcepub fn into_inner(self) -> BytesMut
pub fn into_inner(self) -> BytesMut
Consume the buffer and return the underlying BytesMut
Sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<()>
Write raw bytes
Sourcepub fn write_zeros(&mut self, n: usize) -> Result<()>
pub fn write_zeros(&mut self, n: usize) -> Result<()>
Write zeros
Sourcepub fn write_u16_be(&mut self, value: u16) -> Result<()>
pub fn write_u16_be(&mut self, value: u16) -> Result<()>
Write a 16-bit unsigned integer in big-endian format
Sourcepub fn write_u16_le(&mut self, value: u16) -> Result<()>
pub fn write_u16_le(&mut self, value: u16) -> Result<()>
Write a 16-bit unsigned integer in little-endian format
Sourcepub fn write_u32_be(&mut self, value: u32) -> Result<()>
pub fn write_u32_be(&mut self, value: u32) -> Result<()>
Write a 32-bit unsigned integer in big-endian format
Sourcepub fn write_u64_be(&mut self, value: u64) -> Result<()>
pub fn write_u64_be(&mut self, value: u64) -> Result<()>
Write a 64-bit unsigned integer in big-endian format
Sourcepub fn write_ub2(&mut self, value: u16) -> Result<()>
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)
Sourcepub fn write_ub4(&mut self, value: u32) -> Result<()>
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)
Sourcepub fn write_ub8(&mut self, value: u64) -> Result<()>
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)
Sourcepub fn write_bytes_with_length(&mut self, bytes: Option<&[u8]>) -> Result<()>
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
Sourcepub fn write_string_with_length(&mut self, s: Option<&str>) -> Result<()>
pub fn write_string_with_length(&mut self, s: Option<&str>) -> Result<()>
Write a TNS length-prefixed string (UTF-8)
Sourcepub fn write_oracle_int(&mut self, value: i64) -> Result<()>
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.
Sourcepub fn write_oracle_uint(&mut self, value: u64) -> Result<()>
pub fn write_oracle_uint(&mut self, value: u64) -> Result<()>
Write an Oracle-encoded unsigned integer
Sourcepub fn truncate(&mut self, len: usize)
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
Trait Implementations§
Source§impl AsRef<[u8]> for WriteBuffer
impl AsRef<[u8]> for WriteBuffer
Source§impl Debug for WriteBuffer
impl Debug for WriteBuffer
Auto Trait Implementations§
impl Freeze for WriteBuffer
impl RefUnwindSafe for WriteBuffer
impl Send for WriteBuffer
impl Sync for WriteBuffer
impl Unpin for WriteBuffer
impl UnwindSafe for WriteBuffer
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)