-
Notifications
You must be signed in to change notification settings - Fork 155
The swiss army knife for binary data in JavaScript.
Big endian constant that can be used instead of its boolean value. Evaluates to false
.
Type | boolean |
Access | public const |
Default initial capacity of 16
.
Type | number |
Access | public |
Default endianess of false
for big endian.
Type | boolean |
Access | public |
Default no assertions flag of false
.
Type | boolean |
Access | public |
Little endian constant that can be used instead of its boolean value. Evaluates to true
.
Type | boolean |
Access | public const |
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 | Long |
Access | public const |
Maximum number of bytes required to store a 32bit base 128 variable-length integer.
Type | number |
Access | public const |
Maximum number of bytes required to store a 64bit base 128 variable-length integer.
Type | number |
Access | public const |
Metrics representing number of bytes. Evaluates to 2
.
Type | number |
Access | public const |
Metrics representing number of UTF8 characters. Evaluates to 1
.
Type | number |
Access | public const |
ByteBuffer version.
Type | string |
Access | public const |
Allocates a new ByteBuffer backed by a buffer of the specified capacity.
Parameter | Type | Description |
---|---|---|
capacity | number | Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY. |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer |
Decodes a base64 encoded string to binary like window.atob
does.
Parameter | Type | Description |
---|---|---|
b64 | string | Base64 encoded string |
@returns | string | Binary string |
Encodes a binary string to base64 like window.btoa
does.
Parameter | Type | Description |
---|---|---|
str | string | Binary string |
@returns | string | Base64 encoded string |
Calculates the number of UTF8 bytes of a string.
Parameter | Type | Description |
---|---|---|
str | string | String to calculate |
@returns | number | Number of UTF8 bytes |
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.
Parameter | Type | Description |
---|---|---|
str | string | String to calculate |
@returns | number | Number of UTF8 characters |
Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to encode |
@returns | number | Number of bytes required. Capped to ByteBuffer.MAX_VARINT32_BYTES |
Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
value | number | !Long | Value to encode |
@returns | number | Number of bytes required. Capped to ByteBuffer.MAX_VARINT64_BYTES |
Concatenates multiple ByteBuffers into one.
Parameter | Type | Description |
---|---|---|
buffers | !Array.<(!ByteBuffer | !ArrayBuffer | !Uint8Array | string)> | Buffers to concatenate |
encoding | string | boolean | String encoding if buffers contains a string ("base64", "hex", "binary", defaults to "utf8") |
littleEndian | boolean | Whether to use little or big endian byte order for the resulting ByteBuffer. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values for the resulting ByteBuffer. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | Concatenated ByteBuffer |
Decodes a base64 encoded string to a ByteBuffer.
Parameter | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | ByteBuffer |
Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.
Parameter | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | ByteBuffer |
Decodes a hex encoded string with marked offsets to a ByteBuffer.
Parameter | 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 ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | ByteBuffer |
Decodes a hex encoded string to a ByteBuffer.
Parameter | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | ByteBuffer |
Decodes an UTF8 encoded string to a ByteBuffer.
Parameter | Type | Description |
---|---|---|
str | string | String to decode |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | ByteBuffer |
Tests if the specified type is a ByteBuffer.
Parameter | Type | Description |
---|---|---|
bb | *** | ByteBuffer to test |
@returns | boolean |
true if it is a ByteBuffer, otherwise false
|
Gets the backing buffer type.
Parameter | Type | Description |
---|---|---|
@returns | Function |
Buffer for NB builds, ArrayBuffer for AB builds (classes) |
Wraps a buffer or a string. Sets the allocated ByteBuffer's ByteBuffer#offset to 0
and its
ByteBuffer#limit to the length of the wrapped data.
Parameter | Type | Description |
---|---|---|
buffer | !ByteBuffer | !ArrayBuffer | !Uint8Array | string | Anything that can be wrapped |
encoding | string | boolean | String encoding if buffer is a string ("base64", "hex", "binary", defaults to "utf8") |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
@returns | !ByteBuffer | A ByteBuffer wrapping buffer
|
Decodes a zigzag encoded signed 32bit integer.
Parameter | Type | Description |
---|---|---|
n | number | Unsigned zigzag encoded 32bit integer |
@returns | number | Signed 32bit integer |
Decodes a zigzag encoded signed 64bit integer.
Parameter | Type | Description |
---|---|---|
value | !Long | number | Unsigned zigzag encoded long or JavaScript number |
@returns | !Long | Signed long |
Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding.
Parameter | Type | Description |
---|---|---|
n | number | Signed 32bit integer |
@returns | number | Unsigned zigzag encoded 32bit integer |
Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding.
Parameter | Type | Description |
---|---|---|
value | number | !Long | Signed long |
@returns | !Long | Unsigned zigzag encoded long |
Constructs a new ByteBuffer.
Parameter | Type | Description |
---|---|---|
capacity | number | Initial capacity. Defaults to ByteBuffer.DEFAULT_CAPACITY. |
littleEndian | boolean | Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. |
noAssert | boolean | Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. |
Backing buffer.
Type | !ArrayBuffer |
Access | public |
Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation.
Type | number |
Access | public |
Whether to use little endian byte order, defaults to false
for big endian.
Type | boolean |
Access | public |
Marked offset.
Type | number |
Access | public |
Whether to skip assertions of offsets and values, defaults to false
.
Type | boolean |
Access | public |
Absolute read/write offset.
Type | number |
Access | public |
Data view to manipulate the backing buffer. Becomes null
if the backing buffer has a capacity of 0
.
Type | DataView |
Access | public |
Switches (to) big endian byte order.
Parameter | Type | Description |
---|---|---|
bigEndian | boolean | Defaults to true , otherwise uses little endian |
@returns | !ByteBuffer | this |
Switches (to) little endian byte order.
Parameter | Type | Description |
---|---|---|
littleEndian | boolean | Defaults to true , otherwise uses big endian |
@returns | !ByteBuffer | this |
Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended data's length.
Parameter | Type | Description |
---|---|---|
source | !ByteBuffer | !ArrayBuffer | !Uint8Array | string | Data to append. If source is a ByteBuffer, its offsets will be modified according to the performed read operation. |
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 ByteBuffer#offset by the number of bytes read if omitted. |
@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.
Parameter | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
offset | number | Offset to append to. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@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.
Parameter | Type | Description |
---|---|---|
assert | boolean |
true to enable assertions, otherwise false
|
@returns | !ByteBuffer | this |
Gets the capacity of this ByteBuffer's backing buffer.
Parameter | Type | Description |
---|---|---|
@returns | number | Capacity of the backing buffer |
Clears this ByteBuffer's offsets by setting ByteBuffer#offset to 0
and ByteBuffer#limit to the
backing buffer's capacity. Discards ByteBuffer#markedOffset.
Parameter | Type | Description |
---|---|---|
@returns | !ByteBuffer | this |
Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for ByteBuffer#offset, ByteBuffer#markedOffset and ByteBuffer#limit.
Parameter | 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 ByteBuffer#buffer of its contents' length. Contents are the bytes
between ByteBuffer#offset and ByteBuffer#limit. Will set offset = 0
and limit = capacity
and
adapt ByteBuffer#markedOffset to the same relative position if set.
Parameter | Type | Description |
---|---|---|
begin | number | Offset to start at, defaults to ByteBuffer#offset |
end | number | Offset to end at, defaults to ByteBuffer#limit |
@returns | !ByteBuffer | this |
Creates a copy of this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.
Parameter | Type | Description |
---|---|---|
begin | number | Begin offset, defaults to ByteBuffer#offset. |
end | number | End offset, defaults to ByteBuffer#limit. |
@returns | !ByteBuffer | Copy |
Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.
Parameter | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
targetOffset | number | Offset to copy to. Will use and increase the target's ByteBuffer#offset by the number of bytes copied if omitted. |
sourceOffset | number | Offset to start copying from. Will use and increase ByteBuffer#offset by the number of bytes copied if omitted. |
sourceLimit | number | Offset to end copying from, defaults to ByteBuffer#limit |
@returns | !ByteBuffer | this |
Makes sure that this ByteBuffer is backed by a ByteBuffer#buffer of at least the specified capacity. If the current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity, the required capacity will be used instead.
Parameter | Type | Description |
---|---|---|
capacity | number | Required capacity |
@returns | !ByteBuffer | this |
Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit.
Parameter | 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 ByteBuffer#offset by the number of bytes written if omitted. defaults to ByteBuffer#offset. |
end | number | End offset, defaults to 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.
Parameter | Type | Description |
---|---|---|
@returns | !ByteBuffer | this |
Marks an offset on this ByteBuffer to be used later.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to mark. Defaults to ByteBuffer#offset. |
@returns | !ByteBuffer | this |
Sets the byte order.
Parameter | Type | Description |
---|---|---|
littleEndian | boolean |
true for little endian byte order, false for big 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.
Parameter | Type | Description |
---|---|---|
source | !ByteBuffer | string | !ArrayBuffer | Data to prepend. If source is a ByteBuffer, its offset will be modified according to the performed read operation. |
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 ByteBuffer#offset by the number of bytes prepended if omitted. |
@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.
Parameter | Type | Description |
---|---|---|
target | !ByteBuffer | Target ByteBuffer |
offset | number | Offset to prepend at. Will use and decrease ByteBuffer#offset by the number of bytes prepended if omitted. |
@returns | !ByteBuffer | this |
Prints debug information about this ByteBuffer's contents.
Parameter | Type | Description |
---|---|---|
out | function(string) | Output function to call, defaults to console.log |
Reads an 8bit signed integer. This is an alias of ByteBuffer#readInt8.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | number | Value read |
Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters itself.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | string | !{string: string, length: number} | The string read if offset is omitted, else the string read and the actual number of bytes read. |
Reads a 64bit float. This is an alias of ByteBuffer#readFloat64.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | number |
Reads a 32bit float. This is an alias of ByteBuffer#readFloat32.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | number |
Reads a 32bit float.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | number |
Reads a 64bit float.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | number |
Reads a length as uint32 prefixed UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | string | !{string: string, length: number} | The string read if offset is omitted, else the string read and the actual number of bytes read. |
Reads a 32bit signed integer. This is an alias of ByteBuffer#readInt32.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 4 if omitted. |
@returns | number | Value read |
Reads a 16bit signed integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 2 if omitted. |
@returns | number | Value read |
Reads a 32bit signed integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | number | Value read |
Reads a 64bit signed integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !Long |
Reads an 8bit signed integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | number | Value read |
Reads a 64bit signed integer. This is an alias of ByteBuffer#readInt64.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !Long |
Reads a 16bit signed integer. This is an alias of ByteBuffer#readInt16.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 2 if omitted. |
@returns | number | Value read |
Reads an UTF8 encoded string. This is an alias of ByteBuffer#readUTF8String.
Parameter | Type | Description |
---|---|---|
length | number | Number of characters or bytes to read |
metrics | number | Metrics specifying what n is meant to count. Defaults to ByteBuffer.METRICS_CHARS. |
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | string | !{string: string, length: number} | The string read if offset is omitted, else the string read and the actual number of bytes read. |
Reads an UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
length | number | Number of characters or bytes to read |
metrics | number | Metrics specifying what n is meant to count. Defaults to ByteBuffer.METRICS_CHARS. |
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | string | !{string: string, length: number} | The string read if offset is omitted, else the string read and the actual number of bytes read. |
Reads a 16bit unsigned integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 2 if omitted. |
@returns | number | Value read |
Reads a 32bit unsigned integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | number | Value read |
Reads a 64bit unsigned integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !Long |
Reads an 8bit unsigned integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | number | Value read |
Reads a length as varint32 prefixed UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | string | !{string: string, length: number} | The string read if offset is omitted, else the string read and the actual number of bytes read. |
Reads a 32bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | number | !{value: number, length: number} | The value read if offset is omitted, else the value read and the actual number of bytes read. |
Reads a zig-zag encoded 32bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | number | !{value: number, length: number} | The value read if offset is omitted, else the value read and the actual number of bytes read. |
Reads a 64bit base 128 variable-length integer. Requires Long.js.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | !Long | !{value: Long, length: number} | The value read if offset is omitted, else the value read and the actual number of bytes read. |
Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js.
Parameter | Type | Description |
---|---|---|
offset | number | Offset to read from. Will use and increase ByteBuffer#offset by the number of bytes read if omitted. |
@returns | !Long | !{value: Long, length: number} | The value read if offset is omitted, else the value read and the actual number of bytes read. |
Gets the number of remaining readable bytes. Contents are the bytes between ByteBuffer#offset and
ByteBuffer#limit, so this returns limit - offset
.
Parameter | Type | Description |
---|---|---|
@returns | number | Remaining readable bytes. May be negative if offset > limit . |
Resets this ByteBuffer's ByteBuffer#offset. If an offset has been marked through ByteBuffer#mark
before, offset
will be set to ByteBuffer#markedOffset, which will then be discarded. If no offset has been
marked, sets offset = 0
.
Parameter | 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.
Parameter | Type | Description |
---|---|---|
capacity | number | Capacity required |
@returns | !ByteBuffer | this |
Reverses this ByteBuffer's contents.
Parameter | Type | Description |
---|---|---|
begin | number | Offset to start at, defaults to ByteBuffer#offset |
end | number | Offset to end at, defaults to ByteBuffer#limit |
@returns | !ByteBuffer | this |
Skips the next length
bytes. This will just advance
Parameter | 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
.
Parameter | Type | Description |
---|---|---|
begin | number | Begin offset, defaults to ByteBuffer#offset. |
end | number | End offset, defaults to ByteBuffer#limit. |
@returns | !ByteBuffer | Clone of this ByteBuffer with slicing applied, backed by the same ByteBuffer#buffer |
Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between
ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this
ByteBuffer if offset > limit
but the actual offsets remain untouched. This is an alias of
ByteBuffer#toBuffer.
Parameter | Type | Description |
---|---|---|
forceCopy | boolean | If true returns a copy, otherwise returns a view referencing the same memory. Defaults to false
|
@returns | !ArrayBuffer | Contents as an ArrayBuffer |
Encodes this ByteBuffer's contents to a base64 encoded string.
Parameter | Type | Description |
---|---|---|
begin | number | Offset to begin at, defaults to ByteBuffer#offset. |
end | number | Offset to end at, defaults to ByteBuffer#limit. |
@returns | string | Base64 encoded string |
Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes.
Parameter | Type | Description |
---|---|---|
begin | number | Offset to begin at. Defaults to ByteBuffer#offset. |
end | number | Offset to end at. Defaults to ByteBuffer#limit. |
@returns | string | Binary encoded string |
Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between
ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this
ByteBuffer if offset > limit
but the actual offsets remain untouched.
Parameter | Type | Description |
---|---|---|
forceCopy | boolean | If true returns a copy, otherwise returns a view referencing the same memory if possible. Defaults to false
|
@returns | !ArrayBuffer | Contents as an ArrayBuffer |
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
Parameter | Type | Description |
---|---|---|
columns | boolean | If true returns two columns hex + ascii, defaults to false
|
@returns | string | !Array.<string> | Debug string or array of lines if asArray = true
|
Encodes this ByteBuffer's contents to a hex encoded string.
Parameter | Type | Description |
---|---|---|
begin | number | Offset to begin at. Defaults to ByteBuffer#offset. |
end | number | Offset to end at. Defaults to ByteBuffer#limit. |
@returns | string | Hex encoded string |
Converts the ByteBuffer's contents to a string.
Parameter | Type | Description |
---|---|---|
encoding | string | Output encoding. Returns an informative string representation if omitted but also allows direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with highlighted offsets. |
@returns | string | String representation |
Encodes this ByteBuffer's contents between ByteBuffer#offset and ByteBuffer#limit to an UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
@returns | string | Hex encoded string |
Writes an 8bit signed integer. This is an alias of ByteBuffer#writeInt8.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | !ByteBuffer | this |
Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL characters itself.
Parameter | Type | Description |
---|---|---|
str | string | String to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes contained in str + 1 if omitted. |
@returns | !ByteBuffer | number | this if offset is omitted, else the actual number of bytes written |
Writes a 64bit float. This is an alias of ByteBuffer#writeFloat64.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !ByteBuffer | this |
Writes a 32bit float. This is an alias of ByteBuffer#writeFloat32.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | !ByteBuffer | this |
Writes a 32bit float.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 4 if omitted. |
@returns | !ByteBuffer | this |
Writes a 64bit float.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !ByteBuffer | this |
Writes a length as uint32 prefixed UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
str | string | String to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | !ByteBuffer | number |
this if offset is omitted, else the actual number of bytes written |
Writes a 32bit signed integer. This is an alias of ByteBuffer#writeInt32.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 4 if omitted. |
Writes a 16bit signed integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 2 if omitted. |
Writes a 32bit signed integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 4 if omitted. |
Writes a 64bit signed integer.
Parameter | Type | Description |
---|---|---|
value | number | !Long | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !ByteBuffer | this |
Writes an 8bit signed integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | !ByteBuffer | this |
Writes a 64bit signed integer. This is an alias of ByteBuffer#writeInt64.
Parameter | Type | Description |
---|---|---|
value | number | !Long | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !ByteBuffer | this |
Writes a 16bit signed integer. This is an alias of ByteBuffer#writeInt16.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 2 if omitted. |
Writes an UTF8 encoded string. This is an alias of ByteBuffer#writeUTF8String.
Parameter | Type | Description |
---|---|---|
str | string | String to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset if omitted. |
@returns | !ByteBuffer | number | this if offset is omitted, else the actual number of bytes written. |
Writes an UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
str | string | String to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset if omitted. |
@returns | !ByteBuffer | number | this if offset is omitted, else the actual number of bytes written. |
Writes a 16bit unsigned integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 2 if omitted. |
Writes a 32bit unsigned integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 4 if omitted. |
Writes a 64bit unsigned integer.
Parameter | Type | Description |
---|---|---|
value | number | !Long | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by 8 if omitted. |
@returns | !ByteBuffer | this |
Writes an 8bit unsigned integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and advance ByteBuffer#offset by 1 if omitted. |
@returns | !ByteBuffer | this |
Writes a length as varint32 prefixed UTF8 encoded string.
Parameter | Type | Description |
---|---|---|
str | string | String to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | !ByteBuffer | number |
this if offset is omitted, else the actual number of bytes written |
Writes a 32bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@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.
Parameter | Type | Description |
---|---|---|
value | number | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | !ByteBuffer | number | this if offset is omitted, else the actual number of bytes written |
Writes a 64bit base 128 variable-length integer.
Parameter | Type | Description |
---|---|---|
value | number | Long | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@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.
Parameter | Type | Description |
---|---|---|
value | number | Long | Value to write |
offset | number | Offset to write to. Will use and increase ByteBuffer#offset by the number of bytes written if omitted. |
@returns | !ByteBuffer | number |
this if offset is omitted, else the actual number of bytes written. |
Generated with doco v0.2.0