pub struct PgEncoder;Expand description
PostgreSQL protocol encoder.
Takes a QailCmd and produces wire protocol bytes. This is the “Visitor” in the visitor pattern.
Implementations§
Source§impl PgEncoder
impl PgEncoder
Sourcepub fn encode_query_string(sql: &str) -> BytesMut
pub fn encode_query_string(sql: &str) -> BytesMut
Encode a raw SQL string as a Simple Query message.
Wire format:
- ‘Q’ (1 byte) - message type
- length (4 bytes, big-endian, includes self)
- query string (null-terminated)
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 encode_parse(name: &str, sql: &str, param_types: &[u32]) -> BytesMut
pub fn encode_parse(name: &str, sql: &str, param_types: &[u32]) -> BytesMut
Encode a Parse message (prepare a statement).
Wire format:
- ‘P’ (1 byte) - message type
- length (4 bytes)
- statement name (null-terminated, “” for unnamed)
- query string (null-terminated)
- parameter count (2 bytes)
- parameter OIDs (4 bytes each, 0 = infer type)
Sourcepub fn encode_bind(
portal: &str,
statement: &str,
params: &[Option<Vec<u8>>],
) -> BytesMut
pub fn encode_bind( portal: &str, statement: &str, params: &[Option<Vec<u8>>], ) -> BytesMut
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 (2 bytes) - we use 0 (all text)
Sourcepub fn encode_execute(portal: &str, max_rows: i32) -> BytesMut
pub fn encode_execute(portal: &str, max_rows: i32) -> BytesMut
Encode an Execute message (execute a bound portal).
Wire format:
- ‘E’ (1 byte) - message type
- length (4 bytes)
- portal name (null-terminated)
- max rows (4 bytes, 0 = unlimited)
Sourcepub fn encode_describe(is_portal: bool, name: &str) -> BytesMut
pub fn encode_describe(is_portal: bool, name: &str) -> BytesMut
Encode a Describe message (get statement/portal metadata).
Wire format:
- ‘D’ (1 byte) - message type
- length (4 bytes)
- ‘S’ for statement or ‘P’ for portal
- name (null-terminated)
Source§impl PgEncoder
impl PgEncoder
Sourcepub fn encode_bind_ultra<'a>(
buf: &mut BytesMut,
statement: &str,
params: &[Param<'a>],
)
pub fn encode_bind_ultra<'a>( buf: &mut BytesMut, statement: &str, params: &[Param<'a>], )
Encode Bind message - ULTRA OPTIMIZED.
- Direct integer writes (no temp arrays)
- Borrowed params (zero-copy)
- Single allocation check
Sourcepub fn encode_execute_ultra(buf: &mut BytesMut)
pub fn encode_execute_ultra(buf: &mut BytesMut)
Encode Execute message - ULTRA OPTIMIZED. Pre-computed constant bytes.
Sourcepub fn encode_sync_ultra(buf: &mut BytesMut)
pub fn encode_sync_ultra(buf: &mut BytesMut)
Encode Sync message - ULTRA OPTIMIZED. Pre-computed constant bytes.
Sourcepub fn encode_bind_to(
buf: &mut BytesMut,
statement: &str,
params: &[Option<Vec<u8>>],
)
pub fn encode_bind_to( buf: &mut BytesMut, statement: &str, params: &[Option<Vec<u8>>], )
Encode Bind message directly into existing buffer (ZERO ALLOCATION).
This is the hot path optimization - no intermediate Vec allocation.
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).