Skip to content

API reference / @jsprismarine/prismarine / network/encodePacketBatch

network/encodePacketBatch ​

Classes ​

Interfaces ​

EncodedPacketBatch ​

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:132

Encoded packet objects and the batch that carries them.

Properties ​

content ​

content: Buffer

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:134

The framed bytes ready for the transport.

packetBuffers ​

packetBuffers: readonly Buffer<ArrayBufferLike>[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:138

Transient packet views, valid for the synchronous batch assembly and packet diagnostics.

packets ​

packets: readonly NetworkPacket<unknown>[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:136

The version-specific packets that produced those bytes.


EncodedPacketBuffers ​

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:144

A protocol-stamped packet and its bytes, ready to join into one or more batches.

Properties ​

buffers ​

buffers: Buffer<ArrayBufferLike>[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:148

Bytes in the same order as packets.

packets ​

packets: NetworkPacket<unknown>[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:146

Packets prepared for the selected protocol version.


PacketBatchOptions ​

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:9

Options the server supplies when framing already-encoded Minecraft packets.

Extended by ​

Properties ​

compressed? ​

optional compressed?: boolean

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:11

Whether the negotiated batch format includes a compression prefix.

compressionAlgorithm? ​

optional compressionAlgorithm?: PacketCompressionAlgorithm

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:13

Algorithm advertised by this connection in NetworkSettings.

compressionLevel? ​

optional compressionLevel?: number

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:17

zlib level for this batch; omitted to use Protocol's default.

compressionThreshold? ​

optional compressionThreshold?: number

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:15

Smallest batch payload size to compress; zero leaves every batch uncompressed.

fragmentCache? ​

optional fragmentCache?: FullFlushFragmentCache

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:23

Cache shared fragments for the lifetime appropriate to the caller.

fragmentCodec? ​

optional fragmentCodec?: ProtocolCodec

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:21

The protocol layout owner used as part of each fragment cache key.

fragmentKeyDiscriminators? ​

optional fragmentKeyDiscriminators?: readonly string[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:27

Extra packet identity when a stable key alone does not identify the full packet.

fragmentKeys? ​

optional fragmentKeys?: readonly Buffer<ArrayBufferLike>[]

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:25

Optional stable per-packet cache keys, used by serialized chunk payloads.

fullFlushFragments? ​

optional fullFlushFragments?: boolean

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:19

Use independently compressed, reusable packet fragments for this batch.

Type Aliases ​

PacketEncodingLifetime ​

PacketEncodingLifetime = "transient" | "cached"

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:142

Whether encoded packet views are for immediate framing or caller retention.

Variables ​

ASYNC_PACKET_BATCH_THRESHOLD ​

const ASYNC_PACKET_BATCH_THRESHOLD: number

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:152

Compressed packet bodies above this size use zlib's asynchronous API.

Functions ​

encodePacketBatch() ​

encodePacketBatch(packets, codec, options?, lifetime?): EncodedPacketBatch

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:163

Prepares each packet for one negotiated Protocol codec and frames their bytes with Protocol's batch codec. The server owns codec selection; Protocol owns packet encoding and batch layout.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

Packets as the caller built them.

codec ​

ProtocolCodec

The negotiated packet ids, layouts, and Protocol context.

options? ​

PacketBatchOptions = {}

Compression state and optional zlib level.

lifetime? ​

PacketEncodingLifetime = 'transient'

Keep packet bytes on each packet when callers need its cached getBuffer() contract.

Returns ​

EncodedPacketBatch

Version-specific packets and their framed batch.


encodePacketBatchAsync() ​

encodePacketBatchAsync(packets, codec, options?): Promise<EncodedPacketBatch>

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:312

The async counterpart for large batches whose deflate should leave the main thread.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

codec ​

ProtocolCodec

options? ​

PacketBatchOptions = {}

Returns ​

Promise<EncodedPacketBatch>


encodePacketBatchBySize() ​

encodePacketBatchBySize(packets, codec, options?, lifetime?): EncodedPacketBatch | Promise<EncodedPacketBatch>

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:298

Encodes small batches synchronously and moves larger deflates to the libuv pool. Packet encoding still runs once on the calling thread; only zlib moves off it.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

Packets as the caller built them.

codec ​

ProtocolCodec

The negotiated packet ids, layouts, and Protocol context.

options? ​

PacketBatchOptions = {}

Compression state and optional zlib level.

lifetime? ​

PacketEncodingLifetime = 'transient'

Returns ​

EncodedPacketBatch | Promise<EncodedPacketBatch>

The batch directly below the threshold, or a promise above it.


encodePacketBatchFromBuffers() ​

encodePacketBatchFromBuffers(packets, packetBuffers, options?): EncodedPacketBatch

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:195

Frames protocol-encoded packet buffers without encoding their packet objects again.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

The version-specific packets that produced packetBuffers.

packetBuffers ​

readonly Buffer<ArrayBufferLike>[]

Encoded packet bodies in the same order as packets.

options? ​

PacketBatchOptions = {}

Compression state, zlib level, and size threshold.

Returns ​

EncodedPacketBatch

The batch ready for the transport.


encodePacketBatchFromBuffersBySize() ​

encodePacketBatchFromBuffersBySize(packets, packetBuffers, options?): EncodedPacketBatch | Promise<EncodedPacketBatch>

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:226

Frames already encoded packets, compressing only when the configured body-size threshold is met.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

The version-specific packets that produced packetBuffers.

packetBuffers ​

readonly Buffer<ArrayBufferLike>[]

Encoded packet bodies in the same order as packets.

options? ​

PacketBatchOptions = {}

Compression state, zlib level, and size threshold.

Returns ​

EncodedPacketBatch | Promise<EncodedPacketBatch>

The batch directly below the async deflate threshold, or a promise above it.


encodePacketsForCodec() ​

encodePacketsForCodec(packets, codec, lifetime?): EncodedPacketBuffers

Defined in: packages/prismarine/src/network/encodePacketBatch.ts:180

Encodes packets once for one protocol codec so their buffers can be shared across audiences.

Parameters ​

packets ​

readonly NetworkPacket<unknown>[]

Packets as the caller built them.

codec ​

ProtocolCodec

The negotiated packet ids, layouts, and Protocol context.

lifetime? ​

PacketEncodingLifetime = 'transient'

Returns ​

EncodedPacketBuffers

Protocol-stamped packets and their bytes in matching order.