icmpv6Message(): Coder<Icmpv6Message>
Creates a coder for a generic ICMPv6 message — 4-byte fixed header
(type, code, checksum) and a body that absorbs the rest of the
buffer on decode.
Round-trip a Destination Unreachable message
Round-trip a Destination Unreachable message
import { assertEquals } from "@std/assert"; import { ICMPV6_TYPE, icmpv6Message } from "@binstruct/icmpv6"; const coder = icmpv6Message(); // First 4 body bytes are the unused field, followed by as much of the // invoking packet as fits. const body = new Uint8Array([0x00, 0x00, 0x00, 0x00]); const message = { type: ICMPV6_TYPE.DEST_UNREACHABLE, code: 4, checksum: 0x1234, body, }; const buffer = new Uint8Array(4 + body.length); const bytesWritten = coder.encode(message, buffer); const [decoded, bytesRead] = coder.decode(buffer); assertEquals(bytesWritten, buffer.length); assertEquals(bytesRead, buffer.length); assertEquals(decoded.type, ICMPV6_TYPE.DEST_UNREACHABLE); assertEquals(decoded.code, 4); assertEquals(decoded.checksum, 0x1234); assertEquals(decoded.body, body);
Coder<Icmpv6Message>
A coder for Icmpv6Message.