encodeSentence(words: string[]): EncodedSentence
Encodes a sentence (array of strings) into MikroTik API format
Each word is encoded with its length prefix, and a zero byte (0x00) is appended to mark the end of the sentence.
Encode a simple command sentence
Encode a simple command sentence
import { assertEquals } from "@std/assert"; import { encodeSentence } from "@hertzg/routeros-api/encoding/sentence"; const encoded = encodeSentence(["/interface/print"]); // Should end with zero terminator assertEquals(encoded[encoded.length - 1], 0x00);
Encode a command with attributes
Encode a command with attributes
import { assertEquals } from "@std/assert"; import { encodeSentence } from "@hertzg/routeros-api/encoding/sentence"; const words = ["/interface/set", "=.id=ether1", "=disabled=yes"]; const encoded = encodeSentence(words); assertEquals(encoded[encoded.length - 1], 0x00);
Encoded sentence with all words and zero terminator