Skip to content

Codec

Defined in: astrobase/src/codecs/codecs.ts:26

The interface for a Codec. It provides serialization and deserialization to/from binary format.

T = unknown

optional middlewares: Middleware[]

Defined in: astrobase/src/codecs/codecs.ts:53

An optional array of Middlewares that will be scoped only to this codec. Codec-scoped middlewares are executed in order before Instance-scoped middleware when decoding, and after Instance-scoped middleware when encoding.

decode(payload, context): MaybePromise<T>

Defined in: astrobase/src/codecs/codecs.ts:36

A function that deserializes from the binary format. The function should also validate the data. If the data cannot be deserialized or is invalid, an error should be thrown.

Uint8Array

The bytes to deserialize.

CodecContext

Additional properties that may be needed.

MaybePromise<T>

The deserialized value. Can be in promise form.

If the data cannot be deserialized or is invalid, an error should be thrown.


encode(data, context): MaybePromise<Uint8Array<ArrayBufferLike>>

Defined in: astrobase/src/codecs/codecs.ts:46

A function that serializes to the binary format. The function should also validate the data. If the data cannot be serialized or is invalid, an error should be thrown.

T

The value to serialize.

CodecContext

Additional properties that may be needed.

MaybePromise<Uint8Array<ArrayBufferLike>>

The serialized bytes. Can be in promise form.

If the data cannot be serialized or is invalid, an error should be thrown.