@fibercom/routeros-api
Version:
Robust MikroTik RouterOS API client for Node.js and TypeScript
50 lines (49 loc) • 1.46 kB
TypeScript
import { Socket } from "net";
export interface ISentence {
sentence: string;
hadMore: boolean;
}
/**
* Represents a callback associated with a tag, invoked when data for the tag is received.
*/
export interface IReadCallback {
name: string;
callback: (data: string[]) => void;
}
/**
* Responsible for decoding and routing raw RouterOS API socket data
* to the appropriate tagged command listeners.
*/
export declare class Receiver {
private socket;
private tags;
private pendingData;
private currentSentence;
constructor(socket: Socket);
/**
* Register a callback for a given tag. Each command gets its own tag.
*/
read(tag: string, callback: (packet: string[]) => void): void;
/**
* Unregister the callback for a tag once command completes (!done).
*/
stop(tag: string): void;
/**
* Handle incoming socket data, decode lines based on RouterOS framing protocol.
* Convert win1252-encoded text to UTF-8.
*/
processRawData(data: Buffer): void;
/**
* Dispatch a complete RouterOS sentence to its tagged channel.
*/
private dispatchSentence;
/**
* Decode RouterOS variable-length prefix for sentence lengths.
*
* Supports multi-byte formats depending on the highest bit set.
*
* @param {Buffer} data
* @returns {[number, number]} - [lengthDescriptorSize, sentenceLength]
*/
private decodeLength;
}