@types/bytebuffer

  • Version 5.0.49
  • Published
  • 23.4 kB
  • 2 dependencies
  • MIT license

Install

npm i @types/bytebuffer
yarn add @types/bytebuffer
pnpm add @types/bytebuffer

Overview

TypeScript definitions for bytebuffer

Index

Classes

class ByteBuffer

class ByteBuffer {}

    constructor

    constructor(capacity?: number, littleEndian?: boolean, noAssert?: boolean);
    • Constructs a new ByteBuffer.

    property BIG_ENDIAN

    static BIG_ENDIAN: boolean;
    • Big endian constant that can be used instead of its boolean value. Evaluates to false.

    property buffer

    buffer: Buffer;
    • Backing buffer.

    property DEFAULT_CAPACITY

    static DEFAULT_CAPACITY: number;
    • Default initial capacity of 16.

    property DEFAULT_ENDIAN

    static DEFAULT_ENDIAN: boolean;
    • Default endianness of false for big endian.

    property DEFAULT_NOASSERT

    static DEFAULT_NOASSERT: boolean;
    • Default no assertions flag of false.

    property limit

    limit: number;
    • Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation.

    property LITTLE_ENDIAN

    static LITTLE_ENDIAN: boolean;
    • Little endian constant that can be used instead of its boolean value. Evaluates to true.

    property littleEndian

    littleEndian: boolean;
    • Whether to use little endian byte order, defaults to false for big endian.

    property markedOffset

    markedOffset: number;
    • Marked offset.

    property MAX_VARINT32_BYTES

    static MAX_VARINT32_BYTES: number;
    • Maximum number of bytes required to store a 32bit base 128 variable-length integer.

    property MAX_VARINT64_BYTES

    static MAX_VARINT64_BYTES: number;
    • Maximum number of bytes required to store a 64bit base 128 variable-length integer.

    property METRICS_BYTES

    static METRICS_BYTES: number;
    • Metrics representing number of bytes.Evaluates to 2.

    property METRICS_CHARS

    static METRICS_CHARS: number;
    • Metrics representing number of UTF8 characters.Evaluates to 1.

    property noAssert

    noAssert: boolean;
    • Whether to skip assertions of offsets and values, defaults to false.

    property offset

    offset: number;
    • Absolute read/write offset.

    property VERSION

    static VERSION: string;
    • ByteBuffer version.

    property view

    view: DataView;
    • Data view to manipulate the backing buffer. Becomes null if the backing buffer has a capacity of 0.

    method allocate

    static allocate: (
    capacity?: number,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Allocates a new ByteBuffer backed by a buffer of the specified capacity.

    method append

    append: (
    source: ByteBuffer | Buffer | ArrayBuffer | Uint8Array | string,
    encoding?: string | number,
    offset?: number
    ) => this;
    • Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended data's length.

    method appendTo

    appendTo: (target: ByteBuffer, offset?: number) => this;
    • Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents behind the specified offset up to the length of this ByteBuffer's data.

    method assert

    assert: (assert: boolean) => this;
    • Enables or disables assertions of argument types and offsets. Assertions are enabled by default but you can opt to disable them if your code already makes sure that everything is valid.

    method atob

    static atob: (b64: string) => string;
    • Decodes a base64 encoded string to binary like window.atob does.

    method BE

    BE: (bigEndian?: boolean) => this;
    • Switches (to) big endian byte order.

    method btoa

    static btoa: (str: string) => string;
    • Encodes a binary string to base64 like window.btoa does.

    method calculateString

    static calculateString: (str: string) => number;
    • Calculates the number of UTF8 bytes of a string. This is an alias of ByteBuffer#calculateUTF8Bytes.

    method calculateUTF8Bytes

    static calculateUTF8Bytes: (str: string) => number;
    • Calculates the number of UTF8 bytes of a string.

    method calculateUTF8Chars

    static calculateUTF8Chars: (str: string) => number;
    • Calculates the number of UTF8 characters of a string.JavaScript itself uses UTF- 16, so that a string's length property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF.

    method calculateVarint32

    static calculateVarint32: (value: number) => number;
    • Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer.

    method calculateVarint64

    static calculateVarint64: (value: number | Long) => number;
    • Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer.

    method capacity

    capacity: () => number;
    • Gets the capacity of this ByteBuffer's backing buffer.

    method clear

    clear: () => this;
    • Clears this ByteBuffer's offsets by setting ByteBuffer#offset to 0 and ByteBuffer#limit to the backing buffer's capacity. Discards ByteBuffer#markedOffset.

    method clone

    clone: (copy?: boolean) => ByteBuffer;
    • Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for ByteBuffer#offset, ByteBuffer#markedOffset and ByteBuffer#limit.

    method compact

    compact: (begin?: number, end?: number) => this;
    • Compacts this ByteBuffer to be backed by a ByteBuffer#buffer of its contents' length. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will set offset = 0 and limit = capacity and adapt ByteBuffer#markedOffset to the same relative position if set.

    method concat

    static concat: (
    buffers: Array<ByteBuffer | Buffer | ArrayBuffer | Uint8Array | string>,
    encoding?: string | boolean,
    litteEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Concatenates multiple ByteBuffers into one.

    method copy

    copy: (begin?: number, end?: number) => ByteBuffer;
    • Creates a copy of this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.

    method copyTo

    copyTo: (
    target: ByteBuffer,
    targetOffset?: number,
    sourceOffset?: number,
    sourceLimit?: number
    ) => this;
    • Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.

    method ensureCapacity

    ensureCapacity: (capacity: number) => this;
    • Makes sure that this ByteBuffer is backed by a ByteBuffer#buffer of at least the specified capacity. If the current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity, the required capacity will be used instead.

    method fill

    fill: (value: number | string, begin?: number, end?: number) => this;
    • Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.

    method flip

    flip: () => this;
    • Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets limit = offset and offset = 0. Make sure always to flip a ByteBuffer when all relative read or write operations are complete.

    method fromBase64

    static fromBase64: (
    str: string,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Decodes a base64 encoded string to a ByteBuffer.

    method fromBinary

    static fromBinary: (
    str: string,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.

    method fromDebug

    static fromDebug: (
    str: string,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Decodes a hex encoded string with marked offsets to a ByteBuffer.

    method fromHex

    static fromHex: (
    str: string,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Decodes a hex encoded string to a ByteBuffer.

    method fromUTF8

    static fromUTF8: (
    str: string,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Decodes an UTF8 encoded string to a ByteBuffer.

    method isByteBuffer

    static isByteBuffer: (bb: any) => boolean;
    • Gets the backing buffer type.

    method LE

    LE: (bigEndian?: boolean) => this;
    • Switches (to) little endian byte order.

    method mark

    mark: (offset?: number) => this;
    • Marks an offset on this ByteBuffer to be used later.

    method order

    order: (littleEndian: boolean) => this;
    • Sets the byte order.

    method prepend

    prepend: (
    source: ByteBuffer | string | ArrayBuffer | Buffer,
    encoding?: string | number,
    offset?: number
    ) => this;
    • Prepends some data to this ByteBuffer. This will overwrite any contents before the specified offset up to the prepended data's length. If there is not enough space available before the specified offset, the backing buffer will be resized and its contents moved accordingly.

    method prependTo

    prependTo: (target: ByteBuffer, offset?: number) => this;
    • Prepends this ByteBuffer to another ByteBuffer. This will overwrite any contents before the specified offset up to the prepended data's length. If there is not enough space available before the specified offset, the backing buffer will be resized and its contents moved accordingly.

    method printDebug

    printDebug: (out?: (text: string) => void) => void;
    • Prints debug information about this ByteBuffer's contents.

    method readByte

    readByte: (offset?: number) => number;
    • Reads an 8bit signed integer. This is an alias of ByteBuffer#readInt8.

    method readBytes

    readBytes: (length: number, offset?: number) => ByteBuffer;
    • Reads the specified number of bytes

    method readCString

    readCString: {
    (): string;
    (offset: number): { string: string; length: number };
    };
    • Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters itself.

    method readDouble

    readDouble: (offset?: number) => number;
    • Reads a 64bit float. This is an alias of ByteBuffer#readFloat64.

    method readFloat

    readFloat: (offset?: number) => number;
    • Reads a 32bit float. This is an alias of ByteBuffer#readFloat32.

    method readFloat32

    readFloat32: (offset?: number) => number;
    • Reads a 32bit float.

    method readFloat64

    readFloat64: (offset?: number) => number;
    • Reads a 64bit float.

    method readInt

    readInt: (offset?: number) => number;
    • Reads a 32bit signed integer.This is an alias of ByteBuffer#readInt32.

    method readInt16

    readInt16: (offset?: number) => number;
    • Reads a 16bit signed integer.

    method readInt32

    readInt32: (offset?: number) => number;
    • Reads a 32bit signed integer.

    method readInt64

    readInt64: (offset?: number) => Long;
    • Reads a 64bit signed integer.

    method readInt8

    readInt8: (offset?: number) => number;
    • Reads an 8bit signed integer.

    method readIString

    readIString: {
    (): string;
    (offset: number): { string: string; length: number };
    };
    • Reads a length as uint32 prefixed UTF8 encoded string.

    method readLong

    readLong: (offset?: number) => Long;
    • Reads a 64bit signed integer. This is an alias of ByteBuffer#readInt64.

    method readShort

    readShort: (offset?: number) => number;
    • Reads a 16bit signed integer. This is an alias of ByteBuffer#readInt16.

    method readString

    readString: {
    (length: number, metrics?: number): string;
    (length: number, metrics: number, offset: number): {
    string: string;
    length: number;
    };
    };
    • Reads an UTF8 encoded string. This is an alias of ByteBuffer#readUTF8String.

    method readUint16

    readUint16: (offset?: number) => number;
    • Reads a 16bit unsigned integer.

    method readUint32

    readUint32: (offset?: number) => number;
    • Reads a 32bit unsigned integer.

    method readUint64

    readUint64: (offset?: number) => Long;
    • Reads a 64bit unsigned integer.

    method readUint8

    readUint8: (offset?: number) => number;
    • Reads an 8bit unsigned integer.

    method readUTF8String

    readUTF8String: {
    (chars: number, metrics?: number): string;
    (chars: number, metrics: number, offset: number): {
    string: string;
    length: number;
    };
    };
    • Reads an UTF8 encoded string.

    method readVarint32

    readVarint32: {
    (): number;
    (offset: number): { value: number; length: number };
    };
    • Reads a 32bit base 128 variable-length integer.

    method readVarint32ZigZag

    readVarint32ZigZag: {
    (): number;
    (offset: number): { value: number; length: number };
    };
    • Reads a zig-zag encoded 32bit base 128 variable-length integer.

    method readVarint64

    readVarint64: { (): Long; (offset: number): { value: Long; length: number } };
    • Reads a 64bit base 128 variable-length integer. Requires Long.js.

    method readVarint64ZigZag

    readVarint64ZigZag: {
    (): Long;
    (offset: number): { value: Long; length: number };
    };
    • Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js.

    method readVString

    readVString: {
    (): string;
    (offset: number): { string: string; length: number };
    };
    • Reads a length as varint32 prefixed UTF8 encoded string.

    method remaining

    remaining: () => number;
    • Gets the number of remaining readable bytes. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit, so this returns limit - offset.

    method reset

    reset: () => this;
    • Resets this ByteBuffer's ByteBuffer#offset. If an offset has been marked through ByteBuffer#mark before, offset will be set to ByteBuffer#markedOffset, which will then be discarded. If no offset has been marked, sets offset = 0.

    method resize

    resize: (capacity: number) => this;
    • Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that large or larger.

    method reverse

    reverse: (begin?: number, end?: number) => this;
    • Reverses this ByteBuffer's contents

    method skip

    skip: (length: number) => this;
    • Skips the next length bytes. This will just advance

    method slice

    slice: (begin?: number, end?: number) => ByteBuffer;
    • Slices this ByteBuffer by creating a cloned instance with offset = begin and limit = end.

    method toArrayBuffer

    toArrayBuffer: (forceCopy?: boolean) => ArrayBuffer;
    • Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this ByteBuffer if offset > limit but the actual offsets remain untouched. This is an alias of ByteBuffer#toBuffer.

    method toBase64

    toBase64: (begin?: number, end?: number) => string;
    • Encodes this ByteBuffer's contents to a base64 encoded string.

    method toBinary

    toBinary: (begin?: number, end?: number) => string;
    • Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes.

    method toBuffer

    toBuffer: (forceCopy?: boolean) => Buffer;
    • Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this ByteBuffer if offset > limit but the actual offsets remain untouched.

    method toDebug

    toDebug: (columns?: boolean) => string | string[];
    • Encodes this ByteBuffer to a hex encoded string with marked offsets. Offset symbols are: < : offset, ' : markedOffset, > : limit, | : offset and limit, [ : offset and markedOffset, ] : markedOffset and limit, ! : offset, markedOffset and limit

    method toHex

    toHex: (begin?: number, end?: number) => string;
    • Encodes this ByteBuffer's contents to a hex encoded string.

    method toString

    toString: (encoding?: string) => string;
    • Converts the ByteBuffer's contents to a string.

    method toUTF8

    toUTF8: () => string;
    • Encodes this ByteBuffer's contents between ByteBuffer#offset and ByteBuffer#limit to an UTF8 encoded string.

    method wrap

    static wrap: (
    buffer: ByteBuffer | Buffer | ArrayBuffer | Uint8Array | string,
    enc?: string | boolean,
    littleEndian?: boolean,
    noAssert?: boolean
    ) => ByteBuffer;
    • Wraps a buffer or a string. Sets the allocated ByteBuffer's ByteBuffer#offset to 0 and its ByteBuffer#limit to the length of the wrapped data.

      Parameter buffer

      Anything that can be wrapped

      Parameter encoding

      String encoding if buffer is a string ("base64", "hex", "binary", defaults to "utf8")

      Parameter littleEndian

      Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN.

      Parameter noAssert

      Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT.

    method writeByte

    writeByte: (value: number, offset?: number) => this;
    • Writes an 8bit signed integer. This is an alias of ByteBuffer#writeInt8.

    method writeBytes

    writeBytes: (
    source: ByteBuffer | Buffer | ArrayBuffer | Uint8Array | string,
    encoding?: string | number,
    offset?: number
    ) => this;
    • Writes an array of bytes. This is an alias for append

    method writeCString

    writeCString: (str: string, offset?: number) => this;
    • Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL characters itself.

    method writeDouble

    writeDouble: (value: number, offset?: number) => this;
    • Writes a 64bit float. This is an alias of ByteBuffer#writeFloat64.

    method writeFloat

    writeFloat: (value: number, offset?: number) => this;
    • Writes a 32bit float. This is an alias of ByteBuffer#writeFloat32.

    method writeFloat32

    writeFloat32: (value: number, offset?: number) => this;
    • Writes a 32bit float.

    method writeFloat64

    writeFloat64: (value: number, offset?: number) => this;
    • Writes a 64bit float.

    method writeInt

    writeInt: (value: number, offset?: number) => this;
    • Writes a 32bit signed integer. This is an alias of ByteBuffer#writeInt32.

    method writeInt16

    writeInt16: (value: number, offset?: number) => this;
    • Writes a 16bit signed integer.

    method writeInt32

    writeInt32: (value: number, offset?: number) => this;
    • Writes a 32bit signed integer.

    method writeInt64

    writeInt64: (value: number | Long, offset?: number) => this;
    • Writes a 64bit signed integer.

    method writeInt8

    writeInt8: (value: number, offset?: number) => this;
    • Writes an 8bit signed integer.

    method writeIString

    writeIString: (str: string, offset?: number) => this;
    • Writes a length as uint32 prefixed UTF8 encoded string.

    method writeLong

    writeLong: (value: number | Long, offset?: number) => this;
    • Write a 64bit signed integer. This is an alias of ByteBuffer#writeInt64.

    method writeShort

    writeShort: (value: number, offset?: number) => this;
    • Writes a 16bit signed integer. This is an alias of ByteBuffer#writeInt16.

    method writeString

    writeString: { (str: string): this; (str: string, offset: number): number };
    • Writes an UTF8 encoded string. This is an alias of ByteBuffer#writeUTF8String.

    method writeUint16

    writeUint16: (value: number, offset?: number) => this;
    • Writes a 16bit unsigned integer.

    method writeUint32

    writeUint32: (value: number, offset?: number) => this;
    • Writes a 32bit unsigned integer.

    method writeUint64

    writeUint64: (value: number | Long, offset?: number) => this;
    • Writes a 64bit unsigned integer.

    method writeUint8

    writeUint8: (value: number, offset?: number) => this;
    • Writes an 8bit unsigned integer.

    method writeUTF8String

    writeUTF8String: { (str: string): this; (str: string, offset?: number): number };
    • Writes an UTF8 encoded string.

    method writeVarint32

    writeVarint32: {
    (value: number): this;
    (value: number, offset: number): number;
    };
    • Writes a 32bit base 128 variable-length integer.

    method writeVarint32ZigZag

    writeVarint32ZigZag: {
    (value: number): this;
    (value: number, offset: number): number;
    };
    • Writes a zig-zag encoded 32bit base 128 variable-length integer.

    method writeVarint64

    writeVarint64: {
    (value: number | Long): this;
    (value: any, offset: number): number;
    };
    • Writes a 64bit base 128 variable-length integer.

    method writeVarint64ZigZag

    writeVarint64ZigZag: {
    (value: number | Long): this;
    (value: any, offset: number): number;
    };
    • Writes a zig-zag encoded 64bit base 128 variable-length integer.

    method writeVString

    writeVString: { (str: string): this; (str: string, offset: number): number };
    • Writes a length as varint32 prefixed UTF8 encoded string.

    method zigZagDecode32

    static zigZagDecode32: (n: number) => number;
    • Decodes a zigzag encoded signed 32bit integer.

    method zigZagDecode64

    static zigZagDecode64: (n: number | Long) => Long;
    • Decodes a zigzag encoded signed 64bit integer.

    method zigZagEncode32

    static zigZagEncode32: (n: number) => number;
    • Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding.

    method zigZagEncode64

    static zigZagEncode64: (n: number | Long) => Long;
    • Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding.

    Package Files (1)

    Dependencies (2)

    Dev Dependencies (0)

    No dev dependencies.

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/bytebuffer.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/bytebuffer)
    • HTML
      <a href="https://www.jsdocs.io/package/@types/bytebuffer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>