Expand description
§lnmp-envelope
Operational metadata envelope for LNMP records.
This crate provides a way to attach operational context (timestamp, source, trace ID, sequence) to LNMP records without affecting their deterministic properties or semantic checksums.
§Alignment with Industry Standards
LNMP Envelope aligns with:
- CloudEvents: Similar context attributes (time, source, id)
- Kafka Headers: Record-level metadata separate from payload
- W3C Trace Context: Compatible trace ID format for distributed tracing
- OpenTelemetry: Seamless integration with telemetry spans
§Core Principles
- Determinism Preserved: Envelope metadata does NOT affect
SemanticChecksum - Zero Overhead: Unused envelope features have no performance cost
- Transport Agnostic: Defined independently, bindings provided separately
- Future Proof: Extensible via labels, unknown fields skipped gracefully
§Quick Start
use lnmp_core::{LnmpRecord, LnmpField, LnmpValue};
use lnmp_envelope::EnvelopeBuilder;
// Create a record
let mut record = LnmpRecord::new();
record.add_field(LnmpField { fid: 12, value: LnmpValue::Int(14532) });
// Wrap with envelope
let envelope = EnvelopeBuilder::new(record)
.timestamp(1732373147000)
.source("auth-service")
.trace_id("abc-123-xyz")
.sequence(42)
.build();
assert!(envelope.has_metadata());§Encoding Formats
§Binary (TLV)
Envelope metadata is encoded as Type-Length-Value entries in the LNMP container metadata extension block:
Type: 0x10 (Timestamp) | Length: 8 | Value: u64 BE
Type: 0x11 (Source) | Length: N | Value: UTF-8 string
Type: 0x12 (TraceID) | Length: M | Value: UTF-8 string
Type: 0x13 (Sequence) | Length: 8 | Value: u64 BE§Text (Header Comment)
#ENVELOPE timestamp=1732373147000 source=auth-service trace_id="abc-123"
F12=14532
F7=1§Transport Bindings
§HTTP
X-LNMP-Timestamp: 1732373147000
X-LNMP-Source: auth-service
X-LNMP-Trace-ID: abc-123-xyz
X-LNMP-Sequence: 42§Kafka
Record headers:
lnmp.timestamp: "1732373147000"
lnmp.source: "auth-service"
lnmp.trace_id: "abc-123-xyz"
lnmp.sequence: "42"§Features
serde: Enable serde serialization support (optional)
Modules§
- binary_
codec - Binary TLV (Type-Length-Value) codec for envelope metadata
- text_
codec - Text codec for envelope metadata
Structs§
- Envelope
Builder - Fluent builder for constructing envelopes
- Envelope
Metadata - Operational metadata fields for an LNMP envelope
- Lnmp
Envelope - Complete LNMP message with operational context
- Lnmp
Field - A single field assignment (field ID + value pair)
- Lnmp
Record - A complete LNMP record (collection of fields)
Enums§
- Envelope
Error - Errors that can occur when working with envelopes
- Lnmp
Value - LNMP value types supporting all primitives, arrays, and nested structures.
Type Aliases§
- Result
- Result type for envelope operations