import * as VV from '@asmartbear/version-vectors'; import { POJO, Scalar } from "../augmented/common"; /** * Returns the byte length of an utf8 string */ export default class PackedBuffer { private buf; idx: number; private tokenList; private tokenMap; constructor(a?: Uint8Array); getBuffer(): Uint8Array; rewind(): void; /** * Returns the next byte that would be read, without actually reading it. */ ensureMoreSpace(additionalBytes: number): void; writeByte(x: number): void; readByte(): number; writeSmallPositiveInteger(x: number): void; readSmallPositiveInteger(): number; writeInteger(x: number): void; readInteger(): number; /** * Writes a byte array, optionally with dynamic length * * @param a the byte array to write * @param fixedLength if omitted or `undefined`, the length is written first, to be decoded dynamically, otherwise this number of bytes is written without encoding a length. */ writeByteArray(a: Uint8Array, fixedLength?: number): void; /** * Reads a byte array, optionally with dynamic length * * @param fixedLength if omitted or `undefined`, the length is read from the stream, and decoded dynamically, otherwise this number of bytes that should be read. */ readByteArray(fixedLength?: number): Uint8Array; writeString(s: string): void; readString(): string; writeJson(x: any): void; readJson(): POJO; /** * Writes an array, given a routine that will write the contents of each element. */ writeArray(a: T[], writeEl: (buf: PackedBuffer, el: T) => void): void; /** * Reads and returns an array, given a routine that will read the contents of each element. */ readArray(readEl: (buf: PackedBuffer) => T): T[]; writeVersionVector(v: VV.VV): void; readVersionVector(): VV.VV; /** * Writes a scalar value, using opcodes to occupy just one byte in common cases like * `null`, `boolean`, small numbers, and trivial strings. */ writeScalar(x: Scalar): void; readScalar(): Scalar; /** * Writes a string that we expect to repeat often; we save them once in a table rather than * repeating them in the output. For example, Replica IDs. */ writeToken(s: string): void; readToken(): string; }