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

pub fn decode_packet(input: &[u8]) -> Result<Packet, ParsePacketError>

Decode a packet with binary data from a u8 slice. Each packet has a packet type (Open, Close, Message...) and a data section. decode_packet assumes the packet's data is meant to be binary.

Arguments

  • input - A slice containing the binary-encoded packet

Example

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

assert_eq!(decode_packet(&[4u8, 1u8, 2u8, 3u8, 4u8]), Ok(Packet {
    packet_type: PacketType::Message,
    data: vec![1, 2, 3, 4].into(),
}))