Skip to main content

SbeDecoder

Trait SbeDecoder 

Source
pub trait SbeDecoder<'a>: Sized {
    const TEMPLATE_ID: u16;
    const SCHEMA_ID: u16;
    const SCHEMA_VERSION: u16;
    const BLOCK_LENGTH: u16;

    // Required methods
    fn wrap(buffer: &'a [u8], offset: usize, acting_version: u16) -> Self;
    fn encoded_length(&self) -> usize;

    // Provided methods
    fn validate_header(header: &MessageHeader) -> Result<(), DecodeError> { ... }
    fn decode(buffer: &'a [u8]) -> Result<Self, DecodeError> { ... }
}
Expand description

Trait for zero-copy SBE message decoders.

Implementations wrap a byte buffer and provide field accessors that read directly from the buffer without copying data.

§Type Parameters

  • 'a - Lifetime of the underlying buffer

§Example

// Generated decoder usage
let decoder = NewOrderSingleDecoder::wrap(&buffer, 0, SCHEMA_VERSION);
let symbol = decoder.symbol();
let quantity = decoder.quantity();

Required Associated Constants§

Source

const TEMPLATE_ID: u16

Schema template ID for this message type.

Source

const SCHEMA_ID: u16

Schema ID.

Source

const SCHEMA_VERSION: u16

Schema version.

Source

const BLOCK_LENGTH: u16

Block length (fixed portion size in bytes).

Required Methods§

Source

fn wrap(buffer: &'a [u8], offset: usize, acting_version: u16) -> Self

Wraps a buffer to decode a message (zero-copy).

§Arguments
  • buffer - Byte buffer containing the message
  • offset - Byte offset where the message starts (after header)
  • acting_version - Version to use for decoding (for compatibility)
§Returns

A decoder instance wrapping the buffer.

Source

fn encoded_length(&self) -> usize

Returns the encoded length of the message in bytes.

This includes the header and all fixed/variable portions.

Provided Methods§

Source

fn validate_header(header: &MessageHeader) -> Result<(), DecodeError>

Validates that the message header matches the expected template.

§Arguments
  • header - Message header to validate
§Errors

Returns an error if the template ID or schema ID doesn’t match.

Source

fn decode(buffer: &'a [u8]) -> Result<Self, DecodeError>

Decodes a message from a buffer, including header validation.

§Arguments
  • buffer - Byte buffer containing the message (starting with header)
§Errors

Returns an error if the header is invalid or buffer is too short.

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.

Implementors§