Skip to main content

SbeEncoder

Trait SbeEncoder 

Source
pub trait SbeEncoder: Sized {
    const TEMPLATE_ID: u16;
    const SCHEMA_ID: u16;
    const SCHEMA_VERSION: u16;
    const BLOCK_LENGTH: u16;

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

    // Provided method
    fn create_header() -> MessageHeader { ... }
}
Expand description

Trait for SBE message encoders.

Implementations wrap a mutable byte buffer and provide field setters that write directly to the buffer.

§Example

// Generated encoder usage
let mut buffer = [0u8; 256];
let mut encoder = NewOrderSingleEncoder::wrap(&mut buffer, 0);
encoder
    .set_symbol(b"AAPL    ")
    .set_quantity(100)
    .set_price_mantissa(15050)
    .set_price_exponent(-2);
let len = encoder.encoded_length();

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: &mut [u8], offset: usize) -> Self

Wraps a mutable buffer for encoding.

This automatically writes the message header.

§Arguments
  • buffer - Mutable byte buffer to write to
  • offset - Byte offset where the message starts
§Returns

An encoder instance wrapping the buffer.

Source

fn encoded_length(&self) -> usize

Returns the final encoded length after all writes.

This includes the header and all written portions.

Provided Methods§

Source

fn create_header() -> MessageHeader

Creates the message header for this encoder.

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§