Created
June 14, 2024 11:36
-
-
Save Stmol/e48175a1b12b3a2a7ce8354a0a928d05 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ValueType = number | |
const InvalidValue: ValueType = 1 << 0, | |
StringValue: ValueType = 1 << 1, | |
NumberValue: ValueType = 1 << 2, | |
NilValue: ValueType = 1 << 3, | |
BoolValue: ValueType = 1 << 4, | |
ArrayValue: ValueType = 1 << 5, | |
ObjectValue: ValueType = 1 << 6 | |
let hexDigits: Uint8Array | |
let valueTypes: ValueType[] | |
function init() { | |
hexDigits = new Uint8Array(256) | |
hexDigits.fill(255) | |
// blah blah | |
// .... | |
} | |
type Iterator = { | |
buf: Uint8Array | |
head: number | |
tail: number | |
depth: number | |
captureStartedAt?: number | |
captured?: number | |
Error?: Error | |
Attachment?: any | |
} | |
export function NewIterator(cfg: any): Iterator { | |
return { | |
buf: new Uint8Array(), | |
head: 0, | |
tail: 0, | |
depth: 0, | |
} | |
} | |
function skipWhitespacesWithoutLoadMore(iter: Iterator): boolean { | |
for (let i = iter.head; i < iter.tail; i++) { | |
let c = String(iter.buf[i]) | |
switch (c) { | |
case ' ': | |
case '\n': | |
case '\t': | |
case '\r': | |
continue | |
} | |
iter.head = i | |
return false | |
} | |
return true | |
} | |
export function ReportError(iter: Iterator, operation: string, msg: string): void { | |
if (iter.Error !== undefined) { | |
if (iter.Error instanceof Error) { // io.EOF type | |
return | |
} | |
} | |
let peekStart = iter.head - 10 | |
if (peekStart < 0) { | |
peekStart = 0 | |
} | |
// blah blah | |
iter.Error = new Error( | |
`${operation}: ${operation} error found in ${msg} byte of ...|${iter.head}|...` | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment