vlanTag(): Coder<VlanTag>
Creates a coder for an IEEE 802.1Q VLAN tag.
Layout: 2-byte bit-packed TCI (pcp: 3 bits, dei: 1 bit, vlanId: 12
bits), 2-byte big-endian EtherType, then variable-length payload (default:
"rest of buffer").
This coder does not consume or produce the 0x8100 TPID itself — only the
4 bytes that follow it plus the payload. Compose it with
@binstruct/ethernet's ethernet2Frame to parse a full tagged frame.
Decode known wire bytes for VID 100, priority 5
Decode known wire bytes for VID 100, priority 5
import { assertEquals } from "@std/assert"; import { vlanTag } from "@binstruct/vlan"; // deno-fmt-ignore const wire = new Uint8Array([ 0xa0, 0x64, 0x08, 0x00, 0x45, 0x00, 0x00, 0x14, ]); const [decoded, read] = vlanTag().decode(wire); assertEquals(read, wire.length); assertEquals(decoded.tci, { pcp: 5, dei: 0, vlanId: 100 }); assertEquals(decoded.etherType, 0x0800); assertEquals(decoded.payload, new Uint8Array([0x45, 0x00, 0x00, 0x14]));
Coder<VlanTag>
A Coder<VlanTag>.