/** * Module definition of {@link BitField} decorators. * * {@link BitField} type decorators define bitfields data-structure. * * Bitfields are classes where properties have a fixed size in bits. * * In a bitfield class definition the topmost `@Bitfield` decorated * property match the most significant bit being encoded/decoded. * * @example * * ```typescript * class StatusRegister { * @Bitfield(1) * carry_flag: number * * @Bitfield(1) * zero_flag: number * * @Bitfield(1) * interrupt_disable_flag: number * * @Bitfield(1) * decimal_flag: number * * @Bitfield(1) * break_flag: number * * @Bitfield(1) * _: number * * @Bitfield(1) * overflow_flag: number * } * * class Header { * @Relation(StatusRegister) * bitfield: StatusRegister * } * ``` * * @remarks * * {@link BitField} type decorator can't be used inside class * definition that also contains {@link Primitive} definition. * To create a {@link BitField} object create a class solely * made for the bitfield definition as in the example. * * @see {@link Bitfield} * * @module Bitfield */ import { type PropertyMetaDescriptor } from './common.ts'; import { type Cursor, type BinaryWriter } from '../cursor.ts'; import { type DecoratorType } from '../types.ts'; export declare const BitFieldSymbol: unique symbol; /** * BitFieldOptions. * * @category Options */ export interface BitFieldOptions { /** * Verify there is no relation defined in the target object. */ primitiveCheck: boolean; } /** * @category Options */ export declare const BitFieldOptionsDefault: { primitiveCheck: boolean; }; export interface BitField extends PropertyMetaDescriptor { options: BitFieldOptions; bitlength: number; } /** * `bitFieldDecoratorFactory` is a function to help with the creation of {@link BitField} type decorators. * * @typeParam This The type of the bitfield. * @typeParam Value The type of the property decorated or the target type the bitfield resolve to. * * @param {string} name Decorator name * @param {number} len Size of the bitfield property * @param {Partial} opt Partial definition of the BitFieldOptions * @returns {DecoratorType} * * @category Advanced Use */ export declare function bitFieldDecoratorFactory(name: string, len: number, opt?: Partial): DecoratorType; /** * `@Bitfield` decorator define the bit-length of the property it decorates. * * The sum of the bit-length declared by the properties decorated with a * `@Bitfield` can exceed 8-bits and may not be aligned byte aligned. * * @example * * The top-most property of a class decorated with a `@Bitfield` decorator will * contain the most significant bits (MSB) of the value decoded/encoded. * In the example 'field_1' contains the two most significant bits. * * ```typescript * class BitFieldObject { * @Bitfield(2) * field_1: number * * @Bitfield(4) * field_2: number * * @Bitfield(1) * field_3: number * } * * class Header { * @Relation(BitfieldObject) * bitfield: BitFieldObject * } * ``` * * @remarks * * The sum of the bit-length declared by the properties decorated with a * `@Bitfield` would result in a 8, 16 or 32bits integer being read. Right now * 24 bits bitfields or longer than 32bits are not supported. * * @throws {WrongBitfieldClassImplementation} If a {@link Primitive} (`@Relation`) has already been defined inside the bitfield class * * @typeParam This The type of the bitfield. * @typeParam Value The type of the property decorated or the target type the bitfield resolve to. * * @param {number} len The bitlength of the property it decorate. * @returns {DecoratorType} * * @category Decorators */ export declare function Bitfield(len: number, opt?: Partial): DecoratorType; /** * Read a bitfield definition from a {@link Cursor}. This function is used * in the context of the {@link binread} function. * * @typeParam This The type of the bitfield. * * @param {Array} bitfields An array of {@link BitField} definition * @param {This} targetInstance The object related to the `bitfields` argument where the bitfield content will be written to. * @param {Cursor} cursor {@link Cursor} to read the content of the bitfield from. * * @category Advanced Use */ export declare function useBitField(bitfields: Array>, targetInstance: This, cursor: Cursor): This; /** * Write a bitfield definition to a {@link BinaryWriter}. This function is used * in the context of the {@link binwrite}. * * @typeParam This The type of the bitfield. * * @param {Array} bitfields An array of {@link BitField} definition * @param {This} targetInstance The object related to the `bitfields` argument with the bitfield content * @param {BinaryWriter} cursor Cursor the write the content of the bitfield to. * * @category Advanced Use */ export declare function writeBitField(bitfields: Array>, targetInstance: This, cursor: BinaryWriter): void;