Module zero_copy

Source
Expand description

The zero_copy module contains all the zero-copy-related data structures used in the system. Zero-copy market data structures for ultra-fast binary parsing

This module provides zerocopy-enabled structures for direct memory mapping of binary market data from exchanges, eliminating parsing overhead.

§Bytemuck Usage Strategy

We use a hybrid approach with bytemuck for maximum safety:

  1. Non-generic structs (ZeroCopyPriceLevel, ZeroCopyTrade, MessageHeader):

    • Use bytemuck’s Pod and Zeroable derives for safe zero-copy operations
    • All methods use bytemuck’s safe APIs (bytes_of, try_from_bytes)
  2. Generic structs (ZeroCopyOrderBookUpdate):

    • Cannot derive Pod/Zeroable due to const generic limitations
    • Bytemuck doesn’t support arrays [T; N] with generic N
    • Maintain minimal unsafe code with comprehensive safety documentation
    • Use parse_message_generic() instead of parse_message()

This approach maximizes safety while maintaining the flexibility of const generics for compile-time configurable buffer sizes.

Re-exports§

pub use ZeroCopyOrderBookUpdate10 as DefaultZeroCopyOrderBookUpdate;

Structs§

MessageHeader
Zero-copy message header for length-prefixed protocols
ZeroCopyOrderBookUpdate
Zero-copy order book update with const generic array sizing
ZeroCopyPriceLevel
Zero-copy price level structure
ZeroCopyTrade
Zero-copy trade message

Functions§

parse_message
Parse a message from a buffer with proper alignment checks
parse_message_generic
Parse a message from a buffer for types that can’t implement Pod
parse_message_mut
Parse a mutable message from a buffer with proper alignment checks

Type Aliases§

ZeroCopyOrderBookUpdate5
Type alias for a zero-copy order book update with 5 levels per side.
ZeroCopyOrderBookUpdate10
Type alias for a zero-copy order book update with 10 levels per side.
ZeroCopyOrderBookUpdate20
Type alias for a zero-copy order book update with 20 levels per side.