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
impl PgEncoder
Sourcepub const FORMAT_TEXT: i16 = 0
pub const FORMAT_TEXT: i16 = 0
Wire format code for text columns.
Sourcepub const FORMAT_BINARY: i16 = 1
pub const FORMAT_BINARY: i16 = 1
Wire format code for binary columns.
Sourcepub fn try_encode_query_string(sql: &str) -> Result<BytesMut, EncodeError>
pub fn try_encode_query_string(sql: &str) -> Result<BytesMut, EncodeError>
Fallible simple-query encoder.
Sourcepub fn encode_terminate() -> BytesMut
pub fn encode_terminate() -> BytesMut
Encode a Terminate message to close the connection.
Sourcepub fn encode_sync() -> BytesMut
pub fn encode_sync() -> BytesMut
Encode a Sync message (end of pipeline in extended query protocol).
Sourcepub fn try_encode_parse(
name: &str,
sql: &str,
param_types: &[u32],
) -> Result<BytesMut, EncodeError>
pub fn try_encode_parse( name: &str, sql: &str, param_types: &[u32], ) -> Result<BytesMut, EncodeError>
Fallible Parse message encoder.
Sourcepub fn encode_bind(
portal: &str,
statement: &str,
params: &[Option<Vec<u8>>],
) -> Result<BytesMut, EncodeError>
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;Noneentries encode as SQL NULL.
Sourcepub fn encode_bind_with_result_format(
portal: &str,
statement: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> Result<BytesMut, EncodeError>
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.
Sourcepub fn try_encode_execute(
portal: &str,
max_rows: i32,
) -> Result<BytesMut, EncodeError>
pub fn try_encode_execute( portal: &str, max_rows: i32, ) -> Result<BytesMut, EncodeError>
Fallible Execute message encoder.
Sourcepub fn try_encode_describe(
is_portal: bool,
name: &str,
) -> Result<BytesMut, EncodeError>
pub fn try_encode_describe( is_portal: bool, name: &str, ) -> Result<BytesMut, EncodeError>
Fallible Describe message encoder.
Sourcepub fn encode_extended_query(
sql: &str,
params: &[Option<Vec<u8>>],
) -> Result<BytesMut, EncodeError>
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.
Sourcepub fn encode_extended_query_with_result_format(
sql: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> Result<BytesMut, EncodeError>
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.
Sourcepub fn try_encode_copy_fail(reason: &str) -> Result<BytesMut, EncodeError>
pub fn try_encode_copy_fail(reason: &str) -> Result<BytesMut, EncodeError>
Fallible CopyFail encoder.
Sourcepub fn try_encode_close(
is_portal: bool,
name: &str,
) -> Result<BytesMut, EncodeError>
pub fn try_encode_close( is_portal: bool, name: &str, ) -> Result<BytesMut, EncodeError>
Fallible Close encoder.
Source§impl PgEncoder
impl PgEncoder
Sourcepub fn encode_bind_ultra<'a>(
buf: &mut BytesMut,
statement: &str,
params: &[Param<'a>],
) -> Result<(), EncodeError>
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
Sourcepub fn encode_bind_ultra_with_result_format<'a>(
buf: &mut BytesMut,
statement: &str,
params: &[Param<'a>],
result_format: i16,
) -> Result<(), EncodeError>
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.
Sourcepub fn encode_execute_ultra(buf: &mut BytesMut)
pub fn encode_execute_ultra(buf: &mut BytesMut)
Encode Execute message - ULTRA OPTIMIZED.
Sourcepub fn encode_sync_ultra(buf: &mut BytesMut)
pub fn encode_sync_ultra(buf: &mut BytesMut)
Encode Sync message - ULTRA OPTIMIZED.
Sourcepub fn encode_bind_to(
buf: &mut BytesMut,
statement: &str,
params: &[Option<Vec<u8>>],
) -> Result<(), EncodeError>
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.
Sourcepub fn encode_bind_to_with_result_format(
buf: &mut BytesMut,
statement: &str,
params: &[Option<Vec<u8>>],
result_format: i16,
) -> Result<(), EncodeError>
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.
Sourcepub fn encode_execute_to(buf: &mut BytesMut)
pub fn encode_execute_to(buf: &mut BytesMut)
Encode Execute message directly into existing buffer (ZERO ALLOCATION).
Sourcepub fn encode_sync_to(buf: &mut BytesMut)
pub fn encode_sync_to(buf: &mut BytesMut)
Encode Sync message directly into existing buffer (ZERO ALLOCATION).