[−][src]Function engine_io_parser::binary::encoder::encode_payload
pub fn encode_payload<'a>(input: &'a [Packet]) -> Vec<u8>
Encode a payload containing multiple packets with either binary or string data to a byte array. In an encoded payload, each packet is denoted with its length and its data type; either binary or string. This function passes binary packet data as is, and encodes string packets to bytes.
Arguments
input
- A list ofPacket
s with either string or binary data each
Example
use engine_io_parser::packet::{Packet, PacketData, PacketType}; use engine_io_parser::binary::encoder::*; assert_eq!( encode_payload(&[ Packet { packet_type: PacketType::Message, data: "€".into(), }, Packet { packet_type: PacketType::Message, data: vec![1u8, 2u8, 3u8, 4u8].into() } ]), b"\x00\x04\xff\x34\xe2\x82\xac\x01\x05\xff\x04\x01\x02\x03\x04" );