Class ByteBuffer
🏭 Constructors
constructor
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
buffer: ArrayBuffer
Backing ArrayBuffer.
Defined in: packages/bytebuffer/index.ts:75
limit
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
littleEndian: boolean
Whether to use little endian byte order, defaults to false
for big endian.
Defined in: packages/bytebuffer/index.ts:111
markedOffset
markedOffset: number
Marked offset.
Defined in: packages/bytebuffer/index.ts:97
noAssert
noAssert: boolean
Whether to skip assertions of offsets and values, defaults to false
.
Defined in: packages/bytebuffer/index.ts:117
offset
offset: number
Absolute read/write offset.
Defined in: packages/bytebuffer/index.ts:89
readByte
readByte: Function = ...
Defined in: packages/bytebuffer/index.ts:364
readDouble
readDouble: Function = ...
Defined in: packages/bytebuffer/index.ts:822
readFloat
readFloat: Function = ...
Defined in: packages/bytebuffer/index.ts:757
readInt
readInt: Function = ...
Defined in: packages/bytebuffer/index.ts:632
readLong
readLong: Function = ...
Defined in: packages/bytebuffer/index.ts:1390
readShort
readShort: Function = ...
Defined in: packages/bytebuffer/index.ts:500
readUInt16
readUInt16: Function = ...
Defined in: packages/bytebuffer/index.ts:570
readUInt32
readUInt32: Function = ...
Defined in: packages/bytebuffer/index.ts:694
readUInt64
readUInt64: Function = ...
Defined in: packages/bytebuffer/index.ts:1454
readUInt8
readUInt8: Function = ...
Defined in: packages/bytebuffer/index.ts:428
toArrayBuffer
toArrayBuffer: Function = ...
Defined in: packages/bytebuffer/index.ts:1498
view
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
writeByte: Function = ...
Defined in: packages/bytebuffer/index.ts:336
writeBytes
writeBytes: Function = ...
Defined in: packages/bytebuffer/index.ts:298
writeDouble
writeDouble: Function = ...
Defined in: packages/bytebuffer/index.ts:794
writeFloat
writeFloat: Function = ...
Defined in: packages/bytebuffer/index.ts:729
writeInt
writeInt: Function = ...
Defined in: packages/bytebuffer/index.ts:605
writeLong
writeLong: Function = ...
Defined in: packages/bytebuffer/index.ts:1363
writeShort
writeShort: Function = ...
Defined in: packages/bytebuffer/index.ts:468
writeUInt16
writeUInt16: Function = ...
Defined in: packages/bytebuffer/index.ts:538
writeUInt32
writeUInt32: Function = ...
Defined in: packages/bytebuffer/index.ts:666
writeUInt64
writeUInt64: Function = ...
Defined in: packages/bytebuffer/index.ts:1426
writeUInt8
writeUInt8: Function = ...
Defined in: packages/bytebuffer/index.ts:400
BIG_ENDIAN static
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
DEFAULT_CAPACITY: number = 16
Default initial capacity of 16
.
Defined in: packages/bytebuffer/index.ts:55
DEFAULT_ENDIAN static
DEFAULT_ENDIAN: boolean = ByteBuffer.BIG_ENDIAN
Default endianess of false
for big endian.
Defined in: packages/bytebuffer/index.ts:62
DEFAULT_NOASSERT static
DEFAULT_NOASSERT: boolean = false
Default no assertions flag of false
.
Defined in: packages/bytebuffer/index.ts:69
LITTLE_ENDIAN static
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
VERSION: string = '0.0.1'
ByteBuffer version.
Defined in: packages/bytebuffer/index.ts:32
accessor static
accessor: Function = ...
Defined in: packages/bytebuffer/index.ts:155
allocate static
allocate: Function = ...
Defined in: packages/bytebuffer/index.ts:169
concat static
concat: Function = ...
Defined in: packages/bytebuffer/index.ts:185
type static
type: Function = ...
Defined in: packages/bytebuffer/index.ts:220
wrap static
wrap: Function = ...
Defined in: packages/bytebuffer/index.ts:235
🔧 Methods
BE
BE(bigEndian: undefined | boolean): ByteBuffer
Switches (to) big endian byte order.
Parameters
- bigEndian:
undefined | boolean
Defaults totrue
, otherwise uses little endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1146
LE
LE(littleEndian: undefined | boolean): ByteBuffer
Switches (to) little endian byte order.
Parameters
- littleEndian:
undefined | boolean
Defaults totrue
, otherwise uses big endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1135
append
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. Ifsource
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
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
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:
boolean
true
to enable assertions, otherwisefalse
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:880
capacity
capacity(): number
Gets the capacity of this ByteBuffer's backing buffer.
Return Type
number
Defined in: packages/bytebuffer/index.ts:890
clear
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
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 tofalse
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:914
compact
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
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
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
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
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
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
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
order(littleEndian: boolean): ByteBuffer
Sets the byte order.
Parameters
- littleEndian:
boolean
true
for little endian byte order,false
for big endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1121
prepend
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. Ifsource
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
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
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 bylength
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:274
readFloat32
readFloat32(offset: number): number
Reads a 32bit float.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by4
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:737
readFloat64
readFloat64(offset: number): number
Reads a 64bit float.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by8
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:802
readInt16
readInt16(offset: number): number
Reads a 16bit signed integer.
Parameters
- offset:
number
Offset to read from. Will use and advance offset by2
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:478
readInt32
readInt32(offset: number): number
Reads a 32bit signed integer.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by4
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:613
readInt64
readInt64(offset: number): bigint
Reads a 64bit signed integer.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by8
if omitted.
Return Type
bigint
Defined in: packages/bytebuffer/index.ts:1371
readInt8
readInt8(offset: number): number
Reads an 8bit signed integer.
Parameters
- offset:
number
Offset to read from. Will use and advance offset by1
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:344
readUint16
readUint16(offset: number): number
Reads a 16bit unsigned integer.
Parameters
- offset:
number
Offset to read from. Will use and advance offset by2
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:548
readUint32
readUint32(offset: number): number
Reads a 32bit unsigned integer.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by4
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:674
readUint64
readUint64(offset: number): bigint
Reads a 64bit unsigned integer.
Parameters
- offset:
number
Offset to read from. Will use and increase offset by8
if omitted.
Return Type
bigint
Defined in: packages/bytebuffer/index.ts:1434
readUint8
readUint8(offset: number): number
Reads an 8bit unsigned integer.
Parameters
- offset:
number
Offset to read from. Will use and advance offset by1
if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:408
readVarint32
readVarint32(): number
Return Type
number
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
readVarint32ZigZag(offset: number): number | Object
Parameters
- offset:
number
Return Type
number | Object
Defined in: packages/bytebuffer/varint32.ts:9
readVarint64
readVarint64(): bigint
Return Type
bigint
readVarint64(offset: number): Object
Parameters
- offset:
number
Return Type
Object
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
readVarint64ZigZag(offset: number): bigint | Object
Parameters
- offset:
number
Return Type
bigint | Object
Defined in: packages/bytebuffer/varint64.ts:36
remaining
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
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
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
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
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
slice(begin: number, end: number): ByteBuffer
Slices this ByteBuffer by creating a cloned instance with offset = begin
and limit = end
.
Parameters
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1314
toBuffer
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
Iftrue
returns a copy, otherwise returns a view referencing the same memory if possible. Defaults tofalse
Return Type
ArrayBuffer
Defined in: packages/bytebuffer/index.ts:1464
toHex
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
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 by4
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:703
writeFloat64
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 by8
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:768
writeInt16
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 by2
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:440
writeInt32
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 by4
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:580
writeInt64
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 by8
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1337
writeInt8
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 by1
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:309
writeUint16
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 by2
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:510
writeUint32
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 by4
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:640
writeUint64
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 by8
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1399
writeUint8
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 by1
if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:373
writeVarint32
writeVarint32(value: number, offset: number): number | ByteBuffer
Parameters
- value:
number
- offset:
number
Return Type
number | ByteBuffer
Defined in: packages/bytebuffer/varint32.ts:5
writeVarint32ZigZag
writeVarint32ZigZag(value: number, offset: number): number | ByteBuffer
Parameters
- value:
number
- offset:
number
Return Type
number | ByteBuffer
Defined in: packages/bytebuffer/varint32.ts:8
writeVarint64
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
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