Skip to main content
Defined in: modules/network/src/shared/network-data.ts:20 Payload of one received packet.

Remarks

Returned by getReceivedPackets. Like NfFile, it lets you read the payload in the format you need, but every method is synchronous since the bytes are already in memory. Packets carry no format tag: read a packet the way it was sent, text() for a string, json() for any other value.

Example

Constructors

Constructor

new NetworkData(bytes): NetworkData
Defined in: modules/network/src/shared/network-data.ts:26

Parameters

bytes
Uint8Array Raw payload bytes.

Returns

NetworkData

Methods

arrayBuffer()

arrayBuffer(): ArrayBuffer
Defined in: modules/network/src/shared/network-data.ts:40 Return the payload as a new ArrayBuffer.

Returns

ArrayBuffer

bytes()

bytes(): Uint8Array<ArrayBuffer>
Defined in: modules/network/src/shared/network-data.ts:33 Return the payload as a new Uint8Array.

Returns

Uint8Array<ArrayBuffer>

json()

json<T>(): T
Defined in: modules/network/src/shared/network-data.ts:56 Parse the payload as JSON and return the result.

Type Parameters

T
T = any

Returns

T

Throws

SyntaxError When the payload is not valid JSON.

text()

text(): string
Defined in: modules/network/src/shared/network-data.ts:47 Decode the payload as a UTF-8 string.

Returns

string