Add UhkBuffer read methods and rename Uint to UInt in its other methods.
This commit is contained in:
@@ -20,7 +20,7 @@ class KeystrokeAction implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer) {
|
toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUint8(this.scancode);
|
buffer.writeUInt8(this.scancode);
|
||||||
buffer.writeUint8(this.modifierMask);
|
buffer.writeUInt8(this.modifierMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,39 +7,79 @@ class UhkBuffer {
|
|||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readInt8():number {
|
||||||
|
let value = this.buffer.readInt8(this.offset);
|
||||||
|
this.offset += 1;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
writeInt8(value:number):void {
|
writeInt8(value:number):void {
|
||||||
this.buffer.writeInt8(value, this.offset);
|
this.buffer.writeInt8(value, this.offset);
|
||||||
this.offset += 1;
|
this.offset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeUint8(value:number):void {
|
readUInt8():number {
|
||||||
|
let value = this.buffer.readUInt8(this.offset);
|
||||||
|
this.offset += 1;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeUInt8(value:number):void {
|
||||||
this.buffer.writeUInt8(value, this.offset);
|
this.buffer.writeUInt8(value, this.offset);
|
||||||
this.offset += 1;
|
this.offset += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readInt16():number {
|
||||||
|
let value = this.buffer.readInt16LE(this.offset);
|
||||||
|
this.offset += 2;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
writeInt16(value:number):void {
|
writeInt16(value:number):void {
|
||||||
this.buffer.writeInt16LE(value, this.offset);
|
this.buffer.writeInt16LE(value, this.offset);
|
||||||
this.offset += 2;
|
this.offset += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeUint16(value:number):void {
|
readUInt16():number {
|
||||||
|
let value = this.buffer.readUInt16LE(this.offset);
|
||||||
|
this.offset += 2;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeUInt16(value:number):void {
|
||||||
this.buffer.writeUInt16LE(value, this.offset);
|
this.buffer.writeUInt16LE(value, this.offset);
|
||||||
this.offset += 2;
|
this.offset += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readInt32():number {
|
||||||
|
let value = this.buffer.readInt32LE(this.offset);
|
||||||
|
this.offset += 4;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
writeInt32(value:number):void {
|
writeInt32(value:number):void {
|
||||||
this.buffer.writeInt32LE(value, this.offset);
|
this.buffer.writeInt32LE(value, this.offset);
|
||||||
this.offset += 4;
|
this.offset += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeUint32(value:number):void {
|
readUInt32():number {
|
||||||
|
let value = this.buffer.readUInt32LE(this.offset);
|
||||||
|
this.offset += 4;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeUInt32(value:number):void {
|
||||||
this.buffer.writeUInt32LE(value, this.offset);
|
this.buffer.writeUInt32LE(value, this.offset);
|
||||||
this.offset += 4;
|
this.offset += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readString(string:string):void {
|
||||||
|
// to be implemented
|
||||||
|
}
|
||||||
|
|
||||||
writeString(string:string):void {
|
writeString(string:string):void {
|
||||||
this.buffer.write(string, this.offset, string.length, 'ascii');
|
this.buffer.write(string, this.offset, string.length, 'ascii');
|
||||||
this.offset += string.length;
|
this.offset += string.length;
|
||||||
this.writeUint8(0);
|
this.writeUInt8(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ function serializeKeyActions(keyActions) {
|
|||||||
keyActions.forEach(function(keyAction) {
|
keyActions.forEach(function(keyAction) {
|
||||||
serializeKeyAction(keyAction);
|
serializeKeyAction(keyAction);
|
||||||
});
|
});
|
||||||
writer.writeUint8(ARRAY_LAST_ELEMENT_ID);
|
writer.writeUInt8(ARRAY_LAST_ELEMENT_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeKeyAction(keyAction) {
|
function serializeKeyAction(keyAction) {
|
||||||
@@ -87,17 +87,17 @@ function serializeKeyAction(keyAction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function serializeNoneAction() {
|
function serializeNoneAction() {
|
||||||
writer.writeUint8(KEY_ACTION_ID_NONE);
|
writer.writeUInt8(KEY_ACTION_ID_NONE);
|
||||||
writer.writeUint8(NONE_ACTION_PADDING);
|
writer.writeUInt8(NONE_ACTION_PADDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeKeystrokeAction(keystrokeAction) {
|
function serializeKeystrokeAction(keystrokeAction) {
|
||||||
writer.writeUint8(keystrokeAction.scancode);
|
writer.writeUInt8(keystrokeAction.scancode);
|
||||||
writer.writeUint8(keystrokeAction.modifiers);
|
writer.writeUInt8(keystrokeAction.modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeDualRoleKeyAction(dualRoleKeyAction) {
|
function serializeDualRoleKeyAction(dualRoleKeyAction) {
|
||||||
writer.writeUint8({
|
writer.writeUInt8({
|
||||||
mod : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD,
|
mod : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD,
|
||||||
fn : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN,
|
fn : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN,
|
||||||
mouse : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE,
|
mouse : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE,
|
||||||
@@ -110,12 +110,12 @@ function serializeDualRoleKeyAction(dualRoleKeyAction) {
|
|||||||
rightAlt : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT,
|
rightAlt : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT,
|
||||||
rightSuper : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER
|
rightSuper : KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER
|
||||||
}[dualRoleKeyAction.longPressAction]);
|
}[dualRoleKeyAction.longPressAction]);
|
||||||
writer.writeUint8(dualRoleKeyAction.scancode);
|
writer.writeUInt8(dualRoleKeyAction.scancode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeMouseAction(mouseAction) {
|
function serializeMouseAction(mouseAction) {
|
||||||
writer.writeUint8(KEY_ACTION_ID_MOUSE);
|
writer.writeUInt8(KEY_ACTION_ID_MOUSE);
|
||||||
writer.writeUint8({
|
writer.writeUInt8({
|
||||||
leftClick : MOUSE_ACTION_ID_LEFT_CLICK,
|
leftClick : MOUSE_ACTION_ID_LEFT_CLICK,
|
||||||
middleClick: MOUSE_ACTION_ID_MIDDLE_CLICK,
|
middleClick: MOUSE_ACTION_ID_MIDDLE_CLICK,
|
||||||
rightClick : MOUSE_ACTION_ID_RIGHT_CLICK,
|
rightClick : MOUSE_ACTION_ID_RIGHT_CLICK,
|
||||||
@@ -133,18 +133,18 @@ function serializeMouseAction(mouseAction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function serializeMacroAction(macroAction) {
|
function serializeMacroAction(macroAction) {
|
||||||
writer.writeUint8(KEY_ACTION_ID_PLAY_MACRO);
|
writer.writeUInt8(KEY_ACTION_ID_PLAY_MACRO);
|
||||||
writer.writeUint8(macroAction.macroId);
|
writer.writeUInt8(macroAction.macroId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeSwitchKeymapAction(switchKeymapAction) {
|
function serializeSwitchKeymapAction(switchKeymapAction) {
|
||||||
writer.writeUint8(KEY_ACTION_ID_SWITCH_KEYMAP);
|
writer.writeUInt8(KEY_ACTION_ID_SWITCH_KEYMAP);
|
||||||
writer.writeUint8(switchKeymapAction.keymapId);
|
writer.writeUInt8(switchKeymapAction.keymapId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeSwitchLayerAction(switchLayerAction) {
|
function serializeSwitchLayerAction(switchLayerAction) {
|
||||||
writer.writeUint8(KEY_ACTION_ID_SWITCH_LAYER);
|
writer.writeUInt8(KEY_ACTION_ID_SWITCH_LAYER);
|
||||||
writer.writeUint8({
|
writer.writeUInt8({
|
||||||
mod : SWITCH_LAYER_MOD,
|
mod : SWITCH_LAYER_MOD,
|
||||||
fn : SWITCH_LAYER_FN,
|
fn : SWITCH_LAYER_FN,
|
||||||
mouse: SWITCH_LAYER_MOD
|
mouse: SWITCH_LAYER_MOD
|
||||||
|
|||||||
Reference in New Issue
Block a user