[−][src]Function engine_io_parser::binary::decoder::decode_payload
pub fn decode_payload(input: &[u8]) -> Result<Vec<Packet>, ParsePacketError>
Decode a binary-encoded payload containing multiple packets.
Returns a Vec of parsed Packet
s, with the appropriate PacketData
type
for each packet if successful.
In an encoded payload, each packet is denoted with its length and its
data type; either binary or string. This function returns binary packet
data as is, and parses string packets to UTF-8.
Arguments
input
- A slice containing the binary-encoded payload
Example
use engine_io_parser::packet::{Packet, PacketData, PacketType}; use engine_io_parser::binary::decoder::*; assert_eq!( decode_payload(b"\x00\x04\xff\x34\xe2\x82\xac\x01\x05\xff\x04\x01\x02\x03\x04"), Ok(vec![ Packet { packet_type: PacketType::Message, data: "€".into(), }, Packet { packet_type: PacketType::Message, data: vec![1u8, 2u8, 3u8, 4u8].into() } ]) );