Initial Commit

This commit is contained in:
2026-01-15 21:52:12 +01:00
committed by erik
parent 3ed42cdeb6
commit 5a70f775f1
6702 changed files with 1389544 additions and 0 deletions

32
node_modules/loupedeck/parser.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import { Transform } from 'node:stream'
// Parser to split incoming serial data by a magic byte sequence
// followed by a length
export class MagicByteLengthParser extends Transform {
constructor({ magicByte, ...args }) {
super(args)
this.delimiter = magicByte
this.buffer = Buffer.alloc(0)
}
_transform(chunk, encoding, cb) {
let data = Buffer.concat([this.buffer, chunk])
let position
while ((position = data.indexOf(this.delimiter)) !== -1) {
// We need to at least be able to read the length byte
if (data.length < position + 2) break
const nextLength = data[position + 1]
// Make sure we have enough bytes to meet this length
const expectedEnd = position + nextLength + 2
if (data.length < expectedEnd) break
this.push(data.slice(position + 2, expectedEnd))
data = data.slice(expectedEnd)
}
this.buffer = data
cb()
}
_flush(cb) {
this.push(this.buffer)
this.buffer = Buffer.alloc(0)
cb()
}
}