interface · Browser and Node

# BodyCodec

`@toip-tools/trust-core` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/trust-core/src/compact.ts#L23)

Import:

```ts
import { type BodyCodec } from "@toip-tools/trust-core";
```

## Declaration

interface:

```ts
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

**`format` (required · 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).

Signature:

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

#### Parameters

- **`doc` (required)**: `TrustTaskDocument<unknown>`
- **`ctx` (required)**: `BodyContext`

#### Returns

`Uint8Array<ArrayBufferLike> | null`

### `decode`

Signature:

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

#### Parameters

- **`body` (required)**: `Uint8Array<ArrayBufferLike>`
- **`ctx` (required)**: `BodyContext`

#### Returns

`TrustTaskDocument<unknown>`

[Usage guide](https://toip.tools/toolkit/trust-core/#usage) · [Error handling](https://toip.tools/toolkit/trust-core/#errors) · [All exports](https://toip.tools/toolkit/trust-core/api/)

---

This is the Markdown version of https://toip.tools/toolkit/trust-core/api/BodyCodec/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
