pub struct MessageEnvelope {
pub header: MessageHeader,
pub payload: Vec<u8>,
pub provenance: Option<ProvenanceHeader>,
pub tenant_id: TenantId,
pub audit_tag: AuditTag,
}Expand description
Envelope containing header and serialized payload.
The optional provenance slot carries PROV-O attribution metadata for
NSAI reasoning chains (see crate::provenance). When None, the field
is a single discriminant byte - zero cost for the common case. When
populated, it adds a fixed-size ProvenanceHeader (see that type for
size details).
The tenant_id field is the primary multi-tenant isolation key — it
defaults to 0 (the unspecified tenant) which preserves single-tenant
fast-path behavior and is free of HashMap lookups in the K2K broker.
The audit_tag field carries billable-unit attribution (org_id +
engagement_id) and defaults to AuditTag::default (both fields zero).
The K2K broker stamps the sender’s tag into outgoing envelopes when the
caller leaves this as the default.
Neither the provenance, tenant_id, nor audit_tag fields are included
in the legacy MessageEnvelope::to_bytes / MessageEnvelope::from_bytes
wire format, which is defined by MessageHeader + raw payload for
backwards compatibility. These travel separately (e.g. as part of
rkyv-encoded envelope transfer on GPU) or are reattached by the router.
Fields§
§header: MessageHeaderMessage header.
payload: Vec<u8>Serialized payload.
provenance: Option<ProvenanceHeader>Optional PROV-O attribution metadata. Defaults to None; only
populated when the message participates in an audited reasoning
chain (e.g. VynGraph NSAI pipelines).
tenant_id: TenantIdMulti-tenant isolation key. Defaults to 0 (unspecified tenant),
matching single-tenant deployments that never opt in to isolation.
audit_tag: AuditTagBillable-unit attribution: {org_id, engagement_id}. Defaults to
AuditTag::default() (both fields zero). The K2K broker stamps the
sending kernel’s tag into envelopes whose tag is still the default.
Implementations§
Source§impl MessageEnvelope
impl MessageEnvelope
Sourcepub fn new<M: RingMessage>(
message: &M,
source_kernel: u64,
dest_kernel: u64,
timestamp: HlcTimestamp,
) -> Self
pub fn new<M: RingMessage>( message: &M, source_kernel: u64, dest_kernel: u64, timestamp: HlcTimestamp, ) -> Self
Create a new envelope from a message.
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Get total size (header + payload).
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to contiguous bytes.
NOTE: the provenance metadata is intentionally not serialised here. This method keeps the historical wire format unchanged; provenance is transported out-of-band or via rkyv-encoded transfer.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize from bytes.
Reconstructs an envelope with provenance: None and default
tenant/audit fields. Callers that need provenance must reattach it via
MessageEnvelope::with_provenance; callers that need tenant
attribution must stamp it via MessageEnvelope::with_tenant_id /
MessageEnvelope::with_audit_tag.
Sourcepub fn empty(
source_kernel: u64,
dest_kernel: u64,
timestamp: HlcTimestamp,
) -> Self
pub fn empty( source_kernel: u64, dest_kernel: u64, timestamp: HlcTimestamp, ) -> Self
Create an empty envelope (for testing).
Sourcepub fn with_provenance(self, provenance: ProvenanceHeader) -> Self
pub fn with_provenance(self, provenance: ProvenanceHeader) -> Self
Attach a PROV-O provenance header (builder-style).
Sourcepub fn without_provenance(self) -> Self
pub fn without_provenance(self) -> Self
Strip provenance (builder-style). Useful when routing a message into an untrusted tenant boundary where attribution must not leak.
Sourcepub fn with_tenant_id(self, tenant_id: TenantId) -> Self
pub fn with_tenant_id(self, tenant_id: TenantId) -> Self
Stamp the envelope with a tenant ID (builder-style).
In the two-tier tenancy model the tenant ID is the primary isolation
key; the K2K broker uses it to route the message into the correct
per-tenant sub-broker. Defaults to 0 (unspecified tenant).
Sourcepub fn with_audit_tag(self, audit_tag: AuditTag) -> Self
pub fn with_audit_tag(self, audit_tag: AuditTag) -> Self
Attach an audit tag (builder-style).
The audit tag carries billable-unit attribution (org_id + engagement_id). The K2K broker preserves this tag across delivery
so downstream cost accounting can attribute GPU-seconds back to the
specific engagement.
Trait Implementations§
Source§impl Clone for MessageEnvelope
impl Clone for MessageEnvelope
Source§fn clone(&self) -> MessageEnvelope
fn clone(&self) -> MessageEnvelope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more