@hazae41/cursor
Version:
Rust-like Cursor for TypeScript
139 lines (138 loc) • 5.75 kB
TypeScript
import type { Uint8Array } from "../../libs/lengthed/mod.ts";
export type CursorError = CursorReadError | CursorWriteError;
export type CursorReadError = CursorReadOverflowError | CursorReadUnknownError;
export type CursorReadOverflowError = CursorReadLengthOverflowError | CursorReadNullOverflowError;
export type CursorWriteError = CursorWriteLengthOverflowError | CursorWriteUnknownError;
export declare class CursorReadLengthOverflowError extends Error {
#private;
readonly cursorOffset: number;
readonly cursorLength: number;
readonly bytesLength: number;
readonly name: string;
constructor(cursorOffset: number, cursorLength: number, bytesLength: number);
static from(cursor: Cursor, bytesLength: number): CursorReadLengthOverflowError;
}
export declare class CursorWriteLengthOverflowError extends Error {
#private;
readonly cursorOffset: number;
readonly cursorLength: number;
readonly bytesLength: number;
readonly name: string;
constructor(cursorOffset: number, cursorLength: number, bytesLength: number);
static from(cursor: Cursor, bytesLength: number): CursorWriteLengthOverflowError;
}
export declare class CursorReadNullOverflowError extends Error {
#private;
readonly cursorOffset: number;
readonly cursorLength: number;
readonly name: string;
constructor(cursorOffset: number, cursorLength: number);
static from(cursor: Cursor): CursorReadNullOverflowError;
}
export declare class CursorReadUnknownError extends Error {
#private;
readonly name: string;
}
export declare class CursorWriteUnknownError extends Error {
#private;
readonly name: string;
}
export declare class Cursor<T extends ArrayBufferLike = ArrayBufferLike, N extends number = number> {
readonly bytes: Uint8Array<T, N>;
readonly data: DataView<T>;
offset: number;
/**
* A cursor for bytes
* @param inner
* @param offset
*/
constructor(bytes: Uint8Array<T, N>);
/**
* @returns total number of bytes
*/
get length(): N;
/**
* @returns number of remaining bytes
*/
get remaining(): number;
/**
* Get a subarray of the bytes before the current offset
* @returns subarray of the bytes before the current offset
*/
get before(): Uint8Array<T>;
/**
* Get a subarray of the bytes after the current offset
* @returns subarray of the bytes after the current offset
*/
get after(): Uint8Array<T>;
/**
* Get a subarray of the bytes
* @param length
* @returns subarray of the bytes
*/
getOrThrow<N extends number>(length: N): Uint8Array<T, N>;
/**
* Read a subarray of the bytes
* @param length
* @returns subarray of the bytes
*/
readOrThrow<N extends number>(length: N): Uint8Array<T, N>;
/**
* Set an array to the bytes
* @param array array
*/
setOrThrow(array: Uint8Array): void;
/**
* Write an array to the bytes
* @param array array
*/
writeOrThrow(array: Uint8Array): void;
getUint8OrThrow(): number;
readUint8OrThrow(): number;
setUint8OrThrow(x: number): void;
writeUint8OrThrow(x: number): void;
getInt8OrThrow(): number;
readInt8OrThrow(): number;
setInt8OrThrow(x: number): void;
writeInt8OrThrow(x: number): void;
getUint16OrThrow(littleEndian?: boolean): number;
readUint16OrThrow(littleEndian?: boolean): number;
setUint16OrThrow(x: number, littleEndian?: boolean): void;
writeUint16OrThrow(x: number, littleEndian?: boolean): void;
getInt16OrThrow(littleEndian?: boolean): number;
readInt16OrThrow(littleEndian?: boolean): number;
setInt16OrThrow(x: number, littleEndian?: boolean): void;
writeInt16OrThrow(x: number, littleEndian?: boolean): void;
getUint24OrThrow(littleEndian?: boolean): number;
readUint24OrThrow(littleEndian?: boolean): number;
setUint24OrThrow(x: number, littleEndian?: boolean): void;
writeUint24OrThrow(x: number, littleEndian?: boolean): void;
getUint32OrThrow(littleEndian?: boolean): number;
readUint32OrThrow(littleEndian?: boolean): number;
setUint32OrThrow(x: number, littleEndian?: boolean): void;
writeUint32OrThrow(x: number, littleEndian?: boolean): void;
getInt32OrThrow(littleEndian?: boolean): number;
readInt32OrThrow(littleEndian?: boolean): number;
setInt32OrThrow(x: number, littleEndian?: boolean): void;
writeInt32OrThrow(x: number, littleEndian?: boolean): void;
getBigUint64OrThrow(littleEndian?: boolean): bigint;
readBigUint64OrThrow(littleEndian?: boolean): bigint;
setBigUint64OrThrow(x: bigint, littleEndian?: boolean): void;
writeBigUint64OrThrow(x: bigint, littleEndian?: boolean): void;
getBigInt64OrThrow(littleEndian?: boolean): bigint;
readBigInt64OrThrow(littleEndian?: boolean): bigint;
setBigInt64OrThrow(x: bigint, littleEndian?: boolean): void;
writeBigInt64OrThrow(x: bigint, littleEndian?: boolean): void;
getFloat16OrThrow(littleEndian?: boolean): number;
readFloat16OrThrow(littleEndian?: boolean): number;
setFloat16OrThrow(x: number, littleEndian?: boolean): void;
writeFloat16OrThrow(x: number, littleEndian?: boolean): void;
getFloat32OrThrow(littleEndian?: boolean): number;
readFloat32OrThrow(littleEndian?: boolean): number;
setFloat32OrThrow(x: number, littleEndian?: boolean): void;
writeFloat32OrThrow(x: number, littleEndian?: boolean): void;
getFloat64OrThrow(littleEndian?: boolean): number;
readFloat64OrThrow(littleEndian?: boolean): number;
setFloat64OrThrow(x: number, littleEndian?: boolean): void;
writeFloat64OrThrow(x: number, littleEndian?: boolean): void;
}