pub struct WireEnvelope<T> {
pub wire_version: u32,
pub payload: T,
}Expand description
Versioned wrapper around a hybrid-flow payload.
JSON shape:
{"wire_version":1,"payload":"Ping"}Transport ownership is unchanged: backends still send and receive bytes.
Call WireEnvelope::decode_json or decode_ipc_message_json at the
decode entry point so too-old / too-new envelopes fail before the payload
is used.
Fields§
§wire_version: u32Schema version of payload.
payload: TTyped hybrid-flow message (typically IpcMessage).
Implementations§
Source§impl<T> WireEnvelope<T>
impl<T> WireEnvelope<T>
Sourcepub fn new(payload: T) -> Self
pub fn new(payload: T) -> Self
Wrap payload at WireCompatibility::CURRENT.
Sourcepub fn into_payload(self) -> T
pub fn into_payload(self) -> T
Unwrap the payload after a successful decode.
Source§impl<T: DeserializeOwned> WireEnvelope<T>
impl<T: DeserializeOwned> WireEnvelope<T>
Sourcepub fn decode_json(bytes: &[u8]) -> Result<Self, EnvelopeError>
pub fn decode_json(bytes: &[u8]) -> Result<Self, EnvelopeError>
Decode JSON bytes, checking wire_version before converting payload.
The payload is kept as raw JSON until the version is accepted, so a
too-new/too-old envelope is rejected without building T.
Sourcepub fn from_json_value(value: Value) -> Result<Self, EnvelopeError>
pub fn from_json_value(value: Value) -> Result<Self, EnvelopeError>
Decode an already-parsed JSON value, checking version before T.
Prefer Self::decode_json for byte input so the payload is not first
materialized as a Value tree. This entry point exists for callers
that already hold a Value.
Source§impl<T: Serialize> WireEnvelope<T>
impl<T: Serialize> WireEnvelope<T>
Sourcepub fn encode_json(&self) -> Result<Vec<u8>, EnvelopeError>
pub fn encode_json(&self) -> Result<Vec<u8>, EnvelopeError>
Encode this envelope as compact JSON bytes.