mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-04-21 13:49:03 +00:00
fix: use proper phrase decompress algorithm
[deploy]
This commit is contained in:
@@ -28,11 +28,11 @@ describe("chords", function () {
|
||||
|
||||
describe("phrase", function () {
|
||||
it("should stringify", function () {
|
||||
expect(stringifyPhrase([0x01, 0x68, 0x72, 0xd4, 0x65])).toEqual("016872D465")
|
||||
expect(stringifyPhrase([0x20, 0x68, 0x72, 0xd4, 0x65, 0x1fff])).toEqual("206872D4651FFF")
|
||||
})
|
||||
|
||||
it("should parse", function () {
|
||||
expect(parsePhrase("016872D465")).toEqual([0x01, 0x68, 0x72, 0xd4, 0x65])
|
||||
expect(parsePhrase("206872D4651FFF")).toEqual([0x20, 0x68, 0x72, 0xd4, 0x65, 0x1fff])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import {compressActions, decompressActions} from "../serialization/actions"
|
||||
|
||||
export interface Chord {
|
||||
actions: number[]
|
||||
phrase: number[]
|
||||
}
|
||||
|
||||
export function parsePhrase(phrase: string): number[] {
|
||||
return Array.from({length: phrase.length / 2}).map((_, i) =>
|
||||
Number.parseInt(phrase.slice(i * 2, i * 2 + 2), 16),
|
||||
return decompressActions(
|
||||
Uint8Array.from({length: phrase.length / 2}).map((_, i) =>
|
||||
Number.parseInt(phrase.slice(i * 2, i * 2 + 2), 16),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function stringifyPhrase(phrase: number[]): string {
|
||||
return phrase
|
||||
return [...compressActions(phrase)]
|
||||
.map(it => it.toString(16).padStart(2, "0"))
|
||||
.join("")
|
||||
.toUpperCase()
|
||||
|
||||
Reference in New Issue
Block a user