Skip to main content

RecordParser

Trait RecordParser 

Source
pub(super) trait RecordParser: Send {
    // Required methods
    fn plan_input(&self, data: &[u8], budget: usize) -> (usize, usize);
    fn decode(&mut self, data: &[u8]) -> PgWireResult<(usize, usize)>;
    fn is_full(&self) -> bool;
    fn flush(&mut self) -> PgWireResult<Vec<Row>>;

    // Provided method
    fn finish(&mut self) -> PgWireResult<Vec<Row>> { ... }
}
Expand description

Incremental parser of one COPY FROM STDIN stream.

The wire protocol delivers the payload as an arbitrary sequence of CopyData chunks; implementations keep state across Self::decode calls because records (and even single fields) may span chunk boundaries. The caller reserves memory before decoding and drains each full batch before supplying more input, even when one CopyData message contains many batches.

Required Methods§

Source

fn plan_input(&self, data: &[u8], budget: usize) -> (usize, usize)

Returns the input prefix to decode and the bytes to charge for it.

Source

fn decode(&mut self, data: &[u8]) -> PgWireResult<(usize, usize)>

Consumes at most one batch, returning (bytes consumed, bytes charged) for the actual prefix, which may be shorter than the preview. An empty input signals EOF for parsers that need it to finalize a record.

Source

fn is_full(&self) -> bool

Whether a complete batch is ready to flush.

Source

fn flush(&mut self) -> PgWireResult<Vec<Row>>

Converts the buffered batch into rows. Only valid at a full batch or EOF.

Provided Methods§

Source

fn finish(&mut self) -> PgWireResult<Vec<Row>>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§