function encodeSentence
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.

Examples

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

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);

Encode empty sentence

import { assertEquals } from "@std/assert";
import { encodeSentence } from "@hertzg/routeros-api/encoding/sentence";

const encoded = encodeSentence([]);
// Empty sentence is just the terminator
assertEquals(encoded, new Uint8Array([0x00]));

Parameters

words: string[]

Array of strings to encode as a sentence

Return Type

Encoded sentence with all words and zero terminator

Usage

import { encodeSentence } from "encoding/sentence.ts";