Kit
Functions

getEnumDecoder

Call Signature

getEnumDecoder<TEnum>(constructor, config?): FixedSizeDecoder<GetEnumTo<TEnum>, 1>

Returns a decoder for enums.

This decoder deserializes enums from a numerical discriminator. By default, the discriminator is based on the positional index of the enum variants.

For more details, see getEnumCodec.

Type Parameters

Type ParameterDescription
TEnum extends EnumLookupObjectThe TypeScript enum or object mapping enum keys to values.

Parameters

ParameterTypeDescription
constructorTEnumThe constructor of the enum.
config?Omit<EnumCodecConfig<NumberDecoder>, "size">Configuration options for decoding the enum.

Returns

FixedSizeDecoder<GetEnumTo<TEnum>, 1>

A FixedSizeDecoder or VariableSizeDecoder for decoding enums.

Example

Decoding enum values.

enum Direction { Up,  Down, Left, Right }
const decoder = getEnumDecoder(Direction);
 
decoder.decode(new Uint8Array([0x00])); // Direction.Up
decoder.decode(new Uint8Array([0x01])); // Direction.Down
decoder.decode(new Uint8Array([0x02])); // Direction.Left
decoder.decode(new Uint8Array([0x03])); // Direction.Right

See

getEnumCodec

Call Signature

getEnumDecoder<TEnum, TSize>(constructor, config): FixedSizeDecoder<GetEnumTo<TEnum>, TSize>

Returns a decoder for enums.

This decoder deserializes enums from a numerical discriminator. By default, the discriminator is based on the positional index of the enum variants.

For more details, see getEnumCodec.

Type Parameters

Type ParameterDescription
TEnum extends EnumLookupObjectThe TypeScript enum or object mapping enum keys to values.
TSize extends number-

Parameters

ParameterTypeDescription
constructorTEnumThe constructor of the enum.
configEnumCodecConfig<NumberDecoder> & objectConfiguration options for decoding the enum.

Returns

FixedSizeDecoder<GetEnumTo<TEnum>, TSize>

A FixedSizeDecoder or VariableSizeDecoder for decoding enums.

Example

Decoding enum values.

enum Direction { Up,  Down, Left, Right }
const decoder = getEnumDecoder(Direction);
 
decoder.decode(new Uint8Array([0x00])); // Direction.Up
decoder.decode(new Uint8Array([0x01])); // Direction.Down
decoder.decode(new Uint8Array([0x02])); // Direction.Left
decoder.decode(new Uint8Array([0x03])); // Direction.Right

See

getEnumCodec

Call Signature

getEnumDecoder<TEnum>(constructor, config?): VariableSizeDecoder<GetEnumTo<TEnum>>

Returns a decoder for enums.

This decoder deserializes enums from a numerical discriminator. By default, the discriminator is based on the positional index of the enum variants.

For more details, see getEnumCodec.

Type Parameters

Type ParameterDescription
TEnum extends EnumLookupObjectThe TypeScript enum or object mapping enum keys to values.

Parameters

ParameterTypeDescription
constructorTEnumThe constructor of the enum.
config?EnumCodecConfig<NumberDecoder>Configuration options for decoding the enum.

Returns

VariableSizeDecoder<GetEnumTo<TEnum>>

A FixedSizeDecoder or VariableSizeDecoder for decoding enums.

Example

Decoding enum values.

enum Direction { Up,  Down, Left, Right }
const decoder = getEnumDecoder(Direction);
 
decoder.decode(new Uint8Array([0x00])); // Direction.Up
decoder.decode(new Uint8Array([0x01])); // Direction.Down
decoder.decode(new Uint8Array([0x02])); // Direction.Left
decoder.decode(new Uint8Array([0x03])); // Direction.Right

See

getEnumCodec

On this page