-
Notifications
You must be signed in to change notification settings - Fork 155
- ByteBuffer()
- this.buffer
- this.view
- this.offset
- this.markedOffset
- this.limit
- this.littleEndian
- this.noAssert
- ByteBuffer.VERSION
- ByteBuffer.LITTLE_ENDIAN
- ByteBuffer.BIG_ENDIAN
- ByteBuffer.DEFAULT_CAPACITY
- ByteBuffer.DEFAULT_ENDIAN
- ByteBuffer.DEFAULT_NOASSERT
- ByteBuffer.Long
- EMPTY_BUFFER
- ByteBuffer.allocate(capacity*, littleEndian*, noAssert*)
- ByteBuffer.concat(buffers, encoding*, littleEndian*, noAssert*)
- ByteBuffer.isByteBuffer(bb)
- ByteBuffer.type()
- ByteBuffer.wrap(buffer, encoding*, littleEndian*, noAssert*)
- ByteBuffer.writeInt8(value, offset*)
- ByteBuffer.prototype.writeByte
- ByteBuffer.readInt8(offset*)
- ByteBuffer.prototype.readByte
- ByteBuffer.writeUint8(value, offset*)
- ByteBuffer.readUint8(offset*)
- ByteBuffer.writeInt16(value, offset*)
- ByteBuffer.prototype.writeShort
- ByteBuffer.readInt16(offset*)
- ByteBuffer.prototype.readShort
- ByteBuffer.writeUint16(value, offset*)
- ByteBuffer.readUint16(offset*)
- ByteBuffer.writeInt32(value, offset*)
- ByteBuffer.prototype.writeInt
- ByteBuffer.readInt32(offset*)
- ByteBuffer.prototype.readInt
- ByteBuffer.writeUint32(value, offset*)
- ByteBuffer.readUint32(offset*)
- ByteBuffer.writeInt64(value, offset*)
- ByteBuffer.prototype.writeLong
- ByteBuffer.readInt64(offset*)
- ByteBuffer.prototype.readLong
- ByteBuffer.writeUint64(value, offset*)
- ByteBuffer.readUint64(offset*)
- ByteBuffer.writeFloat32(value, offset*)
- ByteBuffer.prototype.writeFloat
- ByteBuffer.readFloat32(offset*)
- ByteBuffer.prototype.readFloat
- ByteBuffer.writeFloat64(value, offset*)
- ByteBuffer.prototype.writeDouble
- ByteBuffer.readFloat64(offset*)
- ByteBuffer.prototype.readDouble
- ByteBuffer.MAX_VARINT32_BYTES
- ByteBuffer.calculateVarint32(value)
- ByteBuffer.zigZagEncode32(n)
- ByteBuffer.zigZagDecode32(n)
- ByteBuffer.writeVarint32(value, offset*)
- ByteBuffer.writeVarint32ZigZag(value, offset*)
- ByteBuffer.readVarint32(offset*)
- ByteBuffer.readVarint32ZigZag(offset*)
- ByteBuffer.MAX_VARINT64_BYTES
- ByteBuffer.calculateVarint64(value)
- ByteBuffer.zigZagEncode64(value)
- ByteBuffer.zigZagDecode64(value)
- ByteBuffer.writeVarint64(value, offset*)
- ByteBuffer.writeVarint64ZigZag(value, offset*)
- ByteBuffer.readVarint64(offset*)
- ByteBuffer.readVarint64ZigZag(offset*)
- ByteBuffer.writeCString(str, offset*)
- ByteBuffer.readCString(offset*)
- ByteBuffer.writeIString(str, offset*)
- ByteBuffer.readIString(offset*)
- ByteBuffer.METRICS_CHARS
- ByteBuffer.METRICS_BYTES
- ByteBuffer.writeUTF8String(str, offset*)
- ByteBuffer.prototype.writeString
- ByteBuffer.calculateUTF8Chars(str)
- ByteBuffer.calculateUTF8Bytes
- ByteBuffer.readUTF8String(length, metrics*, offset*)
- ByteBuffer.prototype.readString
- ByteBuffer.writeVString(str, offset*)
- ByteBuffer.readVString(offset*)
- ByteBuffer.append(source, encoding*, offset*)
- ByteBuffer.appendTo(target, offset*)
- ByteBuffer.assert(assert)
- ByteBuffer.capacity()
- ByteBuffer.clear()
- ByteBuffer.clone(copy*)
- ByteBuffer.compact(begin*, end*)
- ByteBuffer.copy(begin*, end*)
- ByteBuffer.copyTo(target, targetOffset*, sourceOffset*, sourceLimit*)
- ByteBuffer.ensureCapacity(capacity)
- ByteBuffer.fill(value, begin*, end*)
- ByteBuffer.flip()
- ByteBuffer.mark(offset*)
- ByteBuffer.order(littleEndian)
- ByteBuffer.LE(littleEndian*)
- ByteBuffer.BE(bigEndian*)
- ByteBuffer.prepend(source, encoding*, offset*)
- ByteBuffer.prependTo(target, offset*)
- ByteBuffer.printDebug(out*)
- ByteBuffer.remaining()
- ByteBuffer.reset()
- ByteBuffer.resize(capacity)
- ByteBuffer.reverse(begin*, end*)
- ByteBuffer.skip(length)
- ByteBuffer.slice(begin*, end*)
- ByteBuffer.toBuffer(forceCopy*)
- ByteBuffer.prototype.toArrayBuffer
- ByteBuffer.toString(encoding*)
- B64
- ByteBuffer.toBase64(begin*, end*)
- ByteBuffer.fromBase64(str, littleEndian*, noAssert*)
- ByteBuffer.btoa(str)
- ByteBuffer.atob(b64)
- ByteBuffer.toBinary(begin*, end*)
- ByteBuffer.fromBinary(str, littleEndian*, noAssert*)
- ByteBuffer.toDebug(columns*)
- ByteBuffer.fromDebug(str, littleEndian*, noAssert*)
- ByteBuffer.toHex(begin*, end*)
- ByteBuffer.fromHex(str, littleEndian*, noAssert*)
- utf8_decode_char()
- utf8_calc_char()
- utf8_calc_string()
- utf8_encode_char()
- ByteBuffer.toUTF8()
- ByteBuffer.fromUTF8(str, littleEndian*, noAssert*)
Constructs a new ByteBuffer.
Name | Type | Description |
---|---|---|
capacity* | number | Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
Backing buffer.
Data view to manipulate the backing buffer. Becomes null
if the backing buffer has a capacity of 0
.
Absolute read/write offset.
Marked offset.
Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation.
Whether to use little endian byte order, defaults to false
for big endian.
Whether to skip assertions of offsets and values, defaults to false
.
ByteBuffer version.
Little endian constant that can be used instead of its boolean value. Evaluates to true
.
Big endian constant that can be used instead of its boolean value. Evaluates to false
.
Default initial capacity of 16
.
Default endianess of false
for big endian.
Default no assertions flag of false
.
A Long
class for representing a 64-bit two's-complement integer value. May be null
if Long.js has not been loaded
and int64 support is not available.
@type {!ArrayBuffer}
Allocates a new ByteBuffer backed by a buffer of the specified capacity.
Name | Type | Description |
---|---|---|
capacity* | number | Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}. |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer |
Concatenates multiple ByteBuffers into one.
Name | Type | Description |
---|---|---|
buffers | !Array.<!ByteBuffer ¦ !ArrayBuffer | !Uint8Array |
encoding* | (string ¦ boolean) | String encoding if buffers contains a string ("base64", "hex", "binary", |
littleEndian* | boolean | Whether to use little or big endian byte order for the resulting ByteBuffer. Defaults |
noAssert* | boolean | Whether to skip assertions of offsets and values for the resulting ByteBuffer. Defaults to |
returns | !ByteBuffer | Concatenated ByteBuffer |
Tests if the specified type is a ByteBuffer.
Name | Type | Description |
---|---|---|
bb | * | ByteBuffer to test |
returns | boolean |
true if it is a ByteBuffer, otherwise false
|
Gets the backing buffer type.
Name | Type | Description |
---|---|---|
returns | Function |
Buffer for NB builds, ArrayBuffer for AB builds (classes) |
Wraps a buffer or a string. Sets the allocated ByteBuffer's {@link ByteBuffer#offset} to 0
and its
{@link ByteBuffer#limit} to the length of the wrapped data.
Name | Type | Description |
---|---|---|
buffer | !ByteBuffer ¦ !ArrayBuffer | !Uint8Array |
encoding* | (string ¦ boolean) | String encoding if buffer is a string ("base64", "hex", "binary", defaults to |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | A ByteBuffer wrapping buffer
|
Writes an 8bit signed integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | !ByteBuffer | this |
Writes an 8bit signed integer. This is an alias of {@link ByteBuffer#writeInt8}.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | !ByteBuffer | this |
Reads an 8bit signed integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | number | Value read |
Reads an 8bit signed integer. This is an alias of {@link ByteBuffer#readInt8}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | number | Value read |
Writes an 8bit unsigned integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | !ByteBuffer | this |
Reads an 8bit unsigned integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 1 if omitted. |
returns | number | Value read |
Writes a 16bit signed integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
throws | TypeError | If offset or value is not a valid number |
throws | RangeError | If offset is out of bounds |
Writes a 16bit signed integer. This is an alias of {@link ByteBuffer#writeInt16}.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
throws | TypeError | If offset or value is not a valid number |
throws | RangeError | If offset is out of bounds |
Reads a 16bit signed integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
returns | number | Value read |
throws | TypeError | If offset is not a valid number |
throws | RangeError | If offset is out of bounds |
Reads a 16bit signed integer. This is an alias of {@link ByteBuffer#readInt16}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
returns | number | Value read |
throws | TypeError | If offset is not a valid number |
throws | RangeError | If offset is out of bounds |
Writes a 16bit unsigned integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
throws | TypeError | If offset or value is not a valid number |
throws | RangeError | If offset is out of bounds |
Reads a 16bit unsigned integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 2 if omitted. |
returns | number | Value read |
throws | TypeError | If offset is not a valid number |
throws | RangeError | If offset is out of bounds |
Writes a 32bit signed integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
Reads a 32bit signed integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | number | Value read |
Reads a 32bit signed integer. This is an alias of {@link ByteBuffer#readInt32}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and advance {@link ByteBuffer#offset} by 4 if omitted. |
returns | number | Value read |
Writes a 32bit unsigned integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
Reads a 32bit unsigned integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | number | Value read |
Writes a 64bit signed integer.
Name | Type | Description |
---|---|---|
value | number ¦ !Long | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !ByteBuffer | this |
Writes a 64bit signed integer. This is an alias of {@link ByteBuffer#writeInt64}.
Name | Type | Description |
---|---|---|
value | number ¦ !Long | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !ByteBuffer | this |
Reads a 64bit signed integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !Long |
Reads a 64bit signed integer. This is an alias of {@link ByteBuffer#readInt64}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !Long |
Writes a 64bit unsigned integer.
Name | Type | Description |
---|---|---|
value | number ¦ !Long | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !ByteBuffer | this |
Reads a 64bit unsigned integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !Long |
Writes a 32bit float.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | !ByteBuffer | this |
Writes a 32bit float. This is an alias of {@link ByteBuffer#writeFloat32}.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | !ByteBuffer | this |
Reads a 32bit float.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | number |
Reads a 32bit float. This is an alias of {@link ByteBuffer#readFloat32}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 4 if omitted. |
returns | number |
Writes a 64bit float.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !ByteBuffer | this |
Writes a 64bit float. This is an alias of {@link ByteBuffer#writeFloat64}.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | !ByteBuffer | this |
Reads a 64bit float.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | number |
Reads a 64bit float. This is an alias of {@link ByteBuffer#readFloat64}.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by 8 if omitted. |
returns | number |
Maximum number of bytes required to store a 32bit base 128 variable-length integer.
Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number | Value to encode |
returns | number | Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES} |
Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding.
Name | Type | Description |
---|---|---|
n | number | Signed 32bit integer |
returns | number | Unsigned zigzag encoded 32bit integer |
Decodes a zigzag encoded signed 32bit integer.
Name | Type | Description |
---|---|---|
n | number | Unsigned zigzag encoded 32bit integer |
returns | number | Signed 32bit integer |
Writes a 32bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number | this if offset is omitted, else the actual number of bytes written |
Writes a zig-zag encoded 32bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number | this if offset is omitted, else the actual number of bytes written |
Reads a 32bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | number ¦ !{value: number, length: number} | The value read if offset is omitted, else the value read |
throws | Error | If it's not a valid varint |
Reads a zig-zag encoded 32bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | number ¦ !{value: number, length: number} | The value read if offset is omitted, else the value read |
throws | Error | If it's not a valid varint |
Maximum number of bytes required to store a 64bit base 128 variable-length integer.
Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number ¦ !Long | Value to encode |
returns | number | Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES} |
Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding.
Name | Type | Description |
---|---|---|
value | number ¦ !Long | Signed long |
returns | !Long | Unsigned zigzag encoded long |
Decodes a zigzag encoded signed 64bit integer.
Name | Type | Description |
---|---|---|
value | !Long ¦ number | Unsigned zigzag encoded long or JavaScript number |
returns | !Long | Signed long |
Writes a 64bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number ¦ Long | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number |
this if offset is omitted, else the actual number of bytes written. |
Writes a zig-zag encoded 64bit base 128 variable-length integer.
Name | Type | Description |
---|---|---|
value | number ¦ Long | Value to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number |
this if offset is omitted, else the actual number of bytes written. |
Reads a 64bit base 128 variable-length integer. Requires Long.js.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !Long ¦ !{value: Long, length: number} | The value read if offset is omitted, else the value read and |
throws | Error | If it's not a valid varint |
Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !Long ¦ !{value: Long, length: number} | The value read if offset is omitted, else the value read and |
throws | Error | If it's not a valid varint |
Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL characters itself.
Name | Type | Description |
---|---|---|
str | string | String to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number | this if offset is omitted, else the actual number of bytes written |
Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters itself.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | string ¦ !{string: string, length: number} | The string read if offset is omitted, else the string |
Writes a length as uint32 prefixed UTF8 encoded string.
Name | Type | Description |
---|---|---|
str | string | String to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number |
this if offset is omitted, else the actual number of bytes written |
Reads a length as uint32 prefixed UTF8 encoded string.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | string ¦ !{string: string, length: number} | The string read if offset is omitted, else the string |
Metrics representing number of UTF8 characters. Evaluates to 1
.
Metrics representing number of bytes. Evaluates to 2
.
Writes an UTF8 encoded string.
Name | Type | Description |
---|---|---|
str | string | String to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted. |
returns | !ByteBuffer ¦ number | this if offset is omitted, else the actual number of bytes written. |
Writes an UTF8 encoded string. This is an alias of {@link ByteBuffer#writeUTF8String}.
Name | Type | Description |
---|---|---|
str | string | String to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted. |
returns | !ByteBuffer ¦ number | this if offset is omitted, else the actual number of bytes written. |
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.
Name | Type | Description |
---|---|---|
str | string | String to calculate |
returns | number | Number of UTF8 characters |
Calculates the number of UTF8 bytes of a string.
Name | Type | Description |
---|---|---|
str | string | String to calculate |
returns | number | Number of UTF8 bytes |
Reads an UTF8 encoded string.
Name | Type | Description |
---|---|---|
length | number | Number of characters or bytes to read |
metrics* | number | Metrics specifying what n is meant to count. Defaults to |
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | string ¦ !{string: string, length: number} | The string read if offset is omitted, else the string |
Reads an UTF8 encoded string. This is an alias of {@link ByteBuffer#readUTF8String}.
Name | Type | Description |
---|---|---|
length | number | Number of characters or bytes to read |
metrics* | number | Metrics specifying what n is meant to count. Defaults to |
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | string ¦ !{string: string, length: number} | The string read if offset is omitted, else the string |
Writes a length as varint32 prefixed UTF8 encoded string.
Name | Type | Description |
---|---|---|
str | string | String to write |
offset* | number | Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer ¦ number |
this if offset is omitted, else the actual number of bytes written |
Reads a length as varint32 prefixed UTF8 encoded string.
Name | Type | Description |
---|---|---|
offset* | number | Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | string ¦ !{string: string, length: number} | The string read if offset is omitted, else the string |
Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended data's length.
Name | Type | Description |
---|---|---|
source | !ByteBuffer ¦ !ArrayBuffer | !Uint8Array |
encoding* | (string ¦ number) | Encoding if data is a string ("base64", "hex", "binary", defaults to "utf8") |
offset* | number | Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
offset* | number | Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
assert | boolean |
true to enable assertions, otherwise false
|
returns | !ByteBuffer | this |
Gets the capacity of this ByteBuffer's backing buffer.
Name | Type | Description |
---|---|---|
returns | number | Capacity of the backing buffer |
Clears this ByteBuffer's offsets by setting {@link ByteBuffer#offset} to 0
and {@link ByteBuffer#limit} to the
backing buffer's capacity. Discards {@link ByteBuffer#markedOffset}.
Name | Type | Description |
---|---|---|
returns | !ByteBuffer | this |
Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for {@link ByteBuffer#offset}, {@link ByteBuffer#markedOffset} and {@link ByteBuffer#limit}.
Name | Type | Description |
---|---|---|
copy* | boolean | Whether to copy the backing buffer or to return another view on the same, defaults to false
|
returns | !ByteBuffer | Cloned instance |
Compacts this ByteBuffer to be backed by a {@link ByteBuffer#buffer} of its contents' length. Contents are the bytes
between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will set offset = 0
and limit = capacity
and
adapt {@link ByteBuffer#markedOffset} to the same relative position if set.
Name | Type | Description |
---|---|---|
begin* | number | Offset to start at, defaults to {@link ByteBuffer#offset} |
end* | number | Offset to end at, defaults to {@link ByteBuffer#limit} |
returns | !ByteBuffer | this |
Creates a copy of this ByteBuffer's contents. Contents are the bytes between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
Name | Type | Description |
---|---|---|
begin* | number | Begin offset, defaults to {@link ByteBuffer#offset}. |
end* | number | End offset, defaults to {@link ByteBuffer#limit}. |
returns | !ByteBuffer | Copy |
Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
Name | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
targetOffset* | number | Offset to copy to. Will use and increase the target's {@link ByteBuffer#offset} |
sourceOffset* | number | Offset to start copying from. Will use and increase {@link ByteBuffer#offset} by the |
sourceLimit* | number | Offset to end copying from, defaults to {@link ByteBuffer#limit} |
returns | !ByteBuffer | this |
Makes sure that this ByteBuffer is backed by a {@link 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.
Name | Type | Description |
---|---|---|
capacity | number | Required capacity |
returns | !ByteBuffer | this |
Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
Name | Type | Description |
---|---|---|
value | number ¦ string | Byte value to fill with. If given as a string, the first character is used. |
begin* | number | Begin offset. Will use and increase {@link ByteBuffer#offset} by the number of bytes |
end* | number | End offset, defaults to {@link ByteBuffer#limit}. |
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
returns | !ByteBuffer | this |
Marks an offset on this ByteBuffer to be used later.
Name | Type | Description |
---|---|---|
offset* | number | Offset to mark. Defaults to {@link ByteBuffer#offset}. |
returns | !ByteBuffer | this |
throws | TypeError | If offset is not a valid number |
throws | RangeError | If offset is out of bounds |
Sets the byte order.
Name | Type | Description |
---|---|---|
littleEndian | boolean |
true for little endian byte order, false for big endian |
returns | !ByteBuffer | this |
Switches (to) little endian byte order.
Name | Type | Description |
---|---|---|
littleEndian* | boolean | Defaults to true , otherwise uses big endian |
returns | !ByteBuffer | this |
Switches (to) big endian byte order.
Name | Type | Description |
---|---|---|
bigEndian* | boolean | Defaults to true , otherwise uses little endian |
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
source | !ByteBuffer ¦ string | !ArrayBuffer |
encoding* | (string ¦ number) | Encoding if data is a string ("base64", "hex", "binary", defaults to "utf8") |
offset* | number | Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
offset* | number | Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes |
returns | !ByteBuffer | this |
Prints debug information about this ByteBuffer's contents.
Name | Type | Description |
---|---|---|
out* | function(string) | Output function to call, defaults to console.log |
Gets the number of remaining readable bytes. Contents are the bytes between {@link ByteBuffer#offset} and
{@link ByteBuffer#limit}, so this returns limit - offset
.
Name | Type | Description |
---|---|---|
returns | number | Remaining readable bytes. May be negative if offset > limit . |
Resets this ByteBuffer's {@link ByteBuffer#offset}. If an offset has been marked through {@link ByteBuffer#mark}
before, offset
will be set to {@link ByteBuffer#markedOffset}, which will then be discarded. If no offset has been
marked, sets offset = 0
.
Name | Type | Description |
---|---|---|
returns | !ByteBuffer | 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.
Name | Type | Description |
---|---|---|
capacity | number | Capacity required |
returns | !ByteBuffer | this |
throws | TypeError | If capacity is not a number |
throws | RangeError | If capacity < 0
|
Reverses this ByteBuffer's contents.
Name | Type | Description |
---|---|---|
begin* | number | Offset to start at, defaults to {@link ByteBuffer#offset} |
end* | number | Offset to end at, defaults to {@link ByteBuffer#limit} |
returns | !ByteBuffer | this |
Skips the next length
bytes. This will just advance
Name | Type | Description |
---|---|---|
length | number | Number of bytes to skip. May also be negative to move the offset back. |
returns | !ByteBuffer | this |
Slices this ByteBuffer by creating a cloned instance with offset = begin
and limit = end
.
Name | Type | Description |
---|---|---|
begin* | number | Begin offset, defaults to {@link ByteBuffer#offset}. |
end* | number | End offset, defaults to {@link ByteBuffer#limit}. |
returns | !ByteBuffer | Clone of this ByteBuffer with slicing applied, backed by the same {@link ByteBuffer#buffer} |
Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between
{@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will transparently {@link ByteBuffer#flip} this
ByteBuffer if offset > limit
but the actual offsets remain untouched.
Name | Type | Description |
---|---|---|
forceCopy* | boolean | If true returns a copy, otherwise returns a view referencing the same memory if |
returns | !ArrayBuffer | Contents as an ArrayBuffer |
Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between
{@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will transparently {@link ByteBuffer#flip} this
ByteBuffer if offset > limit
but the actual offsets remain untouched. This is an alias of
{@link ByteBuffer#toBuffer}.
Name | Type | Description |
---|---|---|
forceCopy* | boolean | If true returns a copy, otherwise returns a view referencing the same memory. |
returns | !ArrayBuffer | Contents as an ArrayBuffer |
Converts the ByteBuffer's contents to a string.
Name | Type | Description |
---|---|---|
encoding* | string | Output encoding. Returns an informative string representation if omitted but also allows |
returns | string | String representation |
throws | Error | If encoding is invalid |
Base64 alphabet.
Encodes this ByteBuffer's contents to a base64 encoded string.
Name | Type | Description |
---|---|---|
begin* | number | Offset to begin at, defaults to {@link ByteBuffer#offset}. |
end* | number | Offset to end at, defaults to {@link ByteBuffer#limit}. |
returns | string | Base64 encoded string |
Decodes a base64 encoded string to a ByteBuffer.
Name | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | ByteBuffer |
Encodes a binary string to base64 like window.btoa
does.
Name | Type | Description |
---|---|---|
str | string | Binary string |
returns | string | Base64 encoded string |
Decodes a base64 encoded string to binary like window.atob
does.
Name | Type | Description |
---|---|---|
b64 | string | Base64 encoded string |
returns | string | Binary string |
Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes.
Name | Type | Description |
---|---|---|
begin* | number | Offset to begin at. Defaults to {@link ByteBuffer#offset}. |
end* | number | Offset to end at. Defaults to {@link ByteBuffer#limit}. |
returns | string | Binary encoded string |
throws | RangeError | If offset > limit
|
Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.
Name | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | ByteBuffer |
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
Name | Type | Description |
---|---|---|
columns* | boolean | If true returns two columns hex + ascii, defaults to false
|
returns | string ¦ !Array. | Debug string or array of lines if asArray = true
|
Decodes a hex encoded string with marked offsets to a ByteBuffer.
Name | Type | Description |
---|---|---|
str | string | Debug string to decode (not be generated with columns = true ) |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | ByteBuffer |
Encodes this ByteBuffer's contents to a hex encoded string.
Name | Type | Description |
---|---|---|
begin* | number | Offset to begin at. Defaults to {@link ByteBuffer#offset}. |
end* | number | Offset to end at. Defaults to {@link ByteBuffer#limit}. |
returns | string | Hex encoded string |
Decodes a hex encoded string to a ByteBuffer.
Name | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | ByteBuffer |
Decodes a single UTF8 character from the specified ByteBuffer. The ByteBuffer's offsets remain untouched.
Name | Type | Description |
---|---|---|
bb | !ByteBuffer | ByteBuffer to decode from |
offset | number | Offset to start at |
returns | !{codePoint: number, length: number} | Decoded char code and the number of bytes read |
Calculates the actual number of bytes required to encode the specified char code.
Name | Type | Description |
---|---|---|
codePoint | number | Code point to encode |
returns | number | Number of bytes required to encode the specified code point |
Calculates the number of bytes required to store an UTF8 encoded string.
Name | Type | Description |
---|---|---|
str | string | String to calculate |
returns | number | Number of bytes required |
Encodes a single UTF8 character to the specified ByteBuffer backed by an ArrayBuffer. The ByteBuffer's offsets are not modified.
Name | Type | Description |
---|---|---|
codePoint | number | Code point to encode |
bb | !ByteBuffer | ByteBuffer to encode to |
offset | number | Offset to write to |
returns | number | Number of bytes written |
Encodes this ByteBuffer's contents between {@link ByteBuffer#offset} and {@link ByteBuffer#limit} to an UTF8 encoded string.
Name | Type | Description |
---|---|---|
returns | string | Hex encoded string |
throws | RangeError | If offset > limit
|
Decodes an UTF8 encoded string to a ByteBuffer.
Name | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian* | boolean | Whether to use little or big endian byte order. Defaults to |
noAssert* | boolean | Whether to skip assertions of offsets and values. Defaults to |
returns | !ByteBuffer | ByteBuffer |