NodeHostBuffer

A NodeBufferInstance backed by a NIO byteBuffer. The entirety of the buffer is used, thus byteOffset is always zero and length is set to the remaining bytes in the buffer.

The backing buffer's position and limit are assumed to remain constant and should therefore not be modified in any case; doing so will cause unspecified behavior.

Properties

Link copied to clipboard
open override val buffer: PolyglotValue

A simple value wrapper for the backing byteBuffer; the JavaScript engine will treat it as an ArrayBuffer automatically, making it compatible with the Node.js API.

Link copied to clipboard
open override val byteOffset: Int = 0

Unlike the original Node.js Buffer instances, no byte offset is used by this class, as each buffer is backed by its own ByteBuffer, making this value always zero.

Link copied to clipboard
open override val length: Int

Returns the number of usable bytes in the backing byteBuffer. Note that methods in this class do not move the buffer's position or limit, and as such both values are assumed to remain constant, making this property also a constant calculated during construction.

Functions

Link copied to clipboard
open override fun compare(target: PolyglotValue, targetStart: Int?, targetEnd: Int?, sourceStart: Int?, sourceEnd: Int?): Int

Compare this buffer with either another buffer instance or a Uint8Array, optionally using only delimited segments of both values.

Link copied to clipboard
open override fun copy(target: PolyglotValue, targetStart: Int?, sourceStart: Int?, sourceEnd: Int?): Int

Copies the contents of this buffer to a target, optionally starting at an offset and limiting the copied region from the source.

Link copied to clipboard
open override fun entries(): PolyglotValue

Returns an iterable value which yields, for every byte in the buffer, an array with the index as the first element and the byte as a second element.

Link copied to clipboard
open override fun fill(value: PolyglotValue, offset: Int?, end: Int?, encoding: String?): BufferInstance

Fill the buffer starting at offset and stopping at end with the given value. If the value is a string, it is converted to bytes using encoding (UTF-8 by default).

Link copied to clipboard
open operator override fun get(index: Long): Any
Link copied to clipboard
open override fun getIterator(): Any
Link copied to clipboard
open override fun getMember(key: String?): Any
Link copied to clipboard
open override fun getMemberKeys(): Any
Link copied to clipboard
open override fun getSize(): Long
Link copied to clipboard
open override fun hasMember(key: String?): Boolean
Link copied to clipboard
open override fun indexOf(value: PolyglotValue, byteOffset: Int?, encoding: String?): Int

Returns the byte index of the first occurrence of value in the buffer after byteOffset, or -1 if it is not found. The value may be a number (coerced into byte size), a string, another buffer, or a Uint8Array. The encoding will be used for string values if available.

Link copied to clipboard
open override fun keys(): PolyglotValue

Returns an iterable value which yields the buffer's keys (indices).

Link copied to clipboard
open override fun lastIndexOf(value: PolyglotValue, byteOffset: Int?, encoding: String?): Int

Returns the byte index of the last occurrence of value in the buffer after byteOffset, or -1 if it is not found. The value may be a number (coerced into byte size), a string, another buffer, or a Uint8Array. The encoding will be used for string values if available.

Link copied to clipboard
open override fun putMember(key: String?, value: Value?)
Link copied to clipboard
open override fun readBigInt64BE(offset: Int?): Long

Read a 64-bit integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readBigInt64LE(offset: Int?): Long

Read a 64-bit integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readBigUInt64BE(offset: Int?): BigInt

Read a 64-bit unsigned integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readBigUInt64LE(offset: Int?): BigInt

Read a 64-bit unsigned integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readDoubleBE(offset: Int?): Double

Read a 64-bit double-precision floating point value from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readDoubleLE(offset: Int?): Double

Read a 64-bit double-precision floating point value from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readFloatBE(offset: Int?): Float

Read a 32-bit floating point value from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readFloatLE(offset: Int?): Float

Read a 32-bit floating point value from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readInt16BE(offset: Int?): Short

Read a 16-bit integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readInt16LE(offset: Int?): Short

Read a 16-bit integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readInt32BE(offset: Int?): Int

Read a 32-bit integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readInt32LE(offset: Int?): Int

Read a 32-bit integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun readInt8(offset: Int?): Byte

Read an 8-bit integer from the buffer, optionally at an offset.

Link copied to clipboard
open override fun readIntBE(offset: Int, byteLength: Int): Long

Read an integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Big Endian byte order, at the given offset.

Link copied to clipboard
open override fun readIntLE(offset: Int, byteLength: Int): Long

Read an integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Little Endian byte order, at the given offset.

Link copied to clipboard
open fun readUInt16BE(offset: Int?): Int

Read a 16-bit unsigned integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readUInt16LE(offset: Int?): Int

Read a 16-bit unsigned integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readUInt32BE(offset: Int?): Long

Read a 32-bit unsigned integer from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readUInt32LE(offset: Int?): Long

Read a 32-bit unsigned integer from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open fun readUInt8(offset: Int?): Int

Read an 8-bit unsigned integer from the buffer, optionally at an offset.

Link copied to clipboard
open override fun readUIntBE(offset: Int, byteLength: Int): Long

Read an unsigned integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Big Endian byte order, at the given offset.

Link copied to clipboard
open override fun readUIntLE(offset: Int, byteLength: Int): Long

Read an unsigned integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Little Endian byte order, at the given offset.

Link copied to clipboard
open fun remove(index: Long): Boolean
Link copied to clipboard
open override fun removeMember(key: String?): Boolean
Link copied to clipboard
open operator override fun set(index: Long, value: Value?)
Link copied to clipboard
open override fun subarray(start: Int?, end: Int?): BufferInstance

Returns a new Buffer instance as a view of this buffer's contents in the given range. Updates to this buffer's data are visible to the returned instance.

Link copied to clipboard
open override fun swap16(): BufferInstance

Interpret this buffer as containing only 16-bit integers and swap their byte order in-place. If the buffer's byte length is not a multiple of 2, an error will be thrown.

Link copied to clipboard
open override fun swap32(): BufferInstance

Interpret this buffer as containing only 32-bit integers and swap their byte order in-place. If the buffer's byte length is not a multiple of 4, an error will be thrown.

Link copied to clipboard
open override fun swap64(): BufferInstance

Interpret this buffer as containing only 64-bit integers and swap their byte order in-place. If the buffer's byte length is not a multiple of 8, an error will be thrown.

Link copied to clipboard
open override fun toJSON(): PolyglotValue

Returns a JSON object representation of this buffer, with the data rendered into an array of byte values.

Link copied to clipboard
open override fun toString(encoding: String?, start: Int?, end: Int?): String

Decodes the buffer's data as a string using the given encoding.

Link copied to clipboard
open override fun values(): PolyglotValue

Returns an iterable value which yields the buffer's byte values.

Link copied to clipboard
open override fun write(string: String, offset: Int?, length: Int?, encoding: String?): Int

Encode a string and write it into the buffer at the given offset, optionally truncating the resulting bytes to match a specific length.

Link copied to clipboard
open override fun writeBigInt64BE(value: Long, offset: Int?): Int

Write an 64-bit signed integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open override fun writeBigInt64LE(value: Long, offset: Int?): Int

Write an 64-bit signed integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open fun writeBigUInt64BE(value: Long, offset: Int?): Int

Write an 64-bit unsigned integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open fun writeBigUInt64LE(value: Long, offset: Int?): Int

Write an 64-bit unsigned integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open override fun writeDoubleBE(value: Double, offset: Int?): Int

Write a 64-bit double-precision floating point value from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun writeDoubleLE(value: Double, offset: Int?): Int

Write a 64-bit double-precision floating point value from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun writeFloatBE(value: Float, offset: Int?): Int

Write a 32-bit floating point value from the buffer using the Big Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun writeFloatLE(value: Float, offset: Int?): Int

Write a 32-bit floating point value from the buffer using the Little Endian byte order, optionally at an offset.

Link copied to clipboard
open override fun writeInt16BE(value: Short, offset: Int?): Int

Write an 16-bit signed integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open override fun writeInt16LE(value: Short, offset: Int?): Int

Write an 16-bit signed integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open override fun writeInt32BE(value: Int, offset: Int?): Int

Write an 32-bit signed integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open override fun writeInt32LE(value: Int, offset: Int?): Int

Write an 32-bit signed integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open override fun writeInt8(value: Byte, offset: Int?): Int

Write an 8-bit signed integer to the buffer at an offset.

Link copied to clipboard
open override fun writeIntBE(value: Long, offset: Int, byteLength: Int): Int

WRite an integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Big Endian byte order, at the given offset.

Link copied to clipboard
open override fun writeIntLE(value: Long, offset: Int, byteLength: Int): Int

Read an integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Little Endian byte order, at the given offset.

Link copied to clipboard
open fun writeUInt16BE(value: Int, offset: Int?): Int

Write an 16-bit unsigned integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open fun writeUInt16LE(value: Int, offset: Int?): Int

Write an 16-bit unsigned integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open fun writeUInt32BE(value: Long, offset: Int?): Int

Write an 32-bit unsigned integer to the buffer at an offset using Big Endian order.

Link copied to clipboard
open fun writeUInt32LE(value: Long, offset: Int?): Int

Write an 32-bit unsigned integer to the buffer at an offset using Little Endian order.

Link copied to clipboard
open fun writeUInt8(value: Int, offset: Int?): Int

Write an 8-bit unsigned integer to the buffer at an offset.

Link copied to clipboard
open fun writeUIntBE(value: Long, offset: Int, byteLength: Int): Int

Read an unsigned integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Big Endian byte order, at the given offset.

Link copied to clipboard
open fun writeUIntLE(value: Long, offset: Int, byteLength: Int): Int

Read an unsigned integer with the specified byteLength (in bytes, up to 6 bytes/48 bits) using the Little Endian byte order, at the given offset.