From f2aab487c22f4919d48896d33cd0f09ba0928395 Mon Sep 17 00:00:00 2001 From: TheMas3212 Date: Sat, 23 Sep 2023 12:21:43 +1000 Subject: Add additional Packet Types --- src/packets/input.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/packets/input.ts (limited to 'src/packets/input.ts') diff --git a/src/packets/input.ts b/src/packets/input.ts new file mode 100644 index 0000000..b084ebe --- /dev/null +++ b/src/packets/input.ts @@ -0,0 +1,24 @@ +import { PACKET_TYPES } from "../constants"; +import { TASDPacket, buildBuffer } from "./utils"; + +export class InputChunkPacket implements TASDPacket { + constructor(public port: number, public inputs: Uint8Array) {} + get key() { + return PACKET_TYPES.INPUT_CHUNK; + } + get size() { + return this.inputs.length + 1; + } + static fromBuffer(buffer: Uint8Array) { + return new InputChunkPacket(buffer[0], buffer.subarray(1)); + } + toBuffer(g_keylen: number): Uint8Array { + const payload = new Uint8Array(this.inputs.length + 1); + payload[0] = this.port; + payload.set(this.inputs, 1); + return buildBuffer(g_keylen, this.key, payload); + } + toString() { + return `InputChunk ${this.port}, ${this.size}`; + } +} \ No newline at end of file -- cgit v1.2.3