pub struct EventEnvelope { /* private fields */ }Expand description
The immutable message container between functions. Build with the fluent
setters (EventEnvelope::new().set_to("v1.echo").set_body(...)).
Wire format (increment 59): the standard event envelope wire format —
one MsgPack map with these descriptive string keys, shared verbatim with
the Java engine for Event over HTTP (normative spec:
docs/guides/event-envelope-wire-format.md in the Java repo; golden
vectors under tests/resources/envelope-vectors/). Encoders emit id and
headers always and other fields only when set; decoders treat absent and
nil identically and ignore unknown keys (Java may add tags, stack,
obj_type, exception).
Implementations§
Source§impl EventEnvelope
impl EventEnvelope
pub fn new() -> Self
pub fn set_to(self, route: &str) -> Self
pub fn set_from(self, route: &str) -> Self
pub fn set_reply_to(self, route: &str) -> Self
Sourcepub fn clear_reply_to(self) -> Self
pub fn clear_reply_to(self) -> Self
Remove the reply-to address (Java setReplyTo(null)) — used when an
event is re-targeted, e.g. the declarative Event-over-HTTP forward
nulls the local callback route before the envelope crosses the wire.
Sourcepub fn clear_to(self) -> Self
pub fn clear_to(self) -> Self
Remove the routing address (Java setTo(null)) — used when an envelope
is serialized for a wire that rewrites addressing on the consuming side,
e.g. the envelope-mode streaming frames, so a server-internal route name
never leaks.
pub fn set_correlation_id(self, cid: &str) -> Self
pub fn set_trace(self, trace_id: &str, trace_path: &str) -> Self
Sourcepub fn set_span_id(self, span_id: &str) -> Self
pub fn set_span_id(self, span_id: &str) -> Self
Carry a span id on the envelope — the sender’s span, which the receiver
adopts as its parent_span_id (OTel lineage).
pub fn set_status(self, status: i32) -> Self
pub fn set_header(self, key: &str, value: &str) -> Self
Sourcepub fn set_body<T: Serialize>(self, value: T) -> Result<Self, AppError>
pub fn set_body<T: Serialize>(self, value: T) -> Result<Self, AppError>
Serialize any Serialize value into the dynamic body
(the analog of Java’s setBody(Object)).
Sourcepub fn set_raw_body(self, value: Value) -> Self
pub fn set_raw_body(self, value: Value) -> Self
Set the body from an already-dynamic value.
pub fn id(&self) -> &str
pub fn to(&self) -> Option<&str>
pub fn from(&self) -> Option<&str>
pub fn reply_to(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
pub fn trace_id(&self) -> Option<&str>
pub fn trace_path(&self) -> Option<&str>
pub fn headers(&self) -> &HashMap<String, String>
pub fn header(&self, key: &str) -> Option<&str>
pub fn body(&self) -> &Value
Sourcepub fn body_as<T: DeserializeOwned>(&self) -> Result<T, AppError>
pub fn body_as<T: DeserializeOwned>(&self) -> Result<T, AppError>
Deserialize the dynamic body into a concrete type
(the analog of Java’s getBody(Class)).
Sourcepub fn exec_time(&self) -> Option<f32>
pub fn exec_time(&self) -> Option<f32>
Function execution time in milliseconds, when stamped by a worker.
Sourcepub fn round_trip(&self) -> Option<f32>
pub fn round_trip(&self) -> Option<f32>
RPC round-trip milliseconds (Java getRoundTrip), when measured.
Sourcepub fn set_round_trip(self, ms: f32) -> Self
pub fn set_round_trip(self, ms: f32) -> Self
Stamp the RPC round-trip time (Java parity: the requester measures the full request/response cycle).
Sourcepub fn annotations(&self) -> &HashMap<String, Value>
pub fn annotations(&self) -> &HashMap<String, Value>
Trace annotations riding this (reply) envelope (Java getAnnotations).
Sourcepub fn clear_annotations(self) -> Self
pub fn clear_annotations(self) -> Self
Remove all annotations (Java clearAnnotations) — the RPC caller
strips them after folding them into the trace record.
Sourcepub fn add_tag(self, key: &str, value: &str) -> Self
pub fn add_tag(self, key: &str, value: &str) -> Self
Attach an engine-managed tag (Java addTag). Reserved for the engine:
tags never reach a user function’s view — the worker scrubs them at
delivery after extracting what it injects into the header copy.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, AppError>
pub fn to_bytes(&self) -> Result<Vec<u8>, AppError>
Encode the envelope as MsgPack bytes (idiomatic serde — design D4).
The body’s Nil map entries are omitted unless serializer.null.transport
is true — the Rust mirror of Java MsgPack.packMap’s null-skip. Since
increment 58 (the F2 decision) the same strip also runs explicitly on the
in-memory fast path (platform::normalize_null_transport), so delivery
semantics are deterministic on every hop — here it is normally a no-op.
The clone + strip runs only when the body actually carries a
strippable Nil (has_nil_map_entry); otherwise — a scalar body, a
structured body with no nulls, or transport on — self encodes directly
with no extra allocation, so the common case pays only a read-only scan.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, AppError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, AppError>
Decode an envelope from MsgPack bytes.
Trait Implementations§
Source§impl Clone for EventEnvelope
impl Clone for EventEnvelope
Source§fn clone(&self) -> EventEnvelope
fn clone(&self) -> EventEnvelope
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more