Skip to main content

PgEncoder

Struct PgEncoder 

Source
pub struct PgEncoder;
Expand description

Takes a Qail and produces wire protocol bytes. This is the “Visitor” in the visitor pattern.

Implementations§

Source§

impl PgEncoder

Source

pub const FORMAT_TEXT: i16 = 0

Wire format code for text columns.

Source

pub const FORMAT_BINARY: i16 = 1

Wire format code for binary columns.

Source

pub fn try_encode_query_string(sql: &str) -> Result<BytesMut, EncodeError>

Fallible simple-query encoder.

Source

pub fn encode_terminate() -> BytesMut

Encode a Terminate message to close the connection.

Source

pub fn encode_sync() -> BytesMut

Encode a Sync message (end of pipeline in extended query protocol).

Source

pub fn try_encode_parse( name: &str, sql: &str, param_types: &[u32], ) -> Result<BytesMut, EncodeError>

Fallible Parse message encoder.

Source

pub fn encode_bind( portal: &str, statement: &str, params: &[Option<Vec<u8>>], ) -> Result<BytesMut, EncodeError>

Encode a Bind message (bind parameters to a prepared statement). Wire format:

  • ‘B’ (1 byte) - message type
  • length (4 bytes)
  • portal name (null-terminated)
  • statement name (null-terminated)
  • format code count (2 bytes) - we use 0 (all text)
  • parameter count (2 bytes)
  • for each parameter: length (4 bytes, -1 for NULL), data
  • result format count + codes
§Arguments
  • portal — Destination portal name (empty string for unnamed).
  • statement — Source prepared statement name (empty string for unnamed).
  • params — Parameter values; None entries encode as SQL NULL.
Source

pub fn encode_bind_with_result_format( portal: &str, statement: &str, params: &[Option<Vec<u8>>], result_format: i16, ) -> Result<BytesMut, EncodeError>

Encode a Bind message with explicit result-column format.

result_format is PostgreSQL wire format code: 0 = text, 1 = binary. For 0, this encodes “result format count = 0” (server default text). For non-zero codes, this encodes one explicit result format code.

Source

pub fn try_encode_execute( portal: &str, max_rows: i32, ) -> Result<BytesMut, EncodeError>

Fallible Execute message encoder.

Source

pub fn try_encode_describe( is_portal: bool, name: &str, ) -> Result<BytesMut, EncodeError>

Fallible Describe message encoder.

Source

pub fn encode_extended_query( sql: &str, params: &[Option<Vec<u8>>], ) -> Result<BytesMut, EncodeError>

Encode a complete extended query pipeline (OPTIMIZED). This combines Parse + Bind + Execute + Sync in a single buffer. Zero intermediate allocations - writes directly to pre-sized BytesMut.

Source

pub fn encode_extended_query_with_result_format( sql: &str, params: &[Option<Vec<u8>>], result_format: i16, ) -> Result<BytesMut, EncodeError>

Encode a complete extended query pipeline with explicit result format.

result_format is PostgreSQL wire format code: 0 = text, 1 = binary.

Source

pub fn try_encode_copy_fail(reason: &str) -> Result<BytesMut, EncodeError>

Fallible CopyFail encoder.

Source

pub fn try_encode_close( is_portal: bool, name: &str, ) -> Result<BytesMut, EncodeError>

Fallible Close encoder.

Source§

impl PgEncoder

Source

pub fn encode_bind_ultra<'a>( buf: &mut BytesMut, statement: &str, params: &[Param<'a>], ) -> Result<(), EncodeError>

Encode Bind message - ULTRA OPTIMIZED.

  • Direct integer writes (no temp arrays)
  • Borrowed params (zero-copy)
  • Single allocation check
Source

pub fn encode_bind_ultra_with_result_format<'a>( buf: &mut BytesMut, statement: &str, params: &[Param<'a>], result_format: i16, ) -> Result<(), EncodeError>

Encode Bind message with explicit result-column format.

Source

pub fn encode_execute_ultra(buf: &mut BytesMut)

Encode Execute message - ULTRA OPTIMIZED.

Source

pub fn encode_sync_ultra(buf: &mut BytesMut)

Encode Sync message - ULTRA OPTIMIZED.

Source

pub fn encode_bind_to( buf: &mut BytesMut, statement: &str, params: &[Option<Vec<u8>>], ) -> Result<(), EncodeError>

Encode Bind message directly into existing buffer (ZERO ALLOCATION). This is the hot path optimization - no intermediate Vec allocation.

Source

pub fn encode_bind_to_with_result_format( buf: &mut BytesMut, statement: &str, params: &[Option<Vec<u8>>], result_format: i16, ) -> Result<(), EncodeError>

Encode Bind into existing buffer with explicit result-column format.

Source

pub fn encode_execute_to(buf: &mut BytesMut)

Encode Execute message directly into existing buffer (ZERO ALLOCATION).

Source

pub fn encode_sync_to(buf: &mut BytesMut)

Encode Sync message directly into existing buffer (ZERO ALLOCATION).

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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> ColumnValue<Value> for T