Skip to main content

FromSbeReuse

Trait FromSbeReuse 

Source
pub trait FromSbeReuse: FromSbe {
    type Scratch;

    // Required method
    fn from_sbe_reuse(
        bytes: &[u8],
        scratch: &mut Self::Scratch,
    ) -> Result<Self, SbeDecodeError>;
}
Expand description

Extension of FromSbe that reuses allocations between decodes.

Scalar messages decode without heap allocation, so they do not need this trait. Types with growable internal buffers (for example [OrderBookDeltas] with its Vec<OrderBookDelta>) implement it to let callers supply a pre-allocated scratch buffer and avoid per-message allocation in hot paths.

Required Associated Types§

Source

type Scratch

Scratch buffer whose allocation is reused across decodes.

Required Methods§

Source

fn from_sbe_reuse( bytes: &[u8], scratch: &mut Self::Scratch, ) -> Result<Self, SbeDecodeError>

Decodes a value from an SBE message buffer, reusing scratch’s allocation.

On success, ownership of the allocation moves from scratch into the returned value and scratch is left in its empty state. To continue reusing the allocation, move the buffer back from the returned value (for example scratch = std::mem::take(&mut result.deltas)).

§Errors

Returns an error if the header is invalid or the payload is malformed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FromSbeReuse for OrderBookDeltas

Source§

type Scratch = Vec<OrderBookDelta>

Source§

fn from_sbe_reuse( bytes: &[u8], scratch: &mut Vec<OrderBookDelta>, ) -> Result<Self, SbeDecodeError>

Implementors§