toip.tools

interface · Browser and Node

BodyCodec

@toip-tools/trust-coreView source
TypeScriptImport
import { type BodyCodec } from "@toip-tools/trust-core";

Declaration

TypeScriptinterface
interface BodyCodec {
  /** The body's first byte: 0x7B for JSON, 0x01 for CTT1. */
  readonly format: number;
  /** The body bytes, or null when this codec can't carry `doc` exactly (use JSON). */
  encode(doc: TrustTaskDocument<unknown>, ctx: BodyContext): Uint8Array | null;
  decode(body: Uint8Array, ctx: BodyContext): TrustTaskDocument<unknown>;
}

Properties

formatrequired · readonly
number

The body's first byte: 0x7B for JSON, 0x01 for CTT1.

Methods

encode

The body bytes, or null when this codec can't carry doc exactly (use JSON).

TypeScriptSignature
encode(doc: TrustTaskDocument<unknown>, ctx: BodyContext): Uint8Array | null;

Parameters

docrequired
TrustTaskDocument<unknown>
ctxrequired
BodyContext

Returns

Uint8Array<ArrayBufferLike> | null

decode

TypeScriptSignature
decode(body: Uint8Array, ctx: BodyContext): TrustTaskDocument<unknown>;

Parameters

bodyrequired
Uint8Array<ArrayBufferLike>
ctxrequired
BodyContext

Returns

TrustTaskDocument<unknown>