pub trait RowEncoder<F: RecFamily>: Send {
// Required method
fn encode<'buf>(
&mut self,
rec: &Record<F::Rec<'buf>>,
buf: &mut BytesMut,
) -> Result<(), SinkError>;
// Provided methods
fn buffered_bytes(&self) -> usize { ... }
fn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError> { ... }
}Expand description
The CPU half of a sink connector: encodes one record into the sink’s
wire format. Runs on pinned pipeline threads inside the chain’s
terminal stage; must not perform I/O. Family-generic and dyn-compatible,
like Deserializer.
Required Methods§
Sourcefn encode<'buf>(
&mut self,
rec: &Record<F::Rec<'buf>>,
buf: &mut BytesMut,
) -> Result<(), SinkError>
fn encode<'buf>( &mut self, rec: &Record<F::Rec<'buf>>, buf: &mut BytesMut, ) -> Result<(), SinkError>
Append rec’s encoding to buf. Errors are record-level and
subject to the sink stage’s ErrorPolicy. Errors of
ErrorClass::Fatal stop the
pipeline regardless of policy; fatal means the encoder itself is
broken (e.g. the row type cannot match the target schema), so every
subsequent record would fail identically.
Provided Methods§
Sourcefn buffered_bytes(&self) -> usize
fn buffered_bytes(&self) -> usize
Bytes the encoder is holding internally that have not yet been
flushed to a frame. Row formats append directly in
encode and buffer nothing, so the default is 0.
Columnar formats (which must transpose a whole block before any bytes
exist) return the approximate size of the block under assembly; the
terminal stage adds this to the shard buffer length when deciding
whether to seal a chunk, so a columnar block still respects
ChunkConfig::target_bytes.
Sourcefn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError>
fn finish_chunk(&mut self, buf: &mut BytesMut) -> Result<(), SinkError>
Finalize the pending chunk: flush any internally-buffered rows into
buf as exactly one complete, self-describing wire frame, leaving
the encoder empty and ready for the next chunk. Row formats already
wrote every row in encode, so the default is a
no-op. The terminal stage calls this immediately before it seals each
EncodedChunk (in steady state, on data lulls, and at drain), so a
columnar encoder’s buffered rows are not silently dropped.
An Err is fatal (a broken encoder, not a bad record). The stage
discards whatever the failed call wrote and ships no partial frame.
The stop it triggers is asynchronous, so the chunk stays open and a
later seal may call finish_chunk again for it, by which point the
chunk may hold rows the failed call never saw. Return Ok only from a
call whose frame carries every row the chunk holds. The stage discards
what the call wrote and not the row count, so an encoder that had
already moved its rows into buf when it failed re-encodes them, and
keeps failing until it can. Rows no call finalizes have their acknowledgments fail on
teardown, so the data replays.
Because a Native block concatenates with the blocks around it, each
finish_chunk frame is independently valid, so workers still
accumulate frames without re-encoding.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".