• @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.

    Type Parameters

    • This

      The type of the bitfield.

    • Value

      The type of the property decorated or the target type the bitfield resolve to.

    Parameters

    • len: number

      The bitlength of the property it decorate.

    • Optionalopt: Partial<BitFieldOptions>

    Returns DecoratorType<This, Value>

    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.

    class BitFieldObject {
    @Bitfield(2)
    field_1: number

    @Bitfield(4)
    field_2: number

    @Bitfield(1)
    field_3: number
    }

    class Header {
    @Relation(BitfieldObject)
    bitfield: BitFieldObject
    }

    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.

    If a Primitive (@Relation) has already been defined inside the bitfield class