Trait spacetimedb_commitlog::payload::Decoder

source ·
pub trait Decoder {
    type Record: Encode;
    type Error: From<DecodeError>;

    // Required methods
    fn decode_record<'a, R: BufReader<'a>>(
        &self,
        version: u8,
        tx_offset: u64,
        reader: &mut R,
    ) -> Result<Self::Record, Self::Error>;
    fn skip_record<'a, R: BufReader<'a>>(
        &self,
        version: u8,
        tx_offset: u64,
        reader: &mut R,
    ) -> Result<(), Self::Error>;

    // Provided method
    fn consume_record<'a, R: BufReader<'a>>(
        &self,
        version: u8,
        tx_offset: u64,
        reader: &mut R,
    ) -> Result<(), Self::Error> { ... }
}
Expand description

A decoder which can decode the transaction (aka record) format of the log.

Unlike Encode, this is not a datatype: the canonical commitlog format requires to look up row types during log traversal in order to be able to decode (see also [RowDecoder]).

Required Associated Types§

source

type Record: Encode

The type of records this decoder can decode. This is also the type which can be appended to a commitlog, and so must satisfy Encode.

source

type Error: From<DecodeError>

The type of decode errors, which must subsume DecodeError.

Required Methods§

source

fn decode_record<'a, R: BufReader<'a>>( &self, version: u8, tx_offset: u64, reader: &mut R, ) -> Result<Self::Record, Self::Error>

Decode one Self::Record from the given buffer.

The version argument corresponds to the log format version of the current segment (see [segment::Header::log_format_version]).

The tx_argument is the transaction offset of the current record relative to the start of the log.

source

fn skip_record<'a, R: BufReader<'a>>( &self, version: u8, tx_offset: u64, reader: &mut R, ) -> Result<(), Self::Error>

Advance reader past the next Self::Record, without returning it or including it in a fold.

Provided Methods§

source

fn consume_record<'a, R: BufReader<'a>>( &self, version: u8, tx_offset: u64, reader: &mut R, ) -> Result<(), Self::Error>

Variant of Self::decode_record which discards the decoded Self::Record.

Useful for folds which don’t need to yield or collect record values.

The default implementation just drops the record returned from Self::decode_record. Implementations may want to override this, such that the record is not allocated in the first place.

Object Safety§

This trait is not object safe.

Implementors§