@hytopia.com/server-protocol 1.4.13 → 1.4.15

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hytopia.com/server-protocol",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -86,18 +86,22 @@ export function createPacket<TId extends PacketId, TSchema>(
86
86
  packetDef: IPacketDefinition<TId, TSchema>,
87
87
  data: TSchema,
88
88
  worldTick?: WorldTick,
89
+ reusablePacket?: unknown[],
89
90
  ): IPacket<TId, TSchema> {
90
91
  if (!packetDef.validate(data)) {
91
92
  throw new Error(`Invalid payload for packet with id ${packetDef.id}. Error: ${Ajv.instance.errorsText(packetDef.validate.errors)}`);
92
93
  }
93
94
 
94
- const packet: IPacket<TId, TSchema> = [packetDef.id, data];
95
+ const packet = reusablePacket ?? [];
96
+
97
+ packet[0] = packetDef.id;
98
+ packet[1] = data;
95
99
 
96
100
  if (typeof worldTick === 'number') {
97
101
  packet.push(worldTick);
98
102
  }
99
103
 
100
- return packet;
104
+ return packet as IPacket<TId, TSchema>;
101
105
  }
102
106
 
103
107
  export function definePacket<TId extends PacketId, TSchema>(