Expand description
Flat attribute storage for message headers.
This module provides Flattrs, a type optimized for message passing scenarios
where headers are often forwarded without inspection. It uses a single contiguous
buffer with inline entry lengths for efficient zero-copy passthrough.
§Wire Format
┌─────────────┬──────────────────────────────────────────────────┐
│ num_entries │ entries... │
│ (u16) │ (key_hash: u64, len: u32, value: [u8])... │
└─────────────┴──────────────────────────────────────────────────┘Each entry is self-describing with its length inline, allowing linear scan without a separate index section.
- Key IDs are FNV-1a hashes of key names (stable, computed at compile time)
- Uses linear search (optimal for typical small header counts of 2-5 entries)
§Design Benefits
- Zero-copy passthrough: Forward the entire buffer without parsing
- Zero-copy serialization: Uses
Partfor zero-copy through multipart codec - Simple implementation: No mode switching, just a single buffer
- Compact wire format: u64 key IDs instead of string names
§Example
ⓘ
use hyperactor_config::flattrs::Flattrs;
use hyperactor_config::attrs::declare_attrs;
declare_attrs! {
pub attr TIMESTAMP: u64;
pub attr REQUEST_ID: String;
}
let mut headers = Flattrs::new();
headers.set(TIMESTAMP, 1234567890u64);
headers.set(REQUEST_ID, "req-123".to_string());
// Lazy deserialization on access
let ts: Option<u64> = headers.get(TIMESTAMP);Structs§
- Flattrs
- Flat attribute storage for message headers.