declare module "@athombv/data-types" { class DataType { constructor( id: number, shortName: string, length: number, toBuffer: (buffer: Buffer, value: ToBuffer, index?: number) => ToBufferReturn, fromBuffer: (buffer: Buffer, index?: number) => FromBuffer, ...args: Array ); id: number; shortName: string; length: number; toBuffer: (buffer: Buffer, value: ToBuffer, index?: number) => ToBufferReturn; fromBuffer: (buffer: Buffer, index?: number) => FromBuffer; args: Array; defaultValue: FromBuffer; get isAnalog(): boolean; inspect(): string; } const DataTypes: { noData: DataType data8: DataType; data16: DataType; data24: DataType; data32: DataType; data40: DataType; data48: DataType; data56: DataType; data64: DataType; bool: DataType; map8: (...flags: Array) => DataType>; map16: (...flags: Array) => DataType>; map24: (...flags: Array) => DataType>; map32: (...flags: Array) => DataType>; map40: (...flags: Array) => DataType>; map48: (...flags: Array) => DataType>; map56: (...flags: Array) => DataType>; map64: (...flags: Array) => DataType>; uint8: DataType; uint16: DataType; uint24: DataType; uint32: DataType; uint40: DataType; uint48: DataType; // uint56: DataType, // uint64: DataType, int8: DataType; int16: DataType; int24: DataType; int32: DataType; int40: DataType; int48: DataType; // int56: DataType, // int64: DataType, enum8: (flags: Record) => DataType, Flags>; enum16: (flags: Record) => DataType, Flags>; enum32: (flags: Record) => DataType, Flags>; // semi: DataType, single: DataType; double: DataType; octstr: DataType; string: DataType; // octstr16: DataType, // string16: DataType, // array // struct // set // bag // ToD // date // UTC // clusterId // attribId // bacOID EUI48: DataType; EUI64: DataType; key128: DataType; //* Internal Types *// map4: (...flags: Array) => DataType>; uint4: DataType; enum4: (flags: Record) => DataType, Flags>; buffer: DataType; buffer8: DataType; buffer16: DataType; Array0: { (type: DataType): DataType>; // Overload to allow structs in arrays >( type: StaticStruct, ): DataType>>; }; Array8: { (type: DataType): DataType>; // Overload to allow structs in arrays >( type: StaticStruct, ): DataType>>; }; FixedString: (length: number) => DataType; }; type Bitmap = BitmapBase & { [K in Flags as K extends string ? K : never]: boolean; }; class BitmapBase { _buffer: Buffer; _fields: Array; setBit(index: number, value?: boolean): void; getBit(index: number): boolean; clearBit(index: number): void; setBits(bits: number | Array): void; getBits(): Array; get length(): number; static fromBuffer( buffer: Buffer, index: number, length: number, flags: Array, ): Bitmap; static toBuffer( buffer: Buffer, index: number, length: number, flags: Array, value: number, ): number; static toBuffer( buffer: Buffer, index: number, length: number, flags: Array | undefined, value: Bitmap, ): number; toArray(): Array; toBuffer(buffer: Buffer, index: number): Buffer; copy(): Bitmap; toJSON(): object; inspect(): string; } type StructField = DataType | StaticStruct; interface StaticStruct> { get fields(): Defs; get name(): string; get length(): number; fromJSON(props: any): StructInstance; fromArgs(...args: Array): StructInstance; fromBuffer(buffer: Buffer, index?: number, returnLength?: false): StructInstance; fromBuffer( buffer: Buffer, index?: number, returnLength?: true, ): { result: StructInstance; length: number; }; toBuffer(buffer?: Buffer, value?: StructProperties, index?: number): number; } type StructProperties> = { [Property in keyof Defs]: Defs[Property] extends DataType ? FromBuffer : Defs[Property] extends StaticStruct> ? StructProperties : never; }; type StructInstance> = StructProperties & { toJSON: () => StructProperties; toBuffer: (buffer?: Buffer, index?: number) => Buffer; }; function Struct>( name: string, defs: Defs, opts?: { encodeMissingFieldsBehavior?: "default" | "skip" }, ): StaticStruct; } /* How to use @athombv/data-types in TypeScript: // Create a Struct instance const ZdoEndDeviceAnnounceIndicationStruct = Struct("ZdoEndDeviceAnnounceIndication", { srcAddr: DataTypes.uint16, IEEEAddr: DataTypes.EUI64, }); // Create ZdoEndDeviceAnnounceIndication object from a buffer const ZdoEndDeviceAnnounceObject = ZdoEndDeviceAnnounceIndicationStruct.fromBuffer( Buffer.from([0, 1, 2, 3]) ); // @ts-expect-error srcAddr is not a string ZdoEndDeviceAnnounceObject.srcAddr.trim(); // Create Buffer instance from ZdoEndDeviceAnnounceObject const ZdoEndDeviceAnnounceBuffer = Buffer.alloc(8); // @ts-expect-error typo in IEEEAddr name ZdoEndDeviceAnnounceIndicationStruct.toBuffer(ZdoEndDeviceAnnounceBuffer, { srcAddr: 1, IEEAddr: 'abc' }); const Item = Struct('Item', { a: DataTypes.uint8, b: DataTypes.uint8 }); const ArrayOfItems = DataTypes.Array8(Item); Known limitation: Struct.fromArgs cannot be typed. */