Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

RpcSerialization

18 exports Since v1.0.0 Source

Errors

Signature

declare class RpcSerializationError extends YieldableError<this> & {
readonly _tag: "RpcSerializationError";
} & Readonly<{
readonly bufferSize: number;
readonly maxBufferSize: number;
readonly reason: "BufferSizeExceeded";
}> {
constructor(args: {
readonly bufferSize: number;
readonly maxBufferSize: number;
readonly reason: "BufferSizeExceeded";
});
message: string;
}

Serialization

Since v1.0.0

Signature

declare const json: RpcSerialization["Type"]
Since v1.0.0

Signature

declare function jsonRpc(options?: {
readonly contentType?: string;
}): any

A rpc serialization layer that uses JSON for serialization.

Use this if your protocol supports framing for messages, otherwise use layerNdjson.

Signature

declare const layerJson: Layer.Layer<RpcSerialization>

A rpc serialization layer that uses JSON-RPC for serialization.

Signature

declare function layerJsonRpc(options?: {
readonly contentType?: string;
}): Layer<RpcSerialization>

A rpc serialization layer that uses MessagePack for serialization.

MessagePack has a more compact binary format compared to JSON and NDJSON. It also has better support for binary data.

Signature

declare const layerMsgPack: Layer.Layer<RpcSerialization>

Signature

declare function layerMsgPackWith(options?: any): Layer<RpcSerialization>

A rpc serialization layer that uses NDJSON for serialization.

Use this if your protocol does not support framing for messages, otherwise use layerJson.

Signature

declare const layerNdjson: Layer.Layer<RpcSerialization>

A rpc serialization layer that uses JSON-RPC for serialization separated by new lines.

Signature

declare function layerNdJsonRpc(options?: {
readonly contentType?: string;
readonly maxBufferSize?: number | "unbounded";
}): Layer<RpcSerialization>

Signature

declare function layerNdjsonWith(options?: StreamOptions): Layer<RpcSerialization>

Create a MessagePack serialization with custom msgpackr options.

Signature

declare function makeMsgPack(options?: any): any

Signature

declare function makeNdjson(options?: StreamOptions): any
Since v1.0.0

Signature

declare const msgPack: RpcSerialization["Type"]
Since v1.0.0

Signature

declare const ndjson: RpcSerialization["Type"]

Signature

declare function ndJsonRpc(options?: {
readonly contentType?: string;
readonly maxBufferSize?: number | "unbounded";
}): any

Parser

interface
Since v1.0.0

Signature

interface Parser {
readonly decode: (data: string | Uint8Array<ArrayBufferLike>) => readonly Array<unknown>;
readonly encode: (response: unknown) => string | Uint8Array<ArrayBufferLike> | undefined;
}

Signature

declare class RpcSerialization extends any {
constructor();
}

StreamOptions

interface
Since v1.0.0

Signature

interface StreamOptions {
readonly maxBufferSize?: number | "unbounded";
}