[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/script-host](https://jsprismarine.dev/api/@jsprismarine/script-host/index.md) / [debugger/framing](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/framing/index.md) / FrameDecoder

# Class: FrameDecoder

Defined in: [script-host/src/debugger/framing.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/framing.ts#L44)

Splits the bytes of a connection into messages, whatever sizes the chunks arrive in. The
extension reads each body as JSON whole, so a body's trailing newline is part of the JSON's
whitespace and the decoder does not require it. Chunks wait in a list until a header or a body
is complete, so each byte is copied at most once more however small the chunks are.

## Constructors

### Constructor

> **new FrameDecoder**(): `FrameDecoder`

#### Returns

`FrameDecoder`

## Methods

### push()

> **push**(`chunk`): `unknown`[]

Defined in: [script-host/src/debugger/framing.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/debugger/framing.ts#L55)

Takes the next chunk of bytes.

#### Parameters

##### chunk

`Uint8Array`

#### Returns

`unknown`[]

The messages the bytes so far complete, in order.

#### Throws

When a header is not 8 hexadecimal digits and a newline, a header states a body
longer than [MAX\_RECEIVED\_FRAME\_LENGTH](https://jsprismarine.dev/api/@jsprismarine/script-host/debugger/framing/index.md#max_received_frame_length), or a body is not JSON.
