Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Send + Sync {
    // Required methods
    fn mime_type(&self) -> &str;
    fn encode_grid(&self, grid: &HGrid) -> Result<String, CodecError>;
    fn decode_grid(&self, input: &str) -> Result<HGrid, CodecError>;
    fn encode_scalar(&self, val: &Kind) -> Result<String, CodecError>;
    fn decode_scalar(&self, input: &str) -> Result<Kind, CodecError>;

    // Provided methods
    fn encode_grid_header(&self, grid: &HGrid) -> Result<Vec<u8>, CodecError> { ... }
    fn encode_grid_row(
        &self,
        _cols: &[HCol],
        _row: &HDict,
    ) -> Result<Vec<u8>, CodecError> { ... }
}
Expand description

Trait for Haystack wire format codecs.

Required Methods§

Source

fn mime_type(&self) -> &str

The MIME type for this codec (e.g. "text/zinc").

Source

fn encode_grid(&self, grid: &HGrid) -> Result<String, CodecError>

Encode an HGrid to a string.

Source

fn decode_grid(&self, input: &str) -> Result<HGrid, CodecError>

Decode a string to an HGrid.

Source

fn encode_scalar(&self, val: &Kind) -> Result<String, CodecError>

Encode a single scalar Kind value to a string.

Source

fn decode_scalar(&self, input: &str) -> Result<Kind, CodecError>

Decode a string to a single scalar Kind value.

Provided Methods§

Source

fn encode_grid_header(&self, grid: &HGrid) -> Result<Vec<u8>, CodecError>

Encode the grid header (version line + meta + column definitions).

For Zinc: ver:"3.0" meta\ncol1,col2,col3\n Default implementation returns the full encoded grid (no streaming benefit).

Source

fn encode_grid_row( &self, _cols: &[HCol], _row: &HDict, ) -> Result<Vec<u8>, CodecError>

Encode a single grid row given the column definitions.

For Zinc: val1,val2,val3\n Default implementation returns an empty vec (header contained everything).

Implementors§