Skip to main content

BufferWriter

Struct BufferWriter 

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

Buffer writer for creating binary protocol messages

This implementation uses BytesMut from the bytes crate for efficient buffer operations.

Implementations§

Source§

impl BufferWriter

Source

pub fn new() -> Self

Create a new buffer writer with initial capacity

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new buffer writer with specified capacity

Source

pub fn position(&self) -> usize

Get current position in the buffer

Source

pub fn bytes_written(&self) -> usize

Get bytes written so far

Source

pub fn freeze(self) -> Bytes

Get the data as bytes

Source

pub fn into_vec(self) -> Vec<u8>

Get the data as a Vec<u8>

Source

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

Write a single byte

Source

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

Write a 16-bit unsigned integer in network byte order

Source

pub fn write_i16(&mut self, value: i16) -> Result<()>

Write a 16-bit signed integer in network byte order

Source

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

Write a 32-bit unsigned integer in network byte order

Source

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

Write a 64-bit unsigned integer in network byte order

Source

pub fn write_i32(&mut self, value: i32) -> Result<()>

Write a 32-bit signed integer in network byte order

Source

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

Write a 64-bit signed integer in network byte order

Source

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

Write raw bytes

Source

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

Write a null-terminated string

Rejects strings containing embedded null bytes, which would produce malformed PostgreSQL protocol messages (the null byte is the terminator).

Source

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

Write a string without null terminator

Source

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

Reserve capacity for at least additional bytes

Source

pub fn clear(&mut self)

Clear the buffer, resetting length to 0

Source

pub fn capacity(&self) -> usize

Get remaining capacity

Source

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

Get a reference to the internal data

Trait Implementations§

Source§

impl AsRef<[u8]> for BufferWriter

Source§

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

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

impl Default for BufferWriter

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

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

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
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