Skip to content
Welcome to the Astrobase SDK documentation. This area is currently under development.

Codecs

The codec system allows for the encoding and decoding of data payloads based on their media type.

Codecs are an object that implements the Codec interface. They are mapped to media types via the config.

The following codecs are included with the Common config:

Codec NameMedia Type
Binaryapplication/octet-stream
JSONapplication/json
Astrobase Wrapapplication/astrobase-wrap

To implement a custom codec, create an object that implements the Codec interface:

import type { Codec } from '@astrobase/sdk/codecs';
const customCodec: Codec<DeserializedType> = {
decode(payload, { instance, mediaType }) {
// Deserialize from binary back into the data
},
encode(data, { instance, mediaType }) {
// Serialize the data into binary
},
middleware: [
// Optionally provide codec-scoped middleware(s)
],
};