Skip to content

Commit

Permalink
Use the bigint type instead of Long for event ID hashes
Browse files Browse the repository at this point in the history
Long is a non-standard type used by bytebuffer package. The bigint will
be converted to Long in the RawBuffer class (bytebuffer wrapper), but
the node-simconnect users won't have to worry about it anymore.

This is a breaking change. Solves #107
  • Loading branch information
EvenAR committed Jul 13, 2024
1 parent ac45784 commit 83836ce
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
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 83836ce

Please sign in to comment.