Skip to main content

ItemEncoder

Trait ItemEncoder 

Source
pub trait ItemEncoder<T> {
    // Required method
    fn encode(
        &mut self,
        item: &T,
        index: u64,
        buf: &mut BytesMut,
    ) -> Result<(), StreamError>;

    // Provided methods
    fn prologue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError> { ... }
    fn epilogue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError> { ... }
}
Expand description

Per-stream encoding state.

index is passed to encode rather than tracked internally because several formats key their framing off it: the JSON array writes a separator before every item but the first, CSV writes its header row only at index 0, and Arrow emits the schema message only at index 0. Implementations that do not care simply ignore it.

Required Methods§

Source

fn encode( &mut self, item: &T, index: u64, buf: &mut BytesMut, ) -> Result<(), StreamError>

Encode one item.

Provided Methods§

Source

fn prologue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>

Bytes emitted before the first item, if any.

Source

fn epilogue(&mut self, buf: &mut BytesMut) -> Result<(), StreamError>

Bytes emitted after the last item, if any.

Called on normal end of stream only, never after an error, and never if the stream is dropped, since in both cases the body is already truncated and a well-formed terminator would misrepresent it as complete.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl ItemEncoder<RecordBatch> for ArrowIpcEncoder

Available on crate feature arrow only.
Source§

impl ItemEncoder<String> for TextEncoder

Available on crate feature text only.
Source§

impl<T> ItemEncoder<T> for CsvEncoder
where T: Serialize,

Available on crate feature csv only.
Source§

impl<T> ItemEncoder<T> for JsonArrayEncoder
where T: Serialize,

Available on crate feature json only.
Source§

impl<T> ItemEncoder<T> for JsonNewLineEncoder
where T: Serialize,

Available on crate feature json only.
Source§

impl<T> ItemEncoder<T> for ProtobufEncoder
where T: Message,

Available on crate feature protobuf only.