#[non_exhaustive]pub struct BinaryCopyWriter { /* private fields */ }Expand description
Writer for PostgreSQL binary COPY format.
This struct helps encode the binary COPY protocol header, individual rows,
and the terminating trailer. Each call to write_row
appends to an internal buffer and returns a slice of the newly added bytes.
Implementations§
Source§impl BinaryCopyWriter
impl BinaryCopyWriter
Sourcepub fn new(column_count: i16) -> Self
pub fn new(column_count: i16) -> Self
Create a new binary COPY writer for the given number of columns.
Sourcepub fn column_count(&self) -> i16
pub fn column_count(&self) -> i16
Returns the number of columns this writer expects.
Sourcepub fn header(&mut self) -> &[u8] ⓘ
pub fn header(&mut self) -> &[u8] ⓘ
Generate and return the binary COPY file header.
This should be called once at the start of the COPY stream and the returned bytes sent to the server before any row data.
The header consists of:
- 15-byte magic signature:
PGCOPY\n\xff\r\n\0 - 4-byte flags (0)
- 4-byte header extension length (0)
Sourcepub fn write_row(&mut self, values: &[Option<&[u8]>]) -> &[u8] ⓘ
pub fn write_row(&mut self, values: &[Option<&[u8]>]) -> &[u8] ⓘ
Encode a single row and return the bytes.
values must have exactly column_count elements.
None represents a NULL field.
§Panics
Panics if values.len() != column_count.
Sourcepub fn trailer(&mut self) -> &[u8] ⓘ
pub fn trailer(&mut self) -> &[u8] ⓘ
Generate the binary COPY trailer (field_count = -1).
This should be sent after all row data to signal the end of the COPY stream.
Sourcepub fn into_inner(self) -> Vec<u8> ⓘ
pub fn into_inner(self) -> Vec<u8> ⓘ
Consume the writer and return the complete buffer.
Trait Implementations§
Source§impl Clone for BinaryCopyWriter
impl Clone for BinaryCopyWriter
Source§fn clone(&self) -> BinaryCopyWriter
fn clone(&self) -> BinaryCopyWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more