getBinaryFixedPointEncoder

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

Returns an encoder for BinaryFixedPoint values of a specific shape. The encoder serializes value.raw as a fixed-size integer using two's-complement for signed values and little-endian byte order by default.

Throws SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED when totalBits is not a multiple of 8. Encoding a value whose shape does not match the codec's shape throws SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TFractionalBits extends number

Parameters

ParameterType
signednessTSignedness
totalBitsTTotalBits
fractionalBitsTFractionalBits
config?FixedPointCodecConfig

Returns

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

Example

const encoder = getBinaryFixedPointEncoder('signed', 16, 15);
encoder.encode(binaryFixedPoint('signed', 16, 15)('0.5')); // 0x0040

See

On this page