dbus-sdk
Version:
A Node.js SDK for interacting with DBus, enabling seamless service calling and exposure with TypeScript support
97 lines • 5.38 kB
TypeScript
import { DBusMessageHeader } from '../types/DBusMessageHeader';
import { DBusMessageEndianness } from './enums/DBusMessageEndianness';
/**
* A class representing a DBus message.
* Handles the creation, encoding, and decoding of DBus messages, including headers and bodies.
* Supports various message types such as method calls, replies, signals, and errors.
* This class is central to DBus communication, providing the means to construct and parse messages
* according to the DBus wire protocol.
*/
export declare class DBusMessage {
/**
* The endianness used for encoding and decoding DBus messages.
* Defaults to little-endian (LE) as it is the most common in DBus implementations.
* Determines the byte order for multi-byte values in the message.
*/
readonly endianness: DBusMessageEndianness;
/**
* The header of the DBus message.
* Contains metadata such as message type, flags, serial number, and other fields like path and interface.
* This is essential for routing and processing the message on the DBus.
*/
readonly header: DBusMessageHeader;
/**
* The body of the DBus message.
* Contains the payload or arguments of the message, such as method parameters or signal data.
* This is an array that can hold various data types as per the DBus specification.
*/
readonly body: any[];
/**
* Constructor for creating a DBusMessage instance.
* Initializes the message with a header and optional body content, applying default values for required fields.
* Defaults ensure that a message is always in a valid initial state for encoding or transmission.
*
* @param header - The message header or partial header object, with fields like type, flags, and serial.
* @param body - Variable number of arguments representing the message body (payload data).
*/
constructor(header: DBusMessageHeader | Partial<DBusMessageHeader>, ...body: any[]);
/**
* Converts the DBus message instance to a Buffer for transmission.
* Encodes the header and body into a binary format following the DBus wire protocol.
* Ensures proper alignment and padding as required by the specification, including
* an 8-byte boundary for the total header length.
*
* @returns A Buffer containing the encoded DBus message ready to be sent over the wire.
* @throws {SerialError} If the message serial number is missing or invalid.
*/
toBuffer(): Buffer;
/**
* Retrieves the data (body) of the DBus message.
* Returns the payload or arguments contained in the message as an array.
*
* @returns An array of data elements from the message body.
*/
data(): any[];
/**
* A static array mapping header field type IDs to their corresponding names.
* Used for encoding and decoding header fields in DBus messages.
* Null at index 0 as type IDs start from 1 in the DBus protocol.
*/
protected static readonly headerTypeName: (string | null)[];
/**
* A static record mapping header field names to their type IDs.
* Used during encoding to assign the correct type ID to each header field
* as defined by the DBus specification.
*/
protected static readonly headerTypeId: Record<string, number>;
/**
* A static record mapping header field names to their DBus type signatures.
* Used to encode header field values with the correct DBus type during message creation.
*/
protected static readonly fieldSignature: Record<string, string>;
/**
* Encodes a DBus message from a partial header and body data into a Buffer.
* Static utility method to create and encode a message without instantiating it permanently.
* Provides a convenient way to build a message with defaults and serialize it directly.
*
* @param header - A partial DBus message header with fields like type, flags, and serial.
* @param body - Variable number of arguments representing the message body (payload data).
* @returns A Buffer containing the encoded DBus message ready for transmission.
*/
static encode(header: Partial<DBusMessageHeader>, ...body: any[]): Buffer;
/**
* Decodes a DBus message from raw buffers into a DBusMessage instance.
* Parses the header and body from binary data following the DBus wire protocol.
* Handles endianness, header fields, padding, and body decoding based on the signature.
*
* @param header - A Buffer containing the initial 16 bytes of the DBus message header.
* @param fieldsAndBody - A Buffer containing the header fields and body data.
* @param fieldsLength - The length of the header fields section in bytes.
* @param bodyLength - The length of the body section in bytes.
* @param advancedResponse - Boolean flag to enable advanced response handling, where DBus return messages are organized using DBusTypeClass instances.
* @param convertBigIntToNumber - Boolean flag to enable auto convert bigint to javascript number.
* @returns A DBusMessage instance with parsed header and body content.
*/
static decode(header: Buffer, fieldsAndBody: Buffer, fieldsLength: number, bodyLength: number, advancedResponse?: boolean, convertBigIntToNumber?: boolean): DBusMessage;
}
//# sourceMappingURL=DBusMessage.d.ts.map