diff options
| author | TheMas3212 <mas3212@gmail.com> | 2023-09-23 12:21:43 +1000 |
|---|---|---|
| committer | TheMas3212 <mas3212@gmail.com> | 2023-09-23 12:21:43 +1000 |
| commit | f2aab487c22f4919d48896d33cd0f09ba0928395 (patch) | |
| tree | c0930fd74c887c59a009cc8bd36833c381ebed8a /src/packets/input.ts | |
| parent | bdf1756baa223c89587abaa239001222263b665f (diff) | |
| download | tasd-js-f2aab487c22f4919d48896d33cd0f09ba0928395.tar.gz tasd-js-f2aab487c22f4919d48896d33cd0f09ba0928395.zip | |
Add additional Packet Types
Diffstat (limited to 'src/packets/input.ts')
| -rw-r--r-- | src/packets/input.ts | 24 |
1 files changed, 24 insertions, 0 deletions
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 |
