getBinaryFixedPointDecoder

function getBinaryFixedPointDecoder<
    TSignedness,
    TTotalBits,
    TFractionalBits,
>(
    signedness,
    totalBits,
    fractionalBits,
    config?,
): FixedSizeDecoder<
    BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,
    BytesForTotalBits<TTotalBits>
>;

Returns a decoder for BinaryFixedPoint values of a specific shape. The decoder reads a fixed-size integer using two's-complement for signed values and little-endian byte order by default, and reconstructs a frozen BinaryFixedPoint from the bytes.

Throws SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED when totalBits is not a multiple of 8.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TFractionalBits extends number

Parameters

ParameterType
signednessTSignedness
totalBitsTTotalBits
fractionalBitsTFractionalBits
config?FixedPointCodecConfig

Returns

FixedSizeDecoder<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>, BytesForTotalBits<TTotalBits>>

Example

const decoder = getBinaryFixedPointDecoder('signed', 16, 15);
decoder.decode(new Uint8Array([0x00, 0x40])); // represents 0.5

See

On this page