pub trait ToWireValue {
// Required methods
fn natural_oid(&self) -> Oid;
fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>;
}Expand description
Trait for encoding Rust values as PostgreSQL parameters.
Implementations write length-prefixed data directly to the buffer:
- Int32 length followed by the value bytes, OR
- Int32 -1 for NULL
The trait provides OID-aware encoding:
natural_oid()returns the OID this value naturally encodes toencode()encodes the value for a specific target OID, using the preferred format (text for NUMERIC, binary for everything else)
Required Methods§
Sourcefn natural_oid(&self) -> Oid
fn natural_oid(&self) -> Oid
The OID this value naturally encodes to.
For example, i64 naturally encodes to INT8 (OID 20).
Sourcefn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>
fn encode(&self, target_oid: Oid, buf: &mut Vec<u8>) -> Result<()>
Encode this value for the given target OID.
This allows flexible encoding: an i64 can encode as INT2, INT4, or INT8 depending on what the server expects (with overflow checking).
The format (text vs binary) is determined by preferred_format(target_oid):
- NUMERIC uses text format (decimal string representation)
- All other types use binary format
The implementation should write:
- 4-byte length (i32, big-endian)
- followed by the encoded data
For NULL values, write -1 as the length (no data follows).