/// import { Encoding } from "./Encoding"; import { Endianness } from "./Endianness"; import { WalkableBufferOptions } from "./WalkableBufferOptions"; /** * > _🚶🛡️ A class for easily reading data from binary Buffers_ * * Create instance providing `WalkableBufferOptions`, with the `buffer` option as required. */ export declare class WalkableBuffer { readonly options: Readonly; private cursor; private readonly buffer; private endianness; private encoding; private signed; constructor(options: Readonly); /** Reads integer of `byteLength` bytes from current cursor position and advances cursor `byteLength` steps. */ get( /** The length in bytes to read */ byteLength: number, /** * The endianness of the read action. `LE` for LittleEndian, `BE` for BigEndian. * * > _If not provided, will use the default that was provided when creating the instance._ */ endianness?: Endianness, /** * If the integer should be parsed as signed or not. * * > _If not provided, will use the default that was provided when creating the instance._ */ signed?: boolean): number; /** Reads the next 8 bytes as a `bigint`. */ getBigInt( /** * The endianness of the read action. `LE` for LittleEndian, `BE` for BigEndian. * * > _If not provided, will use the default that was provided when creating the instance._ */ endianness?: Endianness, /** * If the integer should be parsed as signed or not. * * > _If not provided, will use the default that was provided when creating the instance._ */ signed?: boolean): bigint; /** Peeks integer of `byteLength` bytes from current cursor position plus `byteOffset`, without advancing cursor. */ peek( /** The length in bytes to read */ byteLength: number, /** * The offset from the current `cursor` to start reading from. Both positive for later in buffer, or negative * for looking back. * * > _Defaults to `0`, so peeks from current `cursor`_ */ byteOffset?: number, /** * The endianness of the read action. `LE` for LittleEndian, `BE` for BigEndian. * * > _If not provided, will use the default that was provided when creating the instance._ */ endianness?: Endianness, /** * If the integer should be parsed as signed or not. * * > _If not provided, will use the default that was provided when creating the instance._ */ signed?: boolean): number; /** * Reads 8 bytes as a `bigint`. Reads forward from from current cursor position plus `byteOffset`. * Does not advance cursor. */ peekBigInt( /** * The offset from the current `cursor` to start reading from. Both positive for later in buffer, or negative * for looking back. * * > _Defaults to `0`, so peeks from current `cursor`_ */ byteOffset?: number, /** * The endianness of the read action. `LE` for LittleEndian, `BE` for BigEndian. * * > _If not provided, will use the default that was provided when creating the instance._ */ endianness?: Endianness, /** * If the integer should be parsed as signed or not. * * > _If not provided, will use the default that was provided when creating the instance._ */ signed?: boolean): bigint; /** Reads strings of `byteLength` bytes from current cursor position and advances cursor `byteLength` steps. */ getString( /** The length in bytes to read */ byteLength: number, /** * The encoding to read strings with. * Valid string encodings are `ascii`, `utf8`, `utf16le`, `ucs2`(alias of `utf16le`), `base64`, `hex`. * * > _If not provided, will use the default that was provided when creating the instance._ */ encoding?: Encoding): string; /** Peek string of `byteLength` bytes from current cursor position plus `byteOffset` without advancing cursor. */ peekString( /** The length in bytes to read */ byteLength: number, /** * The offset from the current `cursor` to start reading from. Both positive for later in buffer, or negative * for looking back. * * > _Defaults to `0`, so peeks from current `cursor`_ */ byteOffset?: number, /** * The encoding to read strings with. * Valid string encodings are `ascii`, `utf8`, `utf16le`, `ucs2`(alias of `utf16le`), `base64`, `hex`. * * > _If not provided, will use the default that was provided when creating the instance._ */ encoding?: Encoding): string; /** * Reads a string with size-describer in front of it. Usually for names and such. * * This method is a shortcut for and works the same as: * * const sizeOfSize = LONG; * const endianness = wb.getEndianness(); * const encoding = wb.getEncoding(); * const length = wb.get(sizeOfSize, endianness, false); // Always reads the size as unsigned integer * const string = wb.getString(length, encoding); * * This method will also take the double bytelength into account for `utf16` and `ucs2`. */ getSizedString( /** * The length in bytes of the integer to use as length for the string. * * > _If not provided, defaults to LONG (4 bytes)._ */ sizeOfSize?: number, /** * The endianness of the integer to use as length for the string. * * > _If not provided, will use the default that was provided when creating the instance._ */ endianness?: Endianness, /** * The text encoding of the string that is read. * * Valid string encodings are `ascii`, `utf8`, `utf16le`, `ucs2`(alias of `utf16le`), `base64`, `hex`. * * If encoding is `utf16le` (or alias `ucs2`) the length of the read will be double the integer. * * > _If not provided, will use the default that was provided when creating the instance._ */ encoding?: Encoding): string; /** Gets a `Buffer` of size `byteLength`. If no `size` is specified, returns remaining buffer. */ getBuffer( /** * The length of the `Buffer` to extract. If omitted, returns `Buffer` between current cursor and end of buffer. * * Has to be `1>=` and not exceed the buffer. */ byteLength?: number): Buffer; /** Advances cursor without reading any data. */ skip(byteLength: number): number; /** Returns current cursor position */ getCurrentPos(): number; /** Moves cursor to byte-position `byteOffset` */ goTo(byteOffset: number): number; /** Returns the instance default endianness */ getEndianness(): Endianness; /** * Sets the instances default endianness. * * Either `BE` for big-endian or `LE` for little-endi an. * * @returns The newly set `endianness`. */ setEndianness( /** Either `BE` for big-endian or `LE` for little-endian. */ endianness: Endianness): Endianness; /** Gets the instance current default text encoding. */ getEncoding(): Encoding; /** * Sets the instance default text encoding. * * Valid text encodings are `ascii`, `utf8`, `utf16le`, `ucs2`(alias of `utf16le`), `base64`, `hex`. * * @returns The newly set `encoding`. */ setEncoding( /** * Valid text encodings are `ascii`, `utf8`, `utf16le`, `ucs2`(alias of `utf16le`), `base64`, `hex`. */ encoding: Encoding): Encoding; /** Get the instance current `signed`. If numbers that are read should be signed rather than unsigned. */ getSigned(): boolean; /** * Set the instance current `signed`. If numbers that are read should be signed rather than unsigned. * * @returns The newly set `signed` boolean. */ setSigned(signed: boolean): boolean; /** * @returns the buffer used internally _as is_. * * Note that this will not be `===` the buffer provided on creation, as a copy is made on creation. */ getSourceBuffer(): Buffer; /** @returns the size in bytes of the full buffer. */ size(): number; /** @returns the number of bytes from current cursor to the end of the buffer. */ sizeRemainingBuffer(): number; /** Wrapper for `Buffer.readIntLE()` and `Buffer.readIntBE()` that takes `endianness` and `signed` into account. */ private readInt; /** Wrapper to read `bigint` from `this.buffer` */ private readBigInt; private rangeCheck; }