Codec
Defined in: astrobase/src/codecs/codecs.ts:26
The interface for a Codec. It provides serialization and deserialization to/from binary format.
Type Parameters
Section titled “Type Parameters”T
= unknown
Properties
Section titled “Properties”middlewares?
Section titled “middlewares?”
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.
Methods
Section titled “Methods”decode()
Section titled “decode()”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.
Parameters
Section titled “Parameters”payload
Section titled “payload”Uint8Array
The bytes to deserialize.
context
Section titled “context”Additional properties that may be needed.
Returns
Section titled “Returns”MaybePromise
<T
>
The deserialized value. Can be in promise form.
Throws
Section titled “Throws”If the data cannot be deserialized or is invalid, an error should be thrown.
encode()
Section titled “encode()”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.
Parameters
Section titled “Parameters”T
The value to serialize.
context
Section titled “context”Additional properties that may be needed.
Returns
Section titled “Returns”MaybePromise
<Uint8Array
<ArrayBufferLike
>>
The serialized bytes. Can be in promise form.
Throws
Section titled “Throws”If the data cannot be serialized or is invalid, an error should be thrown.