implementation of UhkConfiguration
This commit is contained in:
@@ -1,53 +1,81 @@
|
||||
class UhkConfiguration extends Serializable<UhkConfiguration> {
|
||||
|
||||
signature: string;
|
||||
|
||||
// @assertUInt8
|
||||
id: number;
|
||||
dataModelVersion: number;
|
||||
|
||||
name: string;
|
||||
// @assertUInt32
|
||||
prologue: number;
|
||||
|
||||
abbreviation: string;
|
||||
// @assertUInt8
|
||||
hardwareId: number;
|
||||
|
||||
isDefault: boolean;
|
||||
// @assertUInt8
|
||||
brandId: number;
|
||||
|
||||
layers: Serializable<Layers>;
|
||||
moduleConfigurations: Serializable<ModuleConfigurations>;
|
||||
|
||||
keyMaps: Serializable<KeyMaps>;
|
||||
|
||||
macros: Serializable<Macros>;
|
||||
|
||||
// @assertUInt32
|
||||
epilogue: number;
|
||||
|
||||
_fromJsObject(jsObject: any): UhkConfiguration {
|
||||
this.id = jsObject.id;
|
||||
this.isDefault = jsObject.isDefault;
|
||||
this.abbreviation = jsObject.abbreviation;
|
||||
this.name = jsObject.name;
|
||||
this.layers = new Layers().fromJsObject(jsObject.layers);
|
||||
this.signature = jsObject.signature;
|
||||
this.dataModelVersion = jsObject.dataModelVersion;
|
||||
this.prologue = jsObject.prologue;
|
||||
this.hardwareId = jsObject.hardwareId;
|
||||
this.brandId = jsObject.brandId;
|
||||
this.moduleConfigurations = new ModuleConfigurations().fromJsObject(jsObject.moduleConfigurations);
|
||||
this.keyMaps = new KeyMaps().fromJsObject(jsObject.keyMaps);
|
||||
this.macros = new Macros().fromJsObject(jsObject.macros);
|
||||
this.epilogue = jsObject.epilogue;
|
||||
return this;
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): UhkConfiguration {
|
||||
this.id = buffer.readUInt8();
|
||||
this.isDefault = buffer.readBoolean();
|
||||
this.abbreviation = buffer.readString();
|
||||
this.name = buffer.readString();
|
||||
this.layers = new Layers().fromBinary(buffer);
|
||||
this.signature = buffer.readString();
|
||||
this.dataModelVersion = buffer.readUInt8();
|
||||
this.prologue = buffer.readUInt32();
|
||||
this.hardwareId = buffer.readUInt8();
|
||||
this.brandId = buffer.readUInt8();
|
||||
this.moduleConfigurations = new ModuleConfigurations().fromBinary(buffer);
|
||||
this.keyMaps = new KeyMaps().fromBinary(buffer);
|
||||
this.macros = new Macros().fromBinary(buffer);
|
||||
this.epilogue = buffer.readUInt32();
|
||||
return this;
|
||||
}
|
||||
|
||||
_toJsObject(): any {
|
||||
return {
|
||||
id: this.id,
|
||||
isDefault: this.isDefault,
|
||||
abbreviation: this.abbreviation,
|
||||
name: this.name,
|
||||
layers: this.layers.toJsObject()
|
||||
signature: this.signature,
|
||||
dataModelVersion: this.dataModelVersion,
|
||||
prologue: this.prologue,
|
||||
hardwareId: this.hardwareId,
|
||||
brandId: this.brandId,
|
||||
moduleConfigurations: this.moduleConfigurations.toJsObject(),
|
||||
keyMaps: this.keyMaps.toJsObject(),
|
||||
macros: this.macros.toJsObject(),
|
||||
epilogue: this.epilogue
|
||||
};
|
||||
}
|
||||
|
||||
_toBinary(buffer: UhkBuffer): void {
|
||||
buffer.writeUInt8(this.id);
|
||||
buffer.writeBoolean(this.isDefault);
|
||||
buffer.writeString(this.abbreviation);
|
||||
buffer.writeString(this.name);
|
||||
this.layers.toBinary(buffer);
|
||||
buffer.writeString(this.signature);
|
||||
buffer.writeUInt8(this.dataModelVersion);
|
||||
buffer.writeUInt32(this.prologue);
|
||||
buffer.writeUInt8(this.hardwareId);
|
||||
buffer.writeUInt8(this.brandId);
|
||||
this.moduleConfigurations.toBinary(buffer);
|
||||
this.keyMaps.toBinary(buffer);
|
||||
this.macros.toBinary(buffer);
|
||||
buffer.writeUInt32(this.epilogue);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return `<UhkConfiguration id="${this.id}" name="${this.name}">`;
|
||||
return `<UhkConfiguration signature="${this.signature}">`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ let fs = require('fs');
|
||||
|
||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||
|
||||
let config1Js = uhkConfig.moduleConfigurations;
|
||||
let config1Ts: Serializable<ModuleConfigurations> = new ModuleConfigurations().fromJsObject(config1Js);
|
||||
let config1Js = uhkConfig;
|
||||
let config1Ts: Serializable<UhkConfiguration> = new UhkConfiguration().fromJsObject(config1Js);
|
||||
let config1Buffer = new UhkBuffer();
|
||||
config1Ts.toBinary(config1Buffer);
|
||||
let config1BufferContent = config1Buffer.getBufferContent();
|
||||
@@ -19,7 +19,7 @@ fs.writeFileSync('uhk-config.bin', config1BufferContent);
|
||||
|
||||
config1Buffer.offset = 0;
|
||||
console.log();
|
||||
let config2Ts = new ModuleConfigurations().fromBinary(config1Buffer);
|
||||
let config2Ts = new UhkConfiguration().fromBinary(config1Buffer);
|
||||
console.log('\n');
|
||||
let config2Js = config2Ts.toJsObject();
|
||||
let config2Buffer = new UhkBuffer();
|
||||
|
||||
Reference in New Issue
Block a user