Skip to main content

Module serialization

Module serialization 

Source
Expand description

§Serialization Formats

This module provides abstraction over multiple serialization formats for protocol messages. Supports bincode (default), JSON (debugging/interop), and MessagePack (compact encoding).

§Features

  • Multiple formats: Bincode, JSON, MessagePack with automatic format detection
  • Zero-copy where possible: Direct byte manipulation for performance-critical paths
  • Format metadata: Optional format byte prefix for automatic detection
  • Human-readable options: JSON with pretty-printing for debugging
  • Compact encoding: MessagePack for bandwidth-constrained scenarios

§Performance Characteristics

  • Bincode: ~100-200ns (fastest, binary)
  • MessagePack: ~150-300ns (compact, binary)
  • JSON: ~500-1000ns (human-readable, text)

§Usage

use network_protocol::codec::SerializationFormat;

// Default bincode
let bytes = bincode::serialize(&message)?;

// JSON for debugging
let json_bytes = serde_json::to_vec(&message)?;

// MessagePack for compact encoding
let msgpack_bytes = rmp_serde::to_vec(&message)?;

Enums§

SerializationFormat
Supported serialization formats

Traits§

MultiFormat
Trait for types that support multiple serialization formats