f5976a2d74
* feat: moved tl-runtime to esm and native ArrayBuffers * feat: migration to esm * fix(core): web-related fixes * test: finally, some good fucking e2e * chore: fixed linters etc * ci: added e2e to ci * build(tl): fixed gen-code on node 20 * fix: codegen Uint8Array, not Buffer never `git reset --hard` kids * build: only do type-aware linting for `packages/*` * build: ignore no-unresolved in ci for e2e * fix: node 16 doesn't have subtle crypto apparently? * fix(tests): use Uint8Array for gods sake please can i just merge this already * ci: don't parallel tasks in ci because machines are utter garbage and it may just randomly break * ci: pass secrets to e2e tests * ci: separate cli command for ci apparently im retarded * fix: run codegen in e2e im actually retarded * ci: more fixes for e2e * ci: debugging stuff * ci: still debugging * ci: hopefully fix ci???
52 lines
1 KiB
TypeScript
52 lines
1 KiB
TypeScript
// tdlib's RLE only encodes consecutive \x00
|
|
|
|
export function telegramRleEncode(buf: Uint8Array): Uint8Array {
|
|
const len = buf.length
|
|
const ret: number[] = []
|
|
let count = 0
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
const cur = buf[i]
|
|
|
|
if (cur === 0) {
|
|
count += 1
|
|
} else {
|
|
if (count > 0) {
|
|
ret.push(0, count)
|
|
count = 0
|
|
}
|
|
|
|
ret.push(cur)
|
|
}
|
|
}
|
|
|
|
if (count > 0) {
|
|
ret.push(0, count)
|
|
}
|
|
|
|
return new Uint8Array(ret)
|
|
}
|
|
|
|
export function telegramRleDecode(buf: Uint8Array): Uint8Array {
|
|
const len = buf.length
|
|
const ret: number[] = []
|
|
let prev = -1
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
const cur = buf[i]
|
|
|
|
if (prev === 0) {
|
|
for (let j = 0; j < cur; j++) {
|
|
ret.push(prev)
|
|
}
|
|
prev = -1
|
|
} else {
|
|
if (prev !== -1) ret.push(prev)
|
|
prev = cur
|
|
}
|
|
}
|
|
|
|
if (prev !== -1) ret.push(prev)
|
|
|
|
return new Uint8Array(ret)
|
|
}
|