use full byte for each bool
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
class KeyMap extends Serializable<KeyMap> {
|
||||
|
||||
static defaultFlag = 0x80;
|
||||
|
||||
// @assertUInt8
|
||||
id: number;
|
||||
|
||||
@@ -23,10 +21,8 @@ class KeyMap extends Serializable<KeyMap> {
|
||||
}
|
||||
|
||||
_fromBinary(buffer: UhkBuffer): KeyMap {
|
||||
let map = buffer.readUInt8();
|
||||
/* saves almost a byte but limits number of keymaps... */
|
||||
this.isDefault = (map & KeyMap.defaultFlag) !== 0;
|
||||
this.id = map & ~KeyMap.defaultFlag; // Clear isDefault bit.;
|
||||
this.id = buffer.readUInt8();
|
||||
this.isDefault = this.binToBool(buffer.readUInt8());
|
||||
this.abbreviation = buffer.readString();
|
||||
this.name = buffer.readString();
|
||||
this.layers = new Layers().fromBinary(buffer);
|
||||
@@ -44,7 +40,8 @@ class KeyMap extends Serializable<KeyMap> {
|
||||
}
|
||||
|
||||
_toBinary(buffer: UhkBuffer): void {
|
||||
buffer.writeUInt8(this.id | this.getDefaultFlag());
|
||||
buffer.writeUInt8(this.id);
|
||||
buffer.writeUInt8(this.boolToBin(this.isDefault));
|
||||
buffer.writeString(this.abbreviation);
|
||||
buffer.writeString(this.name);
|
||||
this.layers.toBinary(buffer);
|
||||
@@ -53,8 +50,4 @@ class KeyMap extends Serializable<KeyMap> {
|
||||
toString(): string {
|
||||
return `<KeyMap id="${this.id}" name="${this.name}">`;
|
||||
}
|
||||
|
||||
private getDefaultFlag() {
|
||||
return this.isDefault ? KeyMap.defaultFlag : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user