Files
start-os/sdk/base/lib/s9pk/merkleArchive/varint.ts
Aiden McClelland f2142f0bb3 add documentation for ai agents (#3115)
* add documentation for ai agents

* docs: consolidate CLAUDE.md and CONTRIBUTING.md, add style guidelines

- Refactor CLAUDE.md to reference CONTRIBUTING.md for build/test/format info
- Expand CONTRIBUTING.md with comprehensive build targets, env vars, and testing
- Add code style guidelines section with conventional commits
- Standardize SDK prettier config to use single quotes (matching web)
- Add project-level Claude Code settings to disable co-author attribution

* style(sdk): apply prettier with single quotes

Run prettier across sdk/base and sdk/package to apply the
standardized quote style (single quotes matching web).

* docs: add USER.md for per-developer TODO filtering

- Add agents/USER.md to .gitignore (contains user identifier)
- Document session startup flow in CLAUDE.md:
  - Create USER.md if missing, prompting for identifier
  - Filter TODOs by @username tags
  - Offer relevant TODOs on session start

* docs: add i18n documentation task to agent TODOs

* docs: document i18n ID patterns in core/

Add agents/i18n-patterns.md covering rust-i18n setup, translation file
format, t!() macro usage, key naming conventions, and locale selection.
Remove completed TODO item and add reference in CLAUDE.md.

* chore: clarify that all builds work on any OS with Docker
2026-02-06 00:10:16 +01:00

65 lines
1.2 KiB
TypeScript

import { asError } from '../../util'
const msb = 0x80
const dropMsb = 0x7f
const maxSize = Math.floor((8 * 8 + 7) / 7)
export class VarIntProcessor {
private buf: Uint8Array
private i: number
constructor() {
this.buf = new Uint8Array(maxSize)
this.i = 0
}
push(b: number) {
if (this.i >= maxSize) {
throw new Error('Unterminated varint')
}
this.buf[this.i] = b
this.i += 1
}
finished(): boolean {
return this.i > 0 && (this.buf[this.i - 1] & msb) === 0
}
decode(): number | null {
let result = 0
let shift = 0
let success = false
for (let i = 0; i < this.i; i++) {
const b = this.buf[i]
const msbDropped = b & dropMsb
result |= msbDropped << shift
shift += 7
if ((b & msb) == 0 || shift > 9 * 7) {
success = (b & msb) === 0
break
}
}
if (success) {
return result
} else {
console.error(asError(this.buf))
return null
}
}
}
export function serializeVarint(int: number): ArrayBuffer {
const buf = new Uint8Array(maxSize)
let n = int
let i = 0
while (n >= msb) {
buf[i] = msb | n
i += 1
n >>= 7
}
buf[i] = n
i += 1
return buf.slice(0, i).buffer
}