@mml-io/delta-net-protocol 0.0.0-experimental-bcf0b7c-20250715

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +6 -0
  2. package/build/BufferReader.d.ts +92 -0
  3. package/build/BufferWriter.d.ts +98 -0
  4. package/build/DeflateCompressor.d.ts +14 -0
  5. package/build/delta-net-v0.1/constants.d.ts +1 -0
  6. package/build/delta-net-v0.1/decodeClientMessages.d.ts +3 -0
  7. package/build/delta-net-v0.1/decodeServerMessages.d.ts +6 -0
  8. package/build/delta-net-v0.1/encodeClientMessage.d.ts +3 -0
  9. package/build/delta-net-v0.1/encodeServerMessage.d.ts +3 -0
  10. package/build/delta-net-v0.1/index.d.ts +7 -0
  11. package/build/delta-net-v0.1/messageTypes.d.ts +12 -0
  12. package/build/delta-net-v0.1/messages/from-client/clientCustom.d.ts +9 -0
  13. package/build/delta-net-v0.1/messages/from-client/connectUser.d.ts +31 -0
  14. package/build/delta-net-v0.1/messages/from-client/index.d.ts +9 -0
  15. package/build/delta-net-v0.1/messages/from-client/pong.d.ts +8 -0
  16. package/build/delta-net-v0.1/messages/from-client/setUserComponents.d.ts +27 -0
  17. package/build/delta-net-v0.1/messages/from-server/error.d.ts +22 -0
  18. package/build/delta-net-v0.1/messages/from-server/index.d.ts +15 -0
  19. package/build/delta-net-v0.1/messages/from-server/initialCheckout.d.ts +56 -0
  20. package/build/delta-net-v0.1/messages/from-server/ping.d.ts +8 -0
  21. package/build/delta-net-v0.1/messages/from-server/serverCustom.d.ts +9 -0
  22. package/build/delta-net-v0.1/messages/from-server/tick.d.ts +60 -0
  23. package/build/delta-net-v0.1/messages/from-server/userIndex.d.ts +8 -0
  24. package/build/delta-net-v0.1/messages/from-server/warning.d.ts +8 -0
  25. package/build/delta-net-v0.1/messages/index.d.ts +2 -0
  26. package/build/index.d.ts +4 -0
  27. package/build/index.js +1104 -0
  28. package/build/index.js.map +7 -0
  29. package/package.json +28 -0
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # DeltaNet Protocol
2
+ #### `@mml-io/delta-net-protocol`
3
+
4
+ [![npm version](https://img.shields.io/npm/v/@mml-io/delta-net-protocol.svg?style=flat)](https://www.npmjs.com/package/@mml-io/delta-net-protocol)
5
+
6
+ This package contains a TypeScript definition / message types of the `delta-net-v0.1` protocol used by `@mml-io/delta-net-server` and `@mml-io/delta-net-web`.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * A class for reading binary data from a Uint8Array buffer.
3
+ * Supports various data types including varints, strings, and boolean arrays.
4
+ * All numeric values are read using varint encoding for efficiency.
5
+ */
6
+ export declare class BufferReader {
7
+ private buffer;
8
+ private offset;
9
+ /**
10
+ * Creates a new BufferReader instance.
11
+ * @param buffer - The Uint8Array to read from
12
+ */
13
+ constructor(buffer: Uint8Array);
14
+ /**
15
+ * Reads a single unsigned 8-bit integer from the buffer.
16
+ * @returns The read value
17
+ */
18
+ readUInt8(): number;
19
+ /**
20
+ * Reads a boolean value from the buffer.
21
+ * @returns true if the read byte is 1, false otherwise
22
+ */
23
+ readBoolean(): boolean;
24
+ /**
25
+ * Reads a specified number of bytes from the buffer.
26
+ * @param length - The number of bytes to read
27
+ * @returns A new Uint8Array containing the read bytes
28
+ */
29
+ readBytes(length: number): Uint8Array;
30
+ /**
31
+ * Reads a length-prefixed byte array from the buffer.
32
+ * The length is encoded as a varint.
33
+ * @returns A new Uint8Array containing the read bytes
34
+ */
35
+ readUVarintPrefixedBytes(): Uint8Array;
36
+ /**
37
+ * Reads a varint-encoded integer from the buffer.
38
+ * Varints are variable-length integers that use the high bit of each byte to indicate if more bytes follow.
39
+ * @param signed - Whether to interpret the value as a signed integer
40
+ * @returns The decoded integer value
41
+ * @throws Error if the varint encoding is invalid
42
+ */
43
+ readUVarint(signed?: boolean): number;
44
+ /**
45
+ * Reads a string from the buffer with a specified byte length.
46
+ * Optimized for ASCII strings, falls back to TextDecoder for non-ASCII.
47
+ * @param byteLength - The number of bytes to read
48
+ * @returns The decoded string
49
+ */
50
+ private readStringBytes;
51
+ /**
52
+ * Reads a length-prefixed string from the buffer.
53
+ * The length is encoded as an unsigned varint.
54
+ * @returns The decoded string
55
+ */
56
+ readUVarintPrefixedString(): string;
57
+ /**
58
+ * Reads a length-prefixed string from the buffer.
59
+ * The length is encoded as a signed varint.
60
+ * @returns A tuple containing the decoded string and a boolean indicating if the length was negative
61
+ */
62
+ readVarintPrefixedString(): [string, boolean];
63
+ /**
64
+ * Reads a signed varint-encoded integer from the buffer.
65
+ * @returns The decoded signed integer value
66
+ */
67
+ readVarint(): number;
68
+ /**
69
+ * Reads a varint-encoded bigint from the buffer.
70
+ * Varints are variable-length integers that use the high bit of each byte to indicate if more bytes follow.
71
+ * @param signed - Whether to interpret the value as a signed integer
72
+ * @returns The decoded bigint value
73
+ * @throws Error if the varint encoding is invalid
74
+ */
75
+ readUVarintBigInt(signed?: boolean): bigint;
76
+ /**
77
+ * Reads a signed varint-encoded integer from the buffer.
78
+ * @returns The decoded signed integer value
79
+ */
80
+ readBigIntVarint(): bigint;
81
+ /**
82
+ * Reads an array of boolean values from the buffer.
83
+ * The booleans are packed into bytes (8 booleans per byte).
84
+ * @returns An array of boolean values
85
+ */
86
+ readLengthPrefixedBoolArray(): boolean[];
87
+ /**
88
+ * Checks if the reader has reached the end of the buffer.
89
+ * @returns true if all bytes have been read, false otherwise
90
+ */
91
+ isEnd(): boolean;
92
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A class for writing binary data to a Uint8Array buffer.
3
+ * Supports various data types including varints, strings, and boolean arrays.
4
+ * All numeric values are written using varint encoding for efficiency.
5
+ * The buffer automatically expands as needed.
6
+ */
7
+ export declare class BufferWriter {
8
+ private buffer;
9
+ private offset;
10
+ /**
11
+ * Creates a new BufferWriter instance.
12
+ * @param initialLength - The initial size of the buffer in bytes
13
+ */
14
+ constructor(initialLength: number);
15
+ /**
16
+ * Writes an unsigned 8-bit integer to the buffer.
17
+ * @param value - The value to write (will be truncated to 8 bits)
18
+ */
19
+ writeUint8(value: number): void;
20
+ /**
21
+ * Writes a boolean value to the buffer.
22
+ * @param bool - The boolean value to write (true = 1, false = 0)
23
+ */
24
+ writeBoolean(bool: boolean): void;
25
+ /**
26
+ * Writes an array of bytes to the buffer without a length prefix.
27
+ * @param bytes - The bytes to write
28
+ */
29
+ writeUnprefixedBytes(bytes: Uint8Array): void;
30
+ /**
31
+ * Writes a length-prefixed array of bytes to the buffer.
32
+ * The length is encoded as an unsigned varint.
33
+ * @param bytes - The bytes to write
34
+ */
35
+ writeUVarintLengthPrefixedBytes(bytes: Uint8Array): void;
36
+ /**
37
+ * Gets the written bytes as a Uint8Array.
38
+ * @returns A new Uint8Array containing only the written bytes
39
+ */
40
+ getBuffer(): Uint8Array;
41
+ /**
42
+ * Gets the number of bytes written so far.
43
+ * @returns The current write offset
44
+ */
45
+ getWrittenLength(): number;
46
+ /**
47
+ * Ensures the buffer has enough capacity for the required space.
48
+ * @param neededSpace - The number of additional bytes needed
49
+ */
50
+ private ensureCapacity;
51
+ /**
52
+ * Expands the buffer by doubling its current length.
53
+ */
54
+ private expandBuffer;
55
+ /**
56
+ * Writes an unsigned varint to the buffer.
57
+ * Varints are variable-length integers that use the high bit of each byte to indicate if more bytes follow.
58
+ * @param x - The value to write
59
+ */
60
+ writeUVarint(x: number): void;
61
+ /**
62
+ * Writes an unsigned varint to the buffer.
63
+ * Varints are variable-length integers that use the high bit of each byte to indicate if more bytes follow.
64
+ * @param x - The value to write
65
+ */
66
+ writeUVarintBigInt(x: bigint): void;
67
+ /**
68
+ * Writes a signed varint to the buffer using zigzag encoding.
69
+ * @param x - The signed value to write
70
+ */
71
+ writeVarint(x: number): void;
72
+ /**
73
+ * Writes a signed varint to the buffer using zigzag encoding.
74
+ * @param x - The signed value to write
75
+ */
76
+ writeBigIntVarint(x: bigint): void;
77
+ /**
78
+ * Writes an array of boolean values to the buffer.
79
+ * The booleans are packed into bytes (8 booleans per byte).
80
+ * @param data - The array of boolean values to write
81
+ */
82
+ writeLengthPrefixedBoolArray(data: boolean[]): void;
83
+ /**
84
+ * Writes a length-prefixed string to the buffer.
85
+ * Optimized for ASCII strings, falls back to TextEncoder for non-ASCII.
86
+ * @param value - The string to write
87
+ * @param varint - Whether to use signed varint for length (default: false)
88
+ * @param negativeLength - Whether the length should be negative (only used if varint is true)
89
+ */
90
+ writeLengthPrefixedString(value: string, varint?: boolean, negativeLength?: boolean): void;
91
+ }
92
+ /**
93
+ * Encodes a signed integer using zigzag encoding.
94
+ * Zigzag encoding maps signed integers to unsigned integers in a way that preserves ordering.
95
+ * @param value - The signed value to encode
96
+ * @returns The zigzag-encoded value
97
+ */
98
+ export declare function zigzagEncode(value: number): number;
@@ -0,0 +1,14 @@
1
+ export declare enum CompressionLibraryChoice {
2
+ PAKO = "PAKO",
3
+ NODE_ZLIB = "NODE_ZLIB",
4
+ NO_PREFERENCE = "NO_PREFERENCE",
5
+ NONE = "NONE"
6
+ }
7
+ export declare class DeflateCompressor {
8
+ static compress(data: Uint8Array, compressionLibrary?: CompressionLibraryChoice): Uint8Array;
9
+ static decompress(compressed: Uint8Array, compressionLibrary?: CompressionLibraryChoice): Uint8Array;
10
+ static varIntCompress(data: BigInt64Array, length: number, compressionLibrary?: CompressionLibraryChoice): [Uint8Array, Uint8Array];
11
+ static varIntDecompress(compressed: Uint8Array, length: number, compressionLibrary?: CompressionLibraryChoice): BigInt64Array;
12
+ static varIntBytesCompress(data: Array<Uint8Array | null>, length: number, compressionLibrary?: CompressionLibraryChoice): [Uint8Array, Uint8Array];
13
+ static varIntBytesDecompress(compressed: Uint8Array, length: number, compressionLibrary?: CompressionLibraryChoice): Array<Uint8Array>;
14
+ }
@@ -0,0 +1 @@
1
+ export declare const deltaNetProtocolSubProtocol_v0_1 = "delta-net-v0.1";
@@ -0,0 +1,3 @@
1
+ import { BufferReader } from "../BufferReader";
2
+ import { DeltaNetV01ClientMessage } from "./messages";
3
+ export declare function decodeClientMessages(buffer: BufferReader): Array<DeltaNetV01ClientMessage>;
@@ -0,0 +1,6 @@
1
+ import { BufferReader } from "../BufferReader";
2
+ import { DeltaNetV01ServerMessage } from "./messages";
3
+ export type DecodeServerMessageOptions = {
4
+ ignoreData?: boolean;
5
+ };
6
+ export declare function decodeServerMessages(buffer: BufferReader, opts?: DecodeServerMessageOptions): Array<DeltaNetV01ServerMessage>;
@@ -0,0 +1,3 @@
1
+ import { BufferWriter } from "../BufferWriter";
2
+ import { DeltaNetV01ClientMessage } from "./messages";
3
+ export declare function encodeClientMessage(message: DeltaNetV01ClientMessage, writer: BufferWriter): void | BufferWriter;
@@ -0,0 +1,3 @@
1
+ import { BufferWriter } from "../BufferWriter";
2
+ import { DeltaNetV01ServerMessage } from "./messages";
3
+ export declare function encodeServerMessage(message: DeltaNetV01ServerMessage, writer?: BufferWriter): BufferWriter;
@@ -0,0 +1,7 @@
1
+ export * from "./constants";
2
+ export * from "./decodeClientMessages";
3
+ export * from "./decodeServerMessages";
4
+ export * from "./encodeClientMessage";
5
+ export * from "./encodeServerMessage";
6
+ export * from "./messages";
7
+ export * from "./messageTypes";
@@ -0,0 +1,12 @@
1
+ export declare const InitialCheckoutMessageType = 1;
2
+ export declare const ServerCustomMessageType = 2;
3
+ export declare const UserIndexMessageType = 3;
4
+ export declare const TickMessageType = 4;
5
+ export declare const PingMessageType = 5;
6
+ export declare const WarningMessageType = 6;
7
+ export declare const ErrorMessageType = 7;
8
+ export declare const ConnectUserMessageType = 64;
9
+ export declare const ClientCustomMessageType = 65;
10
+ export declare const SetUserComponentsMessageType = 66;
11
+ export declare const SetUserStateMessageType = 67;
12
+ export declare const PongMessageType = 68;
@@ -0,0 +1,9 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01ClientCustomMessage = {
4
+ type: "clientCustom";
5
+ customType: number;
6
+ contents: string;
7
+ };
8
+ export declare function encodeClientCustom(msg: DeltaNetV01ClientCustomMessage, writer?: BufferWriter): BufferWriter;
9
+ export declare function decodeClientCustom(buffer: BufferReader): DeltaNetV01ClientCustomMessage;
@@ -0,0 +1,31 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ /**
4
+ * Initial connection request message from client to server.
5
+ * Contains authentication token and initial state of the connecting user.
6
+ */
7
+ export type DeltaNetV01ConnectUserMessage = {
8
+ /** Message type identifier */
9
+ type: "connectUser";
10
+ /** Authentication token for the user */
11
+ token: string;
12
+ /** Whether the client is an observer-only client */
13
+ observer: boolean;
14
+ /** Array of [componentId, value] pairs for the user's initial component values */
15
+ components: Array<[number, bigint]>;
16
+ /** Array of [stateId, value] pairs for the user's initial state values */
17
+ states: Array<[number, Uint8Array]>;
18
+ };
19
+ /**
20
+ * Encodes a connect user message into a binary buffer.
21
+ * @param connectUserMessage - The message to encode
22
+ * @param writer - The BufferWriter to write to
23
+ */
24
+ export declare function encodeConnectUser(connectUserMessage: DeltaNetV01ConnectUserMessage, writer: BufferWriter): void;
25
+ /**
26
+ * Decodes a connect user message from a binary buffer.
27
+ * Assumes that the first byte (message type) has already been read.
28
+ * @param buffer - The BufferReader containing the message data
29
+ * @returns The decoded connect user message
30
+ */
31
+ export declare function decodeConnectUser(buffer: BufferReader): DeltaNetV01ConnectUserMessage;
@@ -0,0 +1,9 @@
1
+ import { DeltaNetV01ClientCustomMessage } from "./clientCustom";
2
+ import { DeltaNetV01ConnectUserMessage } from "./connectUser";
3
+ import { DeltaNetV01PongMessage } from "./pong";
4
+ import { DeltaNetV01SetUserComponentsMessage } from "./setUserComponents";
5
+ export * from "./connectUser";
6
+ export * from "./pong";
7
+ export * from "./setUserComponents";
8
+ export * from "./clientCustom";
9
+ export type DeltaNetV01ClientMessage = DeltaNetV01ConnectUserMessage | DeltaNetV01SetUserComponentsMessage | DeltaNetV01PongMessage | DeltaNetV01ClientCustomMessage;
@@ -0,0 +1,8 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01PongMessage = {
4
+ type: "pong";
5
+ pong: number;
6
+ };
7
+ export declare function encodePong(pongMessage: DeltaNetV01PongMessage, writer: BufferWriter): void;
8
+ export declare function decodePong(buffer: BufferReader): DeltaNetV01PongMessage;
@@ -0,0 +1,27 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ /**
4
+ * Message sent by client to update component and state values.
5
+ * Used to send user input and state changes to the server.
6
+ */
7
+ export type DeltaNetV01SetUserComponentsMessage = {
8
+ /** Message type identifier */
9
+ type: "setUserComponents";
10
+ /** Array of [componentId, value] pairs for updated component values */
11
+ components: Array<[number, bigint]>;
12
+ /** Array of [stateId, value] pairs for updated state values */
13
+ states: Array<[number, Uint8Array]>;
14
+ };
15
+ /**
16
+ * Encodes a set user components message into a binary buffer.
17
+ * @param message - The message to encode
18
+ * @param writer - The BufferWriter to write to
19
+ */
20
+ export declare function encodeSetUserComponents(message: DeltaNetV01SetUserComponentsMessage, writer: BufferWriter): void;
21
+ /**
22
+ * Decodes a set user components message from a binary buffer.
23
+ * Assumes that the first byte (message type) has already been read.
24
+ * @param buffer - The BufferReader containing the message data
25
+ * @returns The decoded set user components message
26
+ */
27
+ export declare function decodeSetUserComponents(buffer: BufferReader): DeltaNetV01SetUserComponentsMessage;
@@ -0,0 +1,22 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export declare namespace DeltaNetV01ServerErrors {
4
+ const USER_ALREADY_AUTHENTICATED_ERROR_TYPE = "USER_ALREADY_AUTHENTICATED";
5
+ const USER_NOT_AUTHENTICATED_ERROR_TYPE = "USER_NOT_AUTHENTICATED";
6
+ const AUTHENTICATION_IN_PROGRESS_ERROR_TYPE = "AUTHENTICATION_IN_PROGRESS";
7
+ const OBSERVER_CANNOT_SEND_STATE_UPDATES_ERROR_TYPE = "OBSERVER_CANNOT_SEND_STATE_UPDATES";
8
+ const UNSUPPORTED_WEBSOCKET_SUBPROTOCOL_ERROR_TYPE = "UNSUPPORTED_WEBSOCKET_SUBPROTOCOL";
9
+ const USER_NETWORKING_UNKNOWN_ERROR_TYPE = "USER_NETWORKING_UNKNOWN_ERROR";
10
+ const USER_AUTHENTICATION_FAILED_ERROR_TYPE = "USER_AUTHENTICATION_FAILED";
11
+ const USER_NETWORKING_CONNECTION_LIMIT_REACHED_ERROR_TYPE = "CONNECTION_LIMIT_REACHED";
12
+ const USER_NETWORKING_SERVER_SHUTDOWN_ERROR_TYPE = "SERVER_SHUTDOWN";
13
+ }
14
+ export type DeltaNetV01ServerErrorType = typeof DeltaNetV01ServerErrors.USER_ALREADY_AUTHENTICATED_ERROR_TYPE | typeof DeltaNetV01ServerErrors.USER_NOT_AUTHENTICATED_ERROR_TYPE | typeof DeltaNetV01ServerErrors.AUTHENTICATION_IN_PROGRESS_ERROR_TYPE | typeof DeltaNetV01ServerErrors.OBSERVER_CANNOT_SEND_STATE_UPDATES_ERROR_TYPE | typeof DeltaNetV01ServerErrors.UNSUPPORTED_WEBSOCKET_SUBPROTOCOL_ERROR_TYPE | typeof DeltaNetV01ServerErrors.USER_NETWORKING_UNKNOWN_ERROR_TYPE | typeof DeltaNetV01ServerErrors.USER_AUTHENTICATION_FAILED_ERROR_TYPE | typeof DeltaNetV01ServerErrors.USER_NETWORKING_CONNECTION_LIMIT_REACHED_ERROR_TYPE | typeof DeltaNetV01ServerErrors.USER_NETWORKING_SERVER_SHUTDOWN_ERROR_TYPE;
15
+ export type DeltaNetV01ErrorMessage = {
16
+ type: "error";
17
+ errorType: DeltaNetV01ServerErrorType | string;
18
+ message: string;
19
+ retryable: boolean;
20
+ };
21
+ export declare function encodeError(msg: DeltaNetV01ErrorMessage, writer?: BufferWriter): BufferWriter;
22
+ export declare function decodeError(buffer: BufferReader): DeltaNetV01ErrorMessage;
@@ -0,0 +1,15 @@
1
+ import { DeltaNetV01ErrorMessage } from "./error";
2
+ import { DeltaNetV01InitialCheckoutMessage } from "./initialCheckout";
3
+ import { DeltaNetV01PingMessage } from "./ping";
4
+ import { DeltaNetV01ServerCustomMessage } from "./serverCustom";
5
+ import { DeltaNetV01Tick } from "./tick";
6
+ import { DeltaNetV01UserIndexMessage } from "./userIndex";
7
+ import { DeltaNetV01WarningMessage } from "./warning";
8
+ export * from "./error";
9
+ export * from "./initialCheckout";
10
+ export * from "./ping";
11
+ export * from "./serverCustom";
12
+ export * from "./tick";
13
+ export * from "./userIndex";
14
+ export * from "./warning";
15
+ export type DeltaNetV01ServerMessage = DeltaNetV01InitialCheckoutMessage | DeltaNetV01ServerCustomMessage | DeltaNetV01UserIndexMessage | DeltaNetV01Tick | DeltaNetV01PingMessage | DeltaNetV01ErrorMessage | DeltaNetV01WarningMessage;
@@ -0,0 +1,56 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ import { DecodeServerMessageOptions } from "../../decodeServerMessages";
4
+ /**
5
+ * Represents a component in the initial checkout message.
6
+ * Contains both the initial values and the delta values that will be used for subsequent ticks.
7
+ */
8
+ export type DeltaNetV01InitialCheckoutComponent = {
9
+ /** Unique identifier for the component */
10
+ componentId: number;
11
+ /** The delta values from the tick this initial checkout is from which will be referred to in subsequent ticks */
12
+ deltas: BigInt64Array;
13
+ /** The initial values for all users */
14
+ values: BigInt64Array;
15
+ };
16
+ export type DeltaNetV01InitialCheckoutState = {
17
+ /** Unique identifier for the state */
18
+ stateId: number;
19
+ /** The initial values for all users */
20
+ values: Array<Uint8Array>;
21
+ };
22
+ /**
23
+ * Initial checkout message sent when a client first connects.
24
+ * Contains the complete initial state of the game, including all components and states.
25
+ */
26
+ export type DeltaNetV01InitialCheckoutMessage = {
27
+ /** Message type identifier */
28
+ type: "initialCheckout";
29
+ /** Current server time */
30
+ serverTime: number;
31
+ /** Number of user indices in the system */
32
+ indicesCount: number;
33
+ /** Array of components with their initial values and deltas */
34
+ components: Array<DeltaNetV01InitialCheckoutComponent>;
35
+ /** Array of state values, each containing [stateId, stateValue] */
36
+ states: Array<DeltaNetV01InitialCheckoutState>;
37
+ };
38
+ /**
39
+ * Encodes an initial checkout message into a binary buffer.
40
+ * @param msg - The message to encode
41
+ * @param writer - Optional BufferWriter instance to use (creates a new one if not provided)
42
+ * @returns The BufferWriter containing the encoded message
43
+ */
44
+ export declare function encodeInitialCheckout(msg: DeltaNetV01InitialCheckoutMessage, writer?: BufferWriter): BufferWriter;
45
+ export declare const lastInitialCheckoutDebugData: {
46
+ componentsByteLength: number;
47
+ statesByteLength: number;
48
+ };
49
+ /**
50
+ * Decodes an initial checkout message from a binary buffer.
51
+ * Assumes that the first byte (message type) has already been read.
52
+ * @param buffer - The BufferReader containing the message data
53
+ * @param opts - Optional options for decoding, such as ignoring data
54
+ * @returns The decoded initial checkout message
55
+ */
56
+ export declare function decodeInitialCheckout(buffer: BufferReader, opts?: DecodeServerMessageOptions): DeltaNetV01InitialCheckoutMessage;
@@ -0,0 +1,8 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01PingMessage = {
4
+ type: "ping";
5
+ ping: number;
6
+ };
7
+ export declare function encodePing(pingMessage: DeltaNetV01PingMessage, writer?: BufferWriter): BufferWriter;
8
+ export declare function decodePing(buffer: BufferReader): DeltaNetV01PingMessage;
@@ -0,0 +1,9 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01ServerCustomMessage = {
4
+ type: "serverCustom";
5
+ customType: number;
6
+ contents: string;
7
+ };
8
+ export declare function encodeServerCustom(msg: DeltaNetV01ServerCustomMessage, writer?: BufferWriter): BufferWriter;
9
+ export declare function decodeServerCustom(buffer: BufferReader): DeltaNetV01ServerCustomMessage;
@@ -0,0 +1,60 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ import { DecodeServerMessageOptions } from "../../decodeServerMessages";
4
+ /**
5
+ * Represents state updates in a tick message.
6
+ * States are not updated every tick, so they are specified as indices that have changed and their new values.
7
+ */
8
+ export type DeltaNetV01StateUpdates = {
9
+ /** Unique identifier for the state */
10
+ stateId: number;
11
+ /** Array of [index, value] pairs for updated states */
12
+ updatedStates: Array<[number, Uint8Array]>;
13
+ };
14
+ /**
15
+ * Represents component updates in a tick message.
16
+ * Uses second-order delta compression (deltas of deltas) for efficient updates.
17
+ */
18
+ export type DeltaNetV01ComponentTick = {
19
+ /** Unique identifier for the component */
20
+ componentId: number;
21
+ /** The second-order delta values (deltas of deltas) from the previous tick */
22
+ deltaDeltas: BigInt64Array;
23
+ };
24
+ /**
25
+ * Regular state update message sent at configurable intervals (typically 5-20Hz).
26
+ * Contains updates to components and states, as well as information about user indices.
27
+ */
28
+ export type DeltaNetV01Tick = {
29
+ /** Message type identifier */
30
+ type: "tick";
31
+ /** Current server time */
32
+ serverTime: number;
33
+ /** Indices of users that have been removed since the last tick */
34
+ removedIndices: Array<number>;
35
+ /** Current number of user indices in the system */
36
+ indicesCount: number;
37
+ /** Array of component updates using second-order delta compression */
38
+ componentDeltaDeltas: Array<DeltaNetV01ComponentTick>;
39
+ /** Array of state updates */
40
+ states: Array<DeltaNetV01StateUpdates>;
41
+ };
42
+ /**
43
+ * Encodes a tick message into a binary buffer.
44
+ * @param msg - The message to encode
45
+ * @param writer - Optional BufferWriter instance to use (creates a new one if not provided)
46
+ * @returns The BufferWriter containing the encoded message
47
+ */
48
+ export declare function encodeTick(msg: DeltaNetV01Tick, writer?: BufferWriter): BufferWriter;
49
+ export declare const lastTickDebugData: {
50
+ componentsByteLength: number;
51
+ statesByteLength: number;
52
+ };
53
+ /**
54
+ * Decodes a tick message from a binary buffer.
55
+ * Assumes that the first byte (message type) has already been read.
56
+ * @param buffer - The BufferReader containing the message data
57
+ * @param opts - Optional options for decoding, such as ignoring data
58
+ * @returns The decoded tick message
59
+ */
60
+ export declare function decodeTick(buffer: BufferReader, opts?: DecodeServerMessageOptions): DeltaNetV01Tick;
@@ -0,0 +1,8 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01UserIndexMessage = {
4
+ type: "userIndex";
5
+ index: number;
6
+ };
7
+ export declare function encodeUserIndex(msg: DeltaNetV01UserIndexMessage, writer?: BufferWriter): BufferWriter;
8
+ export declare function decodeUserIndex(buffer: BufferReader): DeltaNetV01UserIndexMessage;
@@ -0,0 +1,8 @@
1
+ import { BufferReader } from "../../../BufferReader";
2
+ import { BufferWriter } from "../../../BufferWriter";
3
+ export type DeltaNetV01WarningMessage = {
4
+ type: "warning";
5
+ message: string;
6
+ };
7
+ export declare function encodeWarning(msg: DeltaNetV01WarningMessage, writer?: BufferWriter): BufferWriter;
8
+ export declare function decodeWarning(buffer: BufferReader): DeltaNetV01WarningMessage;
@@ -0,0 +1,2 @@
1
+ export * from "./from-client";
2
+ export * from "./from-server";
@@ -0,0 +1,4 @@
1
+ export * from "./BufferReader";
2
+ export * from "./BufferWriter";
3
+ export * from "./DeflateCompressor";
4
+ export * from "./delta-net-v0.1";