Skip to main content

parse_batch

Function parse_batch 

Source
pub fn parse_batch(raw_packets: &[Vec<u8>]) -> Vec<Packet>
Expand description

Parse a batch of raw byte buffers into packets in parallel.

Each buffer is wrapped in a Packet, parsed, and returned. Parse errors are collected; packets that fail to parse are returned unparsed.

ยงExample

use stackforge_core::parallel::parse_batch;

let raw_packets: Vec<Vec<u8>> = vec![
    // Ethernet + ARP
    vec![
        0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
        0x08, 0x06,
        0x00, 0x01, 0x08, 0x00, 0x06, 0x04,
        0x00, 0x01,
        0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
        0xc0, 0xa8, 0x01, 0x01,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0xc0, 0xa8, 0x01, 0x02,
    ],
];

let parsed = parse_batch(&raw_packets);
assert_eq!(parsed.len(), 1);
assert!(parsed[0].is_parsed());