[][src]Function engine_io_parser::string::decoder::decode_payload

pub fn decode_payload(input: &str) -> Result<Vec<Packet>, ParsePacketError>

Decode a string-encoded payload containing multiple packets. Returns a Vec of parsed Packets, 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 string packet data as is, and parses binary packets from base64 to a byte array.

Arguments

  • input - a string containing an encoded payload.
use engine_io_parser::packet::{Packet, PacketData, PacketType};
use engine_io_parser::string::decoder::*;

assert_eq!(
    decode_payload("6:4hello2:4€"),
    Ok(vec![
        Packet {
            packet_type: PacketType::Message,
            data: "hello".into(),
        },
        Packet {
            packet_type: PacketType::Message,
            data: "€".into()
        }
    ]),
);