KIT

FixedSizeCodec

一个可以编码和解码固定大小的字节数组的值的对象。

请参阅 Codec 以了解更多关于创建和组合编解码器的信息。

示例

const codec: FixedSizeCodec<number | bigint, bigint, 8>;
const bytes = codec.encode(42);
const value = codec.decode(bytes); // 42n
const size = codec.fixedSize; // 8

参见

类型参数

类型参数默认类型描述
TFrom-要编码的值的类型。
TTo extends TFromTFrom解码后的值的类型。
TSize extends numbernumber编码值的固定大小(以字节为单位)。

属性

属性修饰符类型描述
decodereadonly(bytes, offset?) => TTo在给定的偏移量(或零)处解码提供的字节数组,并直接返回值。
encodereadonly(value) => ReadonlyUint8Array编码提供的值,并直接返回编码后的字节。
fixedSizereadonlyTSize编码值的固定大小(以字节为单位)。
readreadonly(bytes, offset) => [TTo, number]从提供的字节数组中给定的偏移量处读取编码值。返回解码后的值和编码值之后下一个字节的偏移量。
writereadonly(value, bytes, offset) => number将编码值写入提供的字节数组中给定的偏移量处。返回编码值之后下一个字节的偏移量。

On this page