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

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

Decode a packet with string data from a UTF-8 string. Each packet has a packet type (Open, Close, Message...) and a data section. decode_packet assumes the packet's data is a string.

Arguments

  • input - A slice containing the string-encoded packet

Example

use engine_io_parser::packet::{Packet, PacketType};
use engine_io_parser::string::decoder::*;

assert_eq!(decode_packet("4Hello world!"), Ok(Packet {
    packet_type: PacketType::Message,
    data: "Hello world!".into(),
}))