Make the first byte of KeyAction items purely denote their type. Make the binary representation of KeyAction items variable-length.
This commit is contained in:
@@ -2,8 +2,6 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
||||
|
||||
static keyActionTypeString = 'keystroke';
|
||||
|
||||
modifierMask: number;
|
||||
|
||||
private _scancode: number;
|
||||
|
||||
get scancode(): number {
|
||||
@@ -18,14 +16,14 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
||||
}
|
||||
|
||||
fromJsObject(jsObject: any): KeystrokeAction {
|
||||
this.assertKeyActionType(jsObject, KeystrokeAction.keyActionTypeString, 'KeystrokeAction');
|
||||
this.scancode = jsObject.scancode;
|
||||
this.modifierMask = jsObject.modifierMask;
|
||||
return this;
|
||||
}
|
||||
|
||||
fromBinary(buffer: UhkBuffer): KeystrokeAction {
|
||||
this.readAndAssertKeyActionId(buffer, KeyActionId.KeystrokeAction, 'KeystrokeAction');
|
||||
this.scancode = buffer.readUInt8();
|
||||
this.modifierMask = buffer.readUInt8();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -33,12 +31,11 @@ class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction>
|
||||
return {
|
||||
keyActionType: KeystrokeAction.keyActionTypeString,
|
||||
scancode: this.scancode,
|
||||
modifierMask: this.modifierMask
|
||||
};
|
||||
}
|
||||
|
||||
toBinary(buffer: UhkBuffer) {
|
||||
buffer.writeUInt8(KeyActionId.KeystrokeAction);
|
||||
buffer.writeUInt8(this.scancode);
|
||||
buffer.writeUInt8(this.modifierMask);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user