encodeLength(length: number): EncodedLength
Encodes a length value into MikroTik API format
Uses variable-length encoding where the first byte(s) indicate the size:
- 1 byte for 0-127
- 2 bytes for 128-16,383
- 3 bytes for 16,384-2,097,151
- 4 bytes for 2,097,152-268,435,455
- 5 bytes for 268,435,456-34,359,738,367
Encode small lengths (1 byte)
Encode small lengths (1 byte)
import { assertEquals } from "@std/assert"; import { encodeLength } from "@hertzg/routeros-api/encoding/length"; const encoded = encodeLength(42); assertEquals(encoded, new Uint8Array([0x2A])); assertEquals(encoded.length, 1);
Encoded length as a Uint8Array (1-5 bytes)