Class ByteBuffer
🏭 Constructors
constructor
new ByteBuffer(capacity: number, littleEndian: boolean, noAssert: boolean): ByteBufferConstructs a new ByteBuffer.
Parameters
- capacity:
numberInitial capacity. Defaults to DEFAULT_CAPACITY. - littleEndian:
booleanWhether to use little or big endian byte order. Defaults to DEFAULT_ENDIAN. - noAssert:
booleanWhether to skip assertions of offsets and values. Defaults to DEFAULT_NOASSERT.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:130
🏷️ Properties
buffer
buffer: ArrayBufferBacking ArrayBuffer.
Defined in: packages/bytebuffer/index.ts:75
limit
limit: numberAbsolute limit of the contained data. Set to the backing buffer's capacity upon allocation.
Defined in: packages/bytebuffer/index.ts:105
littleEndian
littleEndian: booleanWhether to use little endian byte order, defaults to false for big endian.
Defined in: packages/bytebuffer/index.ts:111
markedOffset
markedOffset: numberMarked offset.
Defined in: packages/bytebuffer/index.ts:97
noAssert
noAssert: booleanWhether to skip assertions of offsets and values, defaults to false.
Defined in: packages/bytebuffer/index.ts:117
offset
offset: numberAbsolute 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: DataViewDataView 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
BIG_ENDIAN: boolean = falseBig endian constant that can be used instead of its boolean value. Evaluates to false.
Defined in: packages/bytebuffer/index.ts:48
DEFAULT_CAPACITY
DEFAULT_CAPACITY: number = 16Default initial capacity of 16.
Defined in: packages/bytebuffer/index.ts:55
DEFAULT_ENDIAN
DEFAULT_ENDIAN: boolean = ByteBuffer.BIG_ENDIANDefault endianess of false for big endian.
Defined in: packages/bytebuffer/index.ts:62
DEFAULT_NOASSERT
DEFAULT_NOASSERT: boolean = falseDefault no assertions flag of false.
Defined in: packages/bytebuffer/index.ts:69
LITTLE_ENDIAN
LITTLE_ENDIAN: boolean = trueLittle endian constant that can be used instead of its boolean value. Evaluates to true.
Defined in: packages/bytebuffer/index.ts:40
VERSION
VERSION: string = '0.0.1'ByteBuffer version.
Defined in: packages/bytebuffer/index.ts:32
accessor
accessor: Function = ...Defined in: packages/bytebuffer/index.ts:155
allocate
allocate: Function = ...Defined in: packages/bytebuffer/index.ts:169
concat
concat: Function = ...Defined in: packages/bytebuffer/index.ts:185
type
type: Function = ...Defined in: packages/bytebuffer/index.ts:220
wrap
wrap: Function = ...Defined in: packages/bytebuffer/index.ts:235
🔧 Methods
BE
BE(bigEndian: undefined | boolean): ByteBufferSwitches (to) big endian byte order.
Parameters
- bigEndian:
undefined | booleanDefaults totrue, otherwise uses little endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1146
LE
LE(littleEndian: undefined | boolean): ByteBufferSwitches (to) little endian byte order.
Parameters
- littleEndian:
undefined | booleanDefaults totrue, otherwise uses big endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1135
append
append(source: Uint8Array | ArrayBuffer | ByteBuffer, offset: number): ByteBufferAppends 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 | ByteBufferData to append. Ifsourceis a ByteBuffer, its offsets will be modified according to the performed read operation. - offset:
numberOffset 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): ByteBufferAppends 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:
ByteBufferTarget ByteBuffer - offset:
numberOffset 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): ByteBufferEnables 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:
booleantrueto enable assertions, otherwisefalse
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:880
capacity
capacity(): numberGets the capacity of this ByteBuffer's backing buffer.
Return Type
number
Defined in: packages/bytebuffer/index.ts:890
clear
clear(): ByteBufferClears 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): ByteBufferCreates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for offset, markedOffset and limit.
Parameters
- copy:
booleanWhether 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): ByteBufferCompacts 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 | numberOffset to start at, defaults to offset - end:
undefined | numberOffset to end at, defaults to limit
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:939
copy
copy(begin: undefined | number, end: undefined | number): ByteBufferCreates a copy of this ByteBuffer's contents. Contents are the bytes between offset and limit.
Parameters
- begin:
undefined | numberBegin offset, defaults to offset. - end:
undefined | numberEnd offset, defaults to limit.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:977
copyTo
copyTo(target: ByteBuffer, targetOffset: number, sourceOffset: number, sourceLimit: number): ByteBufferCopies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between offset and limit.
Parameters
- target:
ByteBufferTarget ByteBuffer - targetOffset:
numberOffset to copy to. Will use and increase the target's offset by the number of bytes copied if omitted. - sourceOffset:
numberOffset to start copying from. Will use and increase offset by the number of bytes copied if omitted. - sourceLimit:
numberOffset to end copying from, defaults to limit
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1009
ensureCapacity
ensureCapacity(capacity: number): ByteBufferMakes 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:
numberRequired capacity
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1045
fill
fill(value: string | number, begin: number, end: number): ByteBufferOverwrites this ByteBuffer's contents with the specified value. Contents are the bytes between offset and limit.
Parameters
- value:
string | numberByte value to fill with. If given as a string, the first character is used. - begin:
numberBegin offset. Will use and increase offset by the number of bytes written if omitted. defaults to offset. - end:
numberEnd offset, defaults to limit.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1062
flip
flip(): ByteBufferMakes 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): ByteBufferMarks an offset on this ByteBuffer to be used later.
Parameters
- offset:
numberOffset to mark. Defaults to offset.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1104
order
order(littleEndian: boolean): ByteBufferSets the byte order.
Parameters
- littleEndian:
booleantruefor little endian byte order,falsefor big endian
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1121
prepend
prepend(source: ArrayBuffer | ByteBuffer, offset: number): ByteBufferPrepends 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 | ByteBufferData to prepend. Ifsourceis a ByteBuffer, its offset will be modified according to the performed read operation. - offset:
numberOffset 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): ByteBufferPrepends 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:
ByteBufferTarget ByteBuffer - offset:
numberOffset 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): ByteBufferReads the specified number of bytes.
Parameters
- length:
numberNumber of bytes to read - offset:
numberOffset to read from. Will use and increase offset bylengthif omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:274
readFloat32
readFloat32(offset: number): numberReads a 32bit float.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by4if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:737
readFloat64
readFloat64(offset: number): numberReads a 64bit float.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by8if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:802
readInt16
readInt16(offset: number): numberReads a 16bit signed integer.
Parameters
- offset:
numberOffset to read from. Will use and advance offset by2if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:478
readInt32
readInt32(offset: number): numberReads a 32bit signed integer.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by4if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:613
readInt64
readInt64(offset: number): bigintReads a 64bit signed integer.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by8if omitted.
Return Type
bigint
Defined in: packages/bytebuffer/index.ts:1371
readInt8
readInt8(offset: number): numberReads an 8bit signed integer.
Parameters
- offset:
numberOffset to read from. Will use and advance offset by1if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:344
readUint16
readUint16(offset: number): numberReads a 16bit unsigned integer.
Parameters
- offset:
numberOffset to read from. Will use and advance offset by2if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:548
readUint32
readUint32(offset: number): numberReads a 32bit unsigned integer.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by4if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:674
readUint64
readUint64(offset: number): bigintReads a 64bit unsigned integer.
Parameters
- offset:
numberOffset to read from. Will use and increase offset by8if omitted.
Return Type
bigint
Defined in: packages/bytebuffer/index.ts:1434
readUint8
readUint8(offset: number): numberReads an 8bit unsigned integer.
Parameters
- offset:
numberOffset to read from. Will use and advance offset by1if omitted.
Return Type
number
Defined in: packages/bytebuffer/index.ts:408
readVarint32
readVarint32(): numberReturn Type
number
readVarint32(offset: number): number | ObjectParameters
- offset:
number
Return Type
number | Object
Defined in: packages/bytebuffer/varint32.ts:6, packages/bytebuffer/varint32.ts:7
readVarint32ZigZag
readVarint32ZigZag(offset: number): number | ObjectParameters
- offset:
number
Return Type
number | Object
Defined in: packages/bytebuffer/varint32.ts:9
readVarint64
readVarint64(): bigintReturn Type
bigint
readVarint64(offset: number): ObjectParameters
- offset:
number
Return Type
Object
readVarint64(offset: number): bigint | ObjectReads a 64bit base 128 variable-length integer. Requires bigint.js.
Parameters
- offset:
numberOffset 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 | ObjectParameters
- offset:
number
Return Type
bigint | Object
Defined in: packages/bytebuffer/varint64.ts:36
remaining
remaining(): numberGets 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(): ByteBufferResets 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): ByteBufferResizes 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:
numberCapacity required
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1250
reverse
reverse(begin: undefined | number, end: undefined | number): ByteBufferReverses this ByteBuffer's contents.
Parameters
- begin:
undefined | numberOffset to start at, defaults to offset - end:
undefined | numberOffset to end at, defaults to limit
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1272
skip
skip(length: number): ByteBufferSkips the next length bytes. This will just advance
Parameters
- length:
numberNumber 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): ByteBufferSlices 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): ArrayBufferReturns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between offset and limit.
Parameters
- forceCopy:
booleanIftruereturns 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): stringParameters
- begin:
undefined | number - end:
undefined | number
Return Type
string
Defined in: packages/bytebuffer/hex.ts:5
writeFloat32
writeFloat32(value: number, offset: number): ByteBufferWrites a 32bit float.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and increase offset by4if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:703
writeFloat64
writeFloat64(value: number, offset: number): ByteBufferWrites a 64bit float.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and increase offset by8if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:768
writeInt16
writeInt16(value: number, offset: number): ByteBufferWrites a 16bit signed integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and advance offset by2if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:440
writeInt32
writeInt32(value: number, offset: number): ByteBufferWrites a 32bit signed integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and increase offset by4if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:580
writeInt64
writeInt64(value: number | bigint, offset: number): ByteBufferWrites a 64bit signed integer.
Parameters
- value:
number | bigintValue to write - offset:
numberOffset to write to. Will use and increase offset by8if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1337
writeInt8
writeInt8(value: number, offset: number): ByteBufferWrites an 8bit signed integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and advance offset by1if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:309
writeUint16
writeUint16(value: number, offset: number): ByteBufferWrites a 16bit unsigned integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and advance offset by2if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:510
writeUint32
writeUint32(value: number, offset: number): ByteBufferWrites a 32bit unsigned integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and increase offset by4if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:640
writeUint64
writeUint64(value: number | bigint, offset: number): ByteBufferWrites a 64bit unsigned integer.
Parameters
- value:
number | bigintValue to write - offset:
numberOffset to write to. Will use and increase offset by8if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:1399
writeUint8
writeUint8(value: number, offset: number): ByteBufferWrites an 8bit unsigned integer.
Parameters
- value:
numberValue to write - offset:
numberOffset to write to. Will use and advance offset by1if omitted.
Return Type
ByteBuffer
Defined in: packages/bytebuffer/index.ts:373
writeVarint32
writeVarint32(value: number, offset: number): number | ByteBufferParameters
- value:
number - offset:
number
Return Type
number | ByteBuffer
Defined in: packages/bytebuffer/varint32.ts:5
writeVarint32ZigZag
writeVarint32ZigZag(value: number, offset: number): number | ByteBufferParameters
- value:
number - offset:
number
Return Type
number | ByteBuffer
Defined in: packages/bytebuffer/varint32.ts:8
writeVarint64
writeVarint64(value: number | bigint, offset: number): number | ByteBufferWrites a 64bit base 128 variable-length integer.
Parameters
- value:
number | bigintValue to write - offset:
numberOffset 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 | ByteBufferWrites a zig-zag encoded 64bit base 128 variable-length integer.
Parameters
- value:
number | bigintValue to write - offset:
numberOffset 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