Skip to content

Class ByteBuffer ​

🏭 Constructors ​

constructor ​

ts
new ByteBuffer(capacity: number, littleEndian: boolean, noAssert: boolean): ByteBuffer

Constructs a new ByteBuffer.

Parameters ​

  • capacity: number Initial capacity. Defaults to DEFAULT_CAPACITY.
  • littleEndian: boolean Whether to use little or big endian byte order. Defaults to DEFAULT_ENDIAN.
  • noAssert: boolean Whether to skip assertions of offsets and values. Defaults to DEFAULT_NOASSERT.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:130

🏷️ Properties ​

buffer ​

ts
buffer: ArrayBuffer

Backing ArrayBuffer.

Defined in: packages/bytebuffer/index.ts:75

limit ​

ts
limit: number

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

Defined in: packages/bytebuffer/index.ts:105

littleEndian ​

ts
littleEndian: boolean

Whether to use little endian byte order, defaults to false for big endian.

Defined in: packages/bytebuffer/index.ts:111

markedOffset ​

ts
markedOffset: number

Marked offset.

Defined in: packages/bytebuffer/index.ts:97

noAssert ​

ts
noAssert: boolean

Whether to skip assertions of offsets and values, defaults to false.

Defined in: packages/bytebuffer/index.ts:117

offset ​

ts
offset: number

Absolute read/write offset.

Defined in: packages/bytebuffer/index.ts:89

readByte ​

ts
readByte: Function = ...

Defined in: packages/bytebuffer/index.ts:364

readDouble ​

ts
readDouble: Function = ...

Defined in: packages/bytebuffer/index.ts:822

readFloat ​

ts
readFloat: Function = ...

Defined in: packages/bytebuffer/index.ts:757

readInt ​

ts
readInt: Function = ...

Defined in: packages/bytebuffer/index.ts:632

readLong ​

ts
readLong: Function = ...

Defined in: packages/bytebuffer/index.ts:1390

readShort ​

ts
readShort: Function = ...

Defined in: packages/bytebuffer/index.ts:500

readUInt16 ​

ts
readUInt16: Function = ...

Defined in: packages/bytebuffer/index.ts:570

readUInt32 ​

ts
readUInt32: Function = ...

Defined in: packages/bytebuffer/index.ts:694

readUInt64 ​

ts
readUInt64: Function = ...

Defined in: packages/bytebuffer/index.ts:1454

readUInt8 ​

ts
readUInt8: Function = ...

Defined in: packages/bytebuffer/index.ts:428

toArrayBuffer ​

ts
toArrayBuffer: Function = ...

Defined in: packages/bytebuffer/index.ts:1498

view ​

ts
view: DataView

DataView utilized to manipulate the backing buffer. Becomes null if the backing buffer has a capacity of 0.

Defined in: packages/bytebuffer/index.ts:81

writeByte ​

ts
writeByte: Function = ...

Defined in: packages/bytebuffer/index.ts:336

writeBytes ​

ts
writeBytes: Function = ...

Defined in: packages/bytebuffer/index.ts:298

writeDouble ​

ts
writeDouble: Function = ...

Defined in: packages/bytebuffer/index.ts:794

writeFloat ​

ts
writeFloat: Function = ...

Defined in: packages/bytebuffer/index.ts:729

writeInt ​

ts
writeInt: Function = ...

Defined in: packages/bytebuffer/index.ts:605

writeLong ​

ts
writeLong: Function = ...

Defined in: packages/bytebuffer/index.ts:1363

writeShort ​

ts
writeShort: Function = ...

Defined in: packages/bytebuffer/index.ts:468

writeUInt16 ​

ts
writeUInt16: Function = ...

Defined in: packages/bytebuffer/index.ts:538

writeUInt32 ​

ts
writeUInt32: Function = ...

Defined in: packages/bytebuffer/index.ts:666

writeUInt64 ​

ts
writeUInt64: Function = ...

Defined in: packages/bytebuffer/index.ts:1426

writeUInt8 ​

ts
writeUInt8: Function = ...

Defined in: packages/bytebuffer/index.ts:400

BIG_ENDIAN static ​

ts
BIG_ENDIAN: boolean = false

Big endian constant that can be used instead of its boolean value. Evaluates to false.

Defined in: packages/bytebuffer/index.ts:48

DEFAULT_CAPACITY static ​

ts
DEFAULT_CAPACITY: number = 16

Default initial capacity of 16.

Defined in: packages/bytebuffer/index.ts:55

DEFAULT_ENDIAN static ​

ts
DEFAULT_ENDIAN: boolean = ByteBuffer.BIG_ENDIAN

Default endianess of false for big endian.

Defined in: packages/bytebuffer/index.ts:62

DEFAULT_NOASSERT static ​

ts
DEFAULT_NOASSERT: boolean = false

Default no assertions flag of false.

Defined in: packages/bytebuffer/index.ts:69

LITTLE_ENDIAN static ​

ts
LITTLE_ENDIAN: boolean = true

Little endian constant that can be used instead of its boolean value. Evaluates to true.

Defined in: packages/bytebuffer/index.ts:40

VERSION static ​

ts
VERSION: string = '0.0.1'

ByteBuffer version.

Defined in: packages/bytebuffer/index.ts:32

accessor static ​

ts
accessor: Function = ...

Defined in: packages/bytebuffer/index.ts:155

allocate static ​

ts
allocate: Function = ...

Defined in: packages/bytebuffer/index.ts:169

concat static ​

ts
concat: Function = ...

Defined in: packages/bytebuffer/index.ts:185

type static ​

ts
type: Function = ...

Defined in: packages/bytebuffer/index.ts:220

wrap static ​

ts
wrap: Function = ...

Defined in: packages/bytebuffer/index.ts:235

🔧 Methods ​

BE ​

ts
BE(bigEndian: undefined | boolean): ByteBuffer

Switches (to) big endian byte order.

Parameters ​

  • bigEndian: undefined | boolean Defaults to true, otherwise uses little endian

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1146

LE ​

ts
LE(littleEndian: undefined | boolean): ByteBuffer

Switches (to) little endian byte order.

Parameters ​

  • littleEndian: undefined | boolean Defaults to true, otherwise uses big endian

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1135

append ​

ts
append(source: Uint8Array | ArrayBuffer | ByteBuffer, offset: number): ByteBuffer

Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended data's length.

Parameters ​

  • source: Uint8Array | ArrayBuffer | ByteBuffer Data to append. If source is a ByteBuffer, its offsets will be modified according to the performed read operation.
  • offset: number Offset to append at. Will use and increase offset by the number of bytes written if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:837

appendTo ​

ts
appendTo(target: ByteBuffer, offset: number): ByteBuffer

Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the specified offset up to the length of this ByteBuffer's data.

Parameters ​

  • target: ByteBuffer Target ByteBuffer
  • offset: number Offset to append to. Will use and increase offset by the number of bytes read if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:868

assert ​

ts
assert(assert: boolean): ByteBuffer

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.

Parameters ​

  • assert: booleantrue to enable assertions, otherwise false

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:880

capacity ​

ts
capacity(): number

Gets the capacity of this ByteBuffer's backing buffer.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:890

clear ​

ts
clear(): ByteBuffer

Clears this ByteBuffer's offsets by setting offset to 0 and limit to the backing buffer's capacity. Discards markedOffset.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:900

clone ​

ts
clone(copy: boolean): ByteBuffer

Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for offset, markedOffset and limit.

Parameters ​

  • copy: boolean Whether to copy the backing buffer or to return another view on the same, defaults to false

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:914

compact ​

ts
compact(begin: undefined | number, end: undefined | number): ByteBuffer

Compacts this ByteBuffer to be backed by a buffer of its contents' length. Contents are the bytes between offset and limit. Will set offset = 0 and limit = capacity and adapt markedOffset to the same relative position if set.

Parameters ​

  • begin: undefined | number Offset to start at, defaults to offset
  • end: undefined | number Offset to end at, defaults to limit

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:939

copy ​

ts
copy(begin: undefined | number, end: undefined | number): ByteBuffer

Creates a copy of this ByteBuffer's contents. Contents are the bytes between offset and limit.

Parameters ​

  • begin: undefined | number Begin offset, defaults to offset.
  • end: undefined | number End offset, defaults to limit.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:977

copyTo ​

ts
copyTo(target: ByteBuffer, targetOffset: number, sourceOffset: number, sourceLimit: number): ByteBuffer

Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between offset and limit.

Parameters ​

  • target: ByteBuffer Target ByteBuffer
  • targetOffset: number Offset to copy to. Will use and increase the target's offset by the number of bytes copied if omitted.
  • sourceOffset: number Offset to start copying from. Will use and increase offset by the number of bytes copied if omitted.
  • sourceLimit: number Offset to end copying from, defaults to limit

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1009

ensureCapacity ​

ts
ensureCapacity(capacity: number): ByteBuffer

Makes sure that this ByteBuffer is backed by a 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.

Parameters ​

  • capacity: number Required capacity

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1045

fill ​

ts
fill(value: string | number, begin: number, end: number): ByteBuffer

Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between offset and limit.

Parameters ​

  • value: string | number Byte value to fill with. If given as a string, the first character is used.
  • begin: number Begin offset. Will use and increase offset by the number of bytes written if omitted. defaults to offset.
  • end: number End offset, defaults to limit.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1062

flip ​

ts
flip(): ByteBuffer

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.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1089

mark ​

ts
mark(offset: number): ByteBuffer

Marks an offset on this ByteBuffer to be used later.

Parameters ​

  • offset: number Offset to mark. Defaults to offset.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1104

order ​

ts
order(littleEndian: boolean): ByteBuffer

Sets the byte order.

Parameters ​

  • littleEndian: booleantrue for little endian byte order, false for big endian

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1121

prepend ​

ts
prepend(source: ArrayBuffer | ByteBuffer, offset: number): ByteBuffer

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.

Parameters ​

  • source: ArrayBuffer | ByteBuffer Data to prepend. If source is a ByteBuffer, its offset will be modified according to the performed read operation.
  • offset: number Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1165

prependTo ​

ts
prependTo(target: ByteBuffer, offset: number): ByteBuffer

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.

Parameters ​

  • target: ByteBuffer Target ByteBuffer
  • offset: number Offset to prepend at. Will use and decrease offset by the number of bytes prepended if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1208

readBytes ​

ts
readBytes(length: number, offset: number): ByteBuffer

Reads the specified number of bytes.

Parameters ​

  • length: number Number of bytes to read
  • offset: number Offset to read from. Will use and increase offset by length if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:274

readFloat32 ​

ts
readFloat32(offset: number): number

Reads a 32bit float.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 4 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:737

readFloat64 ​

ts
readFloat64(offset: number): number

Reads a 64bit float.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 8 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:802

readInt16 ​

ts
readInt16(offset: number): number

Reads a 16bit signed integer.

Parameters ​

  • offset: number Offset to read from. Will use and advance offset by 2 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:478

readInt32 ​

ts
readInt32(offset: number): number

Reads a 32bit signed integer.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 4 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:613

readInt64 ​

ts
readInt64(offset: number): bigint

Reads a 64bit signed integer.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 8 if omitted.

Return Type ​

  • bigint

Defined in: packages/bytebuffer/index.ts:1371

readInt8 ​

ts
readInt8(offset: number): number

Reads an 8bit signed integer.

Parameters ​

  • offset: number Offset to read from. Will use and advance offset by 1 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:344

readUint16 ​

ts
readUint16(offset: number): number

Reads a 16bit unsigned integer.

Parameters ​

  • offset: number Offset to read from. Will use and advance offset by 2 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:548

readUint32 ​

ts
readUint32(offset: number): number

Reads a 32bit unsigned integer.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 4 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:674

readUint64 ​

ts
readUint64(offset: number): bigint

Reads a 64bit unsigned integer.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by 8 if omitted.

Return Type ​

  • bigint

Defined in: packages/bytebuffer/index.ts:1434

readUint8 ​

ts
readUint8(offset: number): number

Reads an 8bit unsigned integer.

Parameters ​

  • offset: number Offset to read from. Will use and advance offset by 1 if omitted.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:408

readVarint32 ​

ts
readVarint32(): number

Return Type ​

  • number
ts
readVarint32(offset: number): number | Object

Parameters ​

  • offset: number

Return Type ​

  • number | Object

Defined in: packages/bytebuffer/varint32.ts:6, packages/bytebuffer/varint32.ts:7

readVarint32ZigZag ​

ts
readVarint32ZigZag(offset: number): number | Object

Parameters ​

  • offset: number

Return Type ​

  • number | Object

Defined in: packages/bytebuffer/varint32.ts:9

readVarint64 ​

ts
readVarint64(): bigint

Return Type ​

  • bigint
ts
readVarint64(offset: number): Object

Parameters ​

  • offset: number

Return Type ​

  • Object
ts
readVarint64(offset: number): bigint | Object

Reads a 64bit base 128 variable-length integer. Requires bigint.js.

Parameters ​

  • offset: number Offset to read from. Will use and increase offset by the number of bytes read if omitted.

Return Type ​

  • bigint | Object

Defined in: packages/bytebuffer/varint64.ts:15, packages/bytebuffer/varint64.ts:16, packages/bytebuffer/varint64.ts:26

readVarint64ZigZag ​

ts
readVarint64ZigZag(offset: number): bigint | Object

Parameters ​

  • offset: number

Return Type ​

  • bigint | Object

Defined in: packages/bytebuffer/varint64.ts:36

remaining ​

ts
remaining(): number

Gets the number of remaining readable bytes. Contents are the bytes between offset and limit, so this returns limit - offset.

Return Type ​

  • number

Defined in: packages/bytebuffer/index.ts:1219

reset ​

ts
reset(): ByteBuffer

Resets this ByteBuffer's offset. If an offset has been marked through mark before, offset will be set to markedOffset, which will then be discarded. If no offset has been marked, sets offset = 0.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1231

resize ​

ts
resize(capacity: number): ByteBuffer

Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that large or larger.

Parameters ​

  • capacity: number Capacity required

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1250

reverse ​

ts
reverse(begin: undefined | number, end: undefined | number): ByteBuffer

Reverses this ByteBuffer's contents.

Parameters ​

  • begin: undefined | number Offset to start at, defaults to offset
  • end: undefined | number Offset to end at, defaults to limit

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1272

skip ​

ts
skip(length: number): ByteBuffer

Skips the next length bytes. This will just advance

Parameters ​

  • length: number Number of bytes to skip. May also be negative to move the offset back.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1294

slice ​

ts
slice(begin: number, end: number): ByteBuffer

Slices this ByteBuffer by creating a cloned instance with offset = begin and limit = end.

Parameters ​

  • begin: number Begin offset, defaults to offset.
  • end: number End offset, defaults to limit.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1314

toBuffer ​

ts
toBuffer(forceCopy: boolean): ArrayBuffer

Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between offset and limit.

Parameters ​

  • forceCopy: boolean If true returns a copy, otherwise returns a view referencing the same memory if possible. Defaults to false

Return Type ​

  • ArrayBuffer

Defined in: packages/bytebuffer/index.ts:1464

toHex ​

ts
toHex(begin: undefined | number, end: undefined | number): string

Parameters ​

  • begin: undefined | number
  • end: undefined | number

Return Type ​

  • string

Defined in: packages/bytebuffer/hex.ts:5

writeFloat32 ​

ts
writeFloat32(value: number, offset: number): ByteBuffer

Writes a 32bit float.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and increase offset by 4 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:703

writeFloat64 ​

ts
writeFloat64(value: number, offset: number): ByteBuffer

Writes a 64bit float.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and increase offset by 8 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:768

writeInt16 ​

ts
writeInt16(value: number, offset: number): ByteBuffer

Writes a 16bit signed integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and advance offset by 2 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:440

writeInt32 ​

ts
writeInt32(value: number, offset: number): ByteBuffer

Writes a 32bit signed integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and increase offset by 4 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:580

writeInt64 ​

ts
writeInt64(value: number | bigint, offset: number): ByteBuffer

Writes a 64bit signed integer.

Parameters ​

  • value: number | bigint Value to write
  • offset: number Offset to write to. Will use and increase offset by 8 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1337

writeInt8 ​

ts
writeInt8(value: number, offset: number): ByteBuffer

Writes an 8bit signed integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and advance offset by 1 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:309

writeUint16 ​

ts
writeUint16(value: number, offset: number): ByteBuffer

Writes a 16bit unsigned integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and advance offset by 2 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:510

writeUint32 ​

ts
writeUint32(value: number, offset: number): ByteBuffer

Writes a 32bit unsigned integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and increase offset by 4 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:640

writeUint64 ​

ts
writeUint64(value: number | bigint, offset: number): ByteBuffer

Writes a 64bit unsigned integer.

Parameters ​

  • value: number | bigint Value to write
  • offset: number Offset to write to. Will use and increase offset by 8 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:1399

writeUint8 ​

ts
writeUint8(value: number, offset: number): ByteBuffer

Writes an 8bit unsigned integer.

Parameters ​

  • value: number Value to write
  • offset: number Offset to write to. Will use and advance offset by 1 if omitted.

Return Type ​

  • ByteBuffer

Defined in: packages/bytebuffer/index.ts:373

writeVarint32 ​

ts
writeVarint32(value: number, offset: number): number | ByteBuffer

Parameters ​

  • value: number
  • offset: number

Return Type ​

  • number | ByteBuffer

Defined in: packages/bytebuffer/varint32.ts:5

writeVarint32ZigZag ​

ts
writeVarint32ZigZag(value: number, offset: number): number | ByteBuffer

Parameters ​

  • value: number
  • offset: number

Return Type ​

  • number | ByteBuffer

Defined in: packages/bytebuffer/varint32.ts:8

writeVarint64 ​

ts
writeVarint64(value: number | bigint, offset: number): number | ByteBuffer

Writes a 64bit base 128 variable-length integer.

Parameters ​

  • value: number | bigint Value to write
  • offset: number Offset to write to. Will use and increase offset by the number of bytes written if omitted.

Return Type ​

  • number | ByteBuffer

Defined in: packages/bytebuffer/varint64.ts:14

writeVarint64ZigZag ​

ts
writeVarint64ZigZag(value: number | bigint, offset: number): number | ByteBuffer

Writes a zig-zag encoded 64bit base 128 variable-length integer.

Parameters ​

  • value: number | bigint Value to write
  • offset: number Offset to write to. Will use and increase offset by the number of bytes written if omitted.

Return Type ​

  • number | ByteBuffer

Defined in: packages/bytebuffer/varint64.ts:35