pub struct Envelope<T> {
pub v: u32,
pub id: String,
pub device_id: String,
pub sent_at: DateTime<Utc>,
pub reply_to: Option<String>,
pub body: T,
}Expand description
One decoded frame: the invariant header, and the typed body.
Fields§
§v: u32§id: StringThe request id. Doubles as the idempotency key — see
super::idempotency.
device_id: String§sent_at: DateTime<Utc>§reply_to: Option<String>The id of the request this frame answers, or None for an unsolicited
one.
body: TImplementations§
Source§impl<T> Envelope<T>
impl<T> Envelope<T>
Sourcepub fn new(
id: impl Into<String>,
device_id: impl Into<String>,
sent_at: DateTime<Utc>,
body: T,
) -> Self
pub fn new( id: impl Into<String>, device_id: impl Into<String>, sent_at: DateTime<Utc>, body: T, ) -> Self
Build a frame to send. sent_at is taken from the caller rather than
the clock so that tests and the golden fixtures are not time-dependent.
A frame stamped with the newest version this build speaks.
Right for a peer known to be current, and for tests. A connection that
has negotiated down must use Self::at_version instead.
Sourcepub fn at_version(
version: u32,
id: impl Into<String>,
device_id: impl Into<String>,
sent_at: DateTime<Utc>,
body: T,
) -> Self
pub fn at_version( version: u32, id: impl Into<String>, device_id: impl Into<String>, sent_at: DateTime<Utc>, body: T, ) -> Self
A frame stamped with a specific version.
Why this is not just new. Once two versions exist, the version a
session speaks is the one it negotiated, not the one this build
prefers. A v2 daemon that stamped 2 on every frame after agreeing to
speak 1 would have every frame refused by the peer that asked it to
downgrade — which is the entire population of already-deployed peers.