UNPKG

dbus-sdk

Version:

A Node.js SDK for interacting with DBus, enabling seamless service calling and exposure with TypeScript support

75 lines 4.53 kB
import { DataType } from '../types/DataType'; /** * A class representing a DBus signed value with a specific signature and associated data. * This class wraps a value with its corresponding DBus type signature, enabling proper * encoding and decoding of DBus messages. It supports both basic types (e.g., integers, strings) * and container types (e.g., arrays, structs, dictionaries) as defined by the DBus specification. */ export declare class DBusSignedValue { /** * The signature of the DBus value (e.g., 's' for string, 'i' for integer, 'a' for array). * This identifies the type of data stored in the value according to the DBus type system. */ readonly $signature: string; /** * The signature of the array item (for 'a' type), if applicable. * This is used to specify the type of elements within an array, particularly useful * for distinguishing different array contents (e.g., 'ay' for byte array). */ readonly $arrayItemSignature?: string; /** * The value associated with the signature. * Can be a primitive (e.g., number, string), a single DBusSignedValue (for nested types like variants), * or an array of DBusSignedValue instances (for containers like arrays or structs). */ readonly $value: any | DBusSignedValue | DBusSignedValue[]; /** * Static method to parse a DBus signature and value into an array of DBusSignedValue objects. * Distinguishes between independent parameter sequences (e.g., 'si' for string and integer) * and structs (e.g., '(si)' for a struct containing string and integer). * This method is useful for creating properly typed DBus values from raw data. * * @param signature - The DBus signature string (e.g., 's', 'si', '(si)', 'as') defining the type structure. * @param value - The value or values corresponding to the signature, can be raw data or already DBusSignedValue. * @returns An array of DBusSignedValue objects representing the parsed signature and value. * @throws {SignatureError} If the value structure does not match the signature or is invalid. */ static parse(signature: string, value: any | DBusSignedValue | DBusSignedValue[]): DBusSignedValue[]; /** * Static method to convert an array of DBusSignedValue objects back to plain JavaScript objects. * Recursively processes nested structures (arrays, structs, dictionaries) and removes DBus * signature metadata to return raw values suitable for general use. * * @param values - An array of DBusSignedValue objects to convert. * @returns An array of plain JavaScript values representing the data without DBus signatures. */ static toJSON(values: DBusSignedValue[]): any[]; /** * Private static method to recursively convert a single DBusSignedValue object to a plain JavaScript value. * Handles different DBus types (basic, array, dictionary, struct, variant) and unwraps nested structures. * * @param value - The DBusSignedValue object to convert. * @returns The plain JavaScript value extracted from the DBusSignedValue. */ private static convertToPlain; /** * Constructor for creating a DBusSignedValue object from a signature and value. * Processes the signature (string, DataType, or array of DataType) and associates it with the provided value, * handling basic types, structs, arrays, dictionaries, and variants appropriately. * * @param signature - The DBus signature, as a string (e.g., 's'), a single DataType, or an array of DataType for structs. * @param value - The value associated with the signature, can be raw data, DBusSignedValue, or array of values. * @throws {SignatureError} If the value structure does not match the signature or if the type is unsupported. */ constructor(signature: string | DataType | DataType[], value: any | DBusSignedValue | DBusSignedValue[]); /** * Private method to infer the DBus signature type from a value for variant type 'v'. * Analyzes the type and structure of the value to determine an appropriate DBus signature. * Handles basic types (strings, numbers), arrays, buffers, and objects for dictionary inference. * * @param value - The value to infer the type from, can be any JavaScript value. * @returns The inferred DBus signature string (e.g., 's' for string, 'ai' for integer array). */ private inferType; } //# sourceMappingURL=DBusSignedValue.d.ts.map