Loosely port the serializer to TypeScript.
This commit is contained in:
2
model/.gitignore
vendored
2
model/.gitignore
vendored
@@ -1 +1,3 @@
|
||||
typings
|
||||
uhk-config.bin
|
||||
serializeConfig.js
|
||||
|
||||
8
model/.vscode/tasks.json
vendored
Normal file
8
model/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "tsc",
|
||||
"isShellCommand": true,
|
||||
"showOutput": "silent",
|
||||
"args": [],
|
||||
"problemMatcher": "$tsc"
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
var BufferWriter = function(bufferParam) {
|
||||
var offset = 0;
|
||||
self = {};
|
||||
var buffer = bufferParam;
|
||||
|
||||
self.int8 = function(value) {
|
||||
buffer.writeInt8(value, offset);
|
||||
offset += 1;
|
||||
};
|
||||
|
||||
self.uint8 = function(value) {
|
||||
buffer.writeUInt8(value, offset);
|
||||
offset += 1;
|
||||
};
|
||||
|
||||
self.int16 = function(value) {
|
||||
buffer.writeInt16LE(value, offset);
|
||||
offset += 2;
|
||||
};
|
||||
|
||||
self.uint16 = function(value) {
|
||||
buffer.writeUInt16LE(value, offset);
|
||||
offset += 2;
|
||||
};
|
||||
|
||||
self.int32 = function(value) {
|
||||
buffer.writeInt32LE(value, offset);
|
||||
offset += 4;
|
||||
};
|
||||
|
||||
self.uint32 = function(value) {
|
||||
buffer.writeUInt32LE(value, offset);
|
||||
offset += 4;
|
||||
};
|
||||
|
||||
self.string = function(string) {
|
||||
buffer.write(string, offset, string.length, 'ascii');
|
||||
offset += string.length;
|
||||
self.uint8(0);
|
||||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
module.exports = BufferWriter;
|
||||
45
model/UhkBuffer.ts
Normal file
45
model/UhkBuffer.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
class UhkBuffer {
|
||||
buffer: Buffer;
|
||||
offset: number;
|
||||
|
||||
constructor(buffer) {
|
||||
this.offset = 0;
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
int8(value) {
|
||||
this.buffer.writeInt8(value, this.offset);
|
||||
this.offset += 1;
|
||||
}
|
||||
|
||||
uint8(value) {
|
||||
this.buffer.writeUInt8(value, this.offset);
|
||||
this.offset += 1;
|
||||
}
|
||||
|
||||
int16(value) {
|
||||
this.buffer.writeInt16LE(value, this.offset);
|
||||
this.offset += 2;
|
||||
}
|
||||
|
||||
uint16(value) {
|
||||
this.buffer.writeUInt16LE(value, this.offset);
|
||||
this.offset += 2;
|
||||
}
|
||||
|
||||
int32(value) {
|
||||
this.buffer.writeInt32LE(value, this.offset);
|
||||
this.offset += 4;
|
||||
}
|
||||
|
||||
uint32(value) {
|
||||
this.buffer.writeUInt32LE(value, this.offset);
|
||||
this.offset += 4;
|
||||
}
|
||||
|
||||
string(string) {
|
||||
this.buffer.write(string, this.offset, string.length, 'ascii');
|
||||
this.offset += string.length;
|
||||
this.uint8(0);
|
||||
}
|
||||
}
|
||||
7
model/serializeConfig.js → model/serializeConfig.ts
Executable file → Normal file
7
model/serializeConfig.js → model/serializeConfig.ts
Executable file → Normal file
@@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var BufferWriter = require('./BufferWriter');
|
||||
|
||||
var buffer = new Buffer(1000);
|
||||
buffer.fill(0);
|
||||
var writer = BufferWriter(buffer);
|
||||
var writer = new UhkBuffer(buffer);
|
||||
|
||||
var uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||
var keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
||||
@@ -87,7 +84,7 @@ function serializeKeyAction(keyAction) {
|
||||
}
|
||||
}
|
||||
|
||||
function serializeNoneAction(keystrokeAction) {
|
||||
function serializeNoneAction() {
|
||||
writer.uint8(KEY_ACTION_ID_NONE);
|
||||
writer.uint8(NONE_ACTION_PADDING);
|
||||
}
|
||||
10
model/tsconfig.json
Normal file
10
model/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"out": "serializeConfig.js"
|
||||
},
|
||||
"files": [
|
||||
"typings/main.d.ts",
|
||||
"UhkBuffer.ts",
|
||||
"serializeConfig.ts"
|
||||
]
|
||||
}
|
||||
5
model/typings.json
Normal file
5
model/typings.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"node": "registry:dt/node#4.0.0+20160319033040"
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
"handlebars": "^4.0.5",
|
||||
"jquery": "^2.2.2",
|
||||
"select2": "^4.0.2",
|
||||
"sortablejs": "^1.4.2"
|
||||
"sortablejs": "^1.4.2",
|
||||
"typescript": "^1.8.9"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user