Files
2025-11-30 08:35:03 +02:00

117 lines
4.4 KiB
TypeScript

import { Long } from "./long";
import { Offset, Table } from "./types";
import { Encoding } from "./encoding";
export declare class ByteBuffer {
private bytes_;
private position_;
/**
* Create a new ByteBuffer with a given array of bytes (`Uint8Array`)
*/
constructor(bytes_: Uint8Array);
/**
* Create and allocate a new ByteBuffer with a given size.
*/
static allocate(byte_size: number): ByteBuffer;
clear(): void;
/**
* Get the underlying `Uint8Array`.
*/
bytes(): Uint8Array;
/**
* Get the buffer's position.
*/
position(): number;
/**
* Set the buffer's position.
*/
setPosition(position: number): void;
/**
* Get the buffer's capacity.
*/
capacity(): number;
readInt8(offset: number): number;
readUint8(offset: number): number;
readInt16(offset: number): number;
readUint16(offset: number): number;
readInt32(offset: number): number;
readUint32(offset: number): number;
readInt64(offset: number): Long;
readUint64(offset: number): Long;
readFloat32(offset: number): number;
readFloat64(offset: number): number;
writeInt8(offset: number, value: number): void;
writeUint8(offset: number, value: number): void;
writeInt16(offset: number, value: number): void;
writeUint16(offset: number, value: number): void;
writeInt32(offset: number, value: number): void;
writeUint32(offset: number, value: number): void;
writeInt64(offset: number, value: Long): void;
writeUint64(offset: number, value: Long): void;
writeFloat32(offset: number, value: number): void;
writeFloat64(offset: number, value: number): void;
/**
* Return the file identifier. Behavior is undefined for FlatBuffers whose
* schema does not include a file_identifier (likely points at padding or the
* start of a the root vtable).
*/
getBufferIdentifier(): string;
/**
* Look up a field in the vtable, return an offset into the object, or 0 if the
* field is not present.
*/
__offset(bb_pos: number, vtable_offset: number): Offset;
/**
* Initialize any Table-derived type to point to the union at the given offset.
*/
__union(t: Table, offset: number): Table;
/**
* Create a JavaScript string from UTF-8 data stored inside the FlatBuffer.
* This allocates a new string and converts to wide chars upon each access.
*
* To avoid the conversion to UTF-16, pass Encoding.UTF8_BYTES as
* the "optionalEncoding" argument. This is useful for avoiding conversion to
* and from UTF-16 when the data will just be packaged back up in another
* FlatBuffer later on.
*
* @param offset
* @param opt_encoding Defaults to UTF16_STRING
*/
__string(offset: number, opt_encoding?: Encoding): string | Uint8Array;
/**
* Handle unions that can contain string as its member, if a Table-derived type then initialize it,
* if a string then return a new one
*
* WARNING: strings are immutable in JS so we can't change the string that the user gave us, this
* makes the behaviour of __union_with_string different compared to __union
*/
__union_with_string(o: Table | string, offset: number): Table | string;
/**
* Retrieve the relative offset stored at "offset"
*/
__indirect(offset: Offset): Offset;
/**
* Get the start of data of a vector whose offset is stored at "offset" in this object.
*/
__vector(offset: Offset): Offset;
/**
* Get the length of a vector whose offset is stored at "offset" in this object.
*/
__vector_len(offset: Offset): Offset;
__has_identifier(ident: string): boolean;
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(low: number, high: number): Long;
/**
* A helper function for generating list for obj api
*/
createScalarList(listAccessor: (i: number) => unknown, listLength: number): any[];
/**
* A helper function for generating list for obj api
* @param listAccessor function that accepts an index and return data at that index
* @param listLength listLength
* @param res result list
*/
createObjList(listAccessor: (i: number) => unknown, listLength: number): any[];
}