encodeWord(content: string | Uint8Array): EncodedWord
Encodes a word (string or bytes) into MikroTik API format
Converts the input to UTF-8 bytes, prepends a variable-length size prefix, and returns the complete encoded word ready for transmission.
Encode a simple string
Encode a simple string
import { assertEquals } from "@std/assert"; import { encodeWord } from "@hertzg/routeros-api/encoding/word"; const encoded = encodeWord("hello"); // First byte is length (5), followed by "hello" in UTF-8 assertEquals(encoded, new Uint8Array([0x05, 0x68, 0x65, 0x6C, 0x6C, 0x6F]));
content: string | Uint8Array
The string or byte array to encode
Encoded word with length prefix and content bytes