pub struct TradeSerializer;Expand description
Serialization utilities for trade data
Provides methods to serialize and deserialize trade records using FlatBuffers. Optimized for high-frequency trading scenarios with thread-local builders.
Implementations§
Source§impl TradeSerializer
impl TradeSerializer
Sourcepub fn serialize_trade(trade: &TradeRecord) -> Result<Vec<u8>>
pub fn serialize_trade(trade: &TradeRecord) -> Result<Vec<u8>>
Serialize a single trade record to FlatBuffers
Converts a TradeRecord to FlatBuffers binary format for efficient storage.
Returns a vector of bytes containing the serialized trade data.
§Arguments
trade- The trade record to serialize
§Returns
Returns Ok(Vec<u8>) containing the serialized data, or Err(SchemaError) on failure.
Sourcepub fn serialize_batch(batch: &TradesBatchRecord) -> Result<Vec<u8>>
pub fn serialize_batch(batch: &TradesBatchRecord) -> Result<Vec<u8>>
Serialize a batch of trades to FlatBuffers
Converts a TradesBatchRecord containing multiple trades to FlatBuffers binary format.
More efficient than serializing individual trades for bulk operations.
§Arguments
batch- The batch of trades to serialize
§Returns
Returns Ok(Vec<u8>) containing the serialized batch data, or Err(SchemaError) on failure.
Sourcepub fn serialize_trade_into(
trade: &TradeRecord,
buffer: &mut Vec<u8>,
) -> Result<usize>
pub fn serialize_trade_into( trade: &TradeRecord, buffer: &mut Vec<u8>, ) -> Result<usize>
Serialize a trade directly into a provided buffer (zero-copy)
Serializes a trade record directly into a provided buffer, avoiding allocation. Uses thread-local builder for optimal performance in high-frequency scenarios.
§Arguments
trade- The trade record to serializebuffer- Mutable buffer to write serialized data into
§Returns
Returns Ok(usize) with the number of bytes written, or Err(SchemaError) on failure.
Sourcepub fn deserialize_trade(data: &[u8]) -> Result<TradeRecord>
pub fn deserialize_trade(data: &[u8]) -> Result<TradeRecord>
Deserialize trade data from FlatBuffers
Converts FlatBuffers binary data back to a TradeRecord structure.
Uses optimized decimal parsing for better performance.
§Arguments
data- Byte slice containing serialized trade data
§Returns
Returns Ok(TradeRecord) with the deserialized trade, or Err(SchemaError) on failure.