#[non_exhaustive]pub enum Payload {
Binary(Bytes),
Text(Vec<Value>),
Mixed {
args: Vec<Value>,
attachments: Vec<Bytes>,
},
}Expand description
The arguments of an event or an ack.
socket.io sends a list of arguments; each is JSON or binary. Received arguments arrive as:
Payload::Text: JSON only (the common case),Payload::Binary: exactly one binary argument,Payload::Mixed: binary data anywhere else (several buffers, a buffer next to JSON arguments, a buffer inside an object).
Build one with From (a Value, a Vec<Value>, a string, bytes) or with
Payload::serialize for any Serialize type; read one with Payload::arg /
Payload::deserialize.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Binary(Bytes)
One binary argument.
Text(Vec<Value>)
JSON arguments.
Mixed
Arguments with binary data anywhere in them: each {"_placeholder":true,"num":n} in
args stands for attachments[n] (socket.io-parser binary encoding). Build placeholders
with Payload::placeholder.
Implementations§
Source§impl Payload
impl Payload
Sourcepub fn placeholder(num: usize) -> Value
pub fn placeholder(num: usize) -> Value
The placeholder for attachments[num] in Payload::Mixed.
Sourcepub fn serialize<T: Serialize + ?Sized>(value: &T) -> Result<Self>
pub fn serialize<T: Serialize + ?Sized>(value: &T) -> Result<Self>
One argument from any Serialize value.
Sourcepub fn args(&self) -> &[Value]
pub fn args(&self) -> &[Value]
The JSON arguments (placeholders included for Payload::Mixed; empty for
Payload::Binary).
Sourcepub fn binary(&self) -> &[Bytes]
pub fn binary(&self) -> &[Bytes]
The binary data: the one buffer of Payload::Binary, the attachments of
Payload::Mixed.
Sourcepub fn arg<T: DeserializeOwned>(&self, index: usize) -> Result<T>
pub fn arg<T: DeserializeOwned>(&self, index: usize) -> Result<T>
Argument index as T (null when it is missing, so Option<T> reads optional ones).
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T>
All arguments as T: a tuple (A, B), a Vec<_>, or a struct with one field per
argument position.