function bfdControlPacket
bfdControlPacket(): Coder<BfdControlPacket>

Creates a coder for the mandatory section of a BFD control packet (RFC 5880 section 4.1).

Nothing is validated or computed on encode — length, discriminators, and every interval are written exactly as given. When flags.authenticationPresent is set, the caller owns everything from byte BFD_CONTROL_SIZE onward; this coder neither reads nor writes an authentication section.

Examples

Decode a known-wire Down packet, then re-encode it

import { assertEquals } from "@std/assert";
import { bfdControlPacket, BFD_CONTROL_SIZE, BFD_STATE } from "@binstruct/bfd";

const coder = bfdControlPacket();
// deno-fmt-ignore
const wire = new Uint8Array([
  0x20, 0x50, 0x03, 0x18,
  0x00, 0x00, 0x00, 0x01,
  0x00, 0x00, 0x00, 0x00,
  0x00, 0x0f, 0x42, 0x40,
  0x00, 0x0f, 0x42, 0x40,
  0x00, 0x00, 0x00, 0x00,
]);

const [decoded, read] = coder.decode(wire);

assertEquals(read, BFD_CONTROL_SIZE);
assertEquals(decoded.versionDiagnostic.version, 1);
assertEquals(decoded.flags.state, BFD_STATE.DOWN);
assertEquals(decoded.flags.final, 1);
assertEquals(decoded.myDiscriminator, 1);
assertEquals(decoded.desiredMinTxInterval, 1_000_000);

const buffer = new Uint8Array(BFD_CONTROL_SIZE);
const written = coder.encode(decoded, buffer);

assertEquals(written, BFD_CONTROL_SIZE);
assertEquals(buffer, wire);

Return Type

A coder for BfdControlPacket values.

Usage

import { bfdControlPacket } from ".";