Skip to content

Commit

Permalink
Merge pull request #108 from EvenAR/replace-long-with-bigint
Browse files Browse the repository at this point in the history
Use the bigint type instead of Long for event ID hashes
  • Loading branch information
EvenAR authored Jul 14, 2024
2 parents ac45784 + 059f59e commit 881a37b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-simconnect",
"version": "3.6.3-alpha.0",
"version": "4.0.0",
"description": "A SimConnect client library for Node.JS.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
7 changes: 3 additions & 4 deletions samples/typescript/inputEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ open('My app', Protocol.KittyHawk)

let allInputEvents: {
inputEventName: string;
inputEventIdHash: string;
inputEventIdHash: bigint;
params?: string;
}[] = [];

handle.on('inputEventsList', recvEnumerateInputEvents => {
recvEnumerateInputEvents.inputEventDescriptors.forEach(e => {
allInputEvents.push({
inputEventName: e.name,
inputEventIdHash: e.inputEventIdHash.toString(),
inputEventIdHash: e.inputEventIdHash,
});
handle.enumerateInputEventParams(e.inputEventIdHash);
});
Expand All @@ -27,8 +27,7 @@ open('My app', Protocol.KittyHawk)
// Update the list with the received value
allInputEvents = allInputEvents.map(inputEvent => {
if (
inputEvent.inputEventIdHash ===
recvEnumerateInputEventParams.inputEventIdHash.toString()
inputEvent.inputEventIdHash === recvEnumerateInputEventParams.inputEventIdHash
) {
return { ...inputEvent, params: recvEnumerateInputEventParams.value };
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/RawBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class RawBuffer {
return this.buffer.readInt64().toNumber();
}

readUint64(): Long {
return this.buffer.readUint64();
readUint64(): bigint {
return BigInt(this.buffer.readUint64().toString(10));
}

/** @deprecated use readInt64() instead */
Expand All @@ -86,8 +86,10 @@ class RawBuffer {
this.buffer.writeUint64(value, offset);
}

writeUint64(value: Long, offset?: number) {
this.buffer.writeUint64(value, offset);
writeUint64(value: bigint, offset?: number) {
const buffer = Buffer.alloc(8);
buffer.writeBigUint64LE(value);
this.buffer.append(buffer, undefined, offset);
}

/** @deprecated use writeInt64() instead */
Expand Down
10 changes: 5 additions & 5 deletions src/SimConnectConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ class SimConnectConnection extends EventEmitter {
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
getInputEvent(dataRequestID: number, inputEventHashID: Long): number {
getInputEvent(dataRequestID: number, inputEventHashID: bigint): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

const packet = this._beginPacket(0x50).putInt32(dataRequestID).putUint64(inputEventHashID);
Expand All @@ -1607,7 +1607,7 @@ class SimConnectConnection extends EventEmitter {
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
setInputEvent(inputEventHashID: Long, value: number | string): number {
setInputEvent(inputEventHashID: bigint, value: number | string): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

const packet = this._beginPacket(0x51).putUint64(inputEventHashID);
Expand All @@ -1625,7 +1625,7 @@ class SimConnectConnection extends EventEmitter {
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
subscribeInputEvent(inputEventHashID: Long): number {
subscribeInputEvent(inputEventHashID: bigint): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

return this._buildAndSend(this._beginPacket(0x52).putUint64(inputEventHashID));
Expand All @@ -1635,7 +1635,7 @@ class SimConnectConnection extends EventEmitter {
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
unsubscribeInputEvent(inputEventHashID: Long): number {
unsubscribeInputEvent(inputEventHashID: bigint): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

return this._buildAndSend(this._beginPacket(0x53).putUint64(inputEventHashID));
Expand All @@ -1645,7 +1645,7 @@ class SimConnectConnection extends EventEmitter {
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
enumerateInputEventParams(inputEventHashID: Long): number {
enumerateInputEventParams(inputEventHashID: bigint): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

return this._buildAndSend(this._beginPacket(0x54).putUint64(inputEventHashID));
Expand Down
2 changes: 1 addition & 1 deletion src/SimConnectPacketBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SimConnectPacketBuilder {
return this;
}

putUint64(value: Long, offset?: number) {
putUint64(value: bigint, offset?: number) {
this.packetContent.writeUint64(value, offset);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/datastructures/InputEventDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RawBuffer } from '../RawBuffer';
export class InputEventDescriptor {
name: string;

inputEventIdHash: Long;
inputEventIdHash: bigint;

type: InputEventType;

Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvEnumerateInputEventParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RawBuffer } from '../RawBuffer';

export class RecvEnumerateInputEventParams {
inputEventIdHash: Long;
inputEventIdHash: bigint;

value: string;

Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvSubscribeInputEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RawBuffer } from '../RawBuffer';
import { InputEventType } from '../enums/InputEventType';

export class RecvSubscribeInputEvent {
inputEventIdHash: Long;
inputEventIdHash: bigint;

type: InputEventType;

Expand Down

0 comments on commit 881a37b

Please sign in to comment.