SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ByteBuffer provides a compact byte array representation for sending, receiving and processing binary data using WebSocket.
Field Summary | |
Array
|
array
The array property provides byte storage for the buffer. |
Boolean
|
autoExpand
The autoExpand property enables writing variable length data, and is on by default. |
Number
|
capacity
The capacity property indicates the maximum number of bytes of storage available if the buffer is not automatically expanding. |
Number
|
limit
The limit property indicates the last byte of data available for reading. |
ByteOrder
|
order
The order property indicates the endianness of multibyte integer types in the buffer. |
Number
|
position
The position property indicates the progress through the buffer, and indicates the position within the underlying array that subsequent data will be read from or written to. |
Constructor Summary | |
ByteBuffer(bytes)
Creates a new ByteBuffer instance. |
Method Summary | |
<static>
ByteBuffer
|
allocate(capacity)
Allocates a new ByteBuffer instance. |
ByteBuffer
|
clear()
Clears the buffer. |
ByteBuffer
|
compact()
Compacts the buffer by removing leading bytes up to the buffer position, and decrements the limit and position values accordingly. |
ByteBuffer
|
duplicate()
Duplicates the buffer by reusing the underlying byte array but with independent position, limit and capacity. |
ByteBuffer
|
expand(expectedRemaining)
Expands the buffer to support the expected number of remaining bytes after the current position. |
ByteBuffer
|
expandAt(i, expectedRemaining)
Expands the buffer to support the expected number of remaining bytes at the specified index. |
ByteBuffer
|
fill(size)
Fills the buffer with a repeated number of zeros. |
ByteBuffer
|
fillWith(b, size)
Fills the buffer with a specific number of repeated bytes. |
ByteBuffer
|
flip()
Flips the buffer. |
Number
|
get()
Returns a single-byte number from the buffer at the current position. |
ArrayBuffer
|
getArrayBuffer(size)
Returns a ArrayBuffer from the buffer at the current position. |
Number
|
getAt(index)
Returns a single-byte number from the buffer at the specified index. |
Blob
|
getBlob(size)
Returns a Blob from the buffer at the current position. |
Blob
|
getBlobAt(index, size)
Returns a Blob from the buffer at the specified index. |
Array
|
getBytes(index, size)
Returns a n-byte number from the buffer at the specified index. |
Array
|
getBytes(size)
Returns a n-byte number from the buffer at the current position. |
String
|
getHexDump()
Returns a hex dump of this buffer. |
Number
|
getInt()
Returns a four-byte number from the buffer at the current position. |
Number
|
getIntAt(index)
Returns a four-byte number from the buffer at the specified index. |
Number
|
getMediumInt()
Returns a three-byte number from the buffer at the current position. |
Number
|
getMediumIntAt(i)
Returns a three-byte number from the buffer at the specified index. |
String
|
getPrefixedString(fieldSize, cs)
Returns a length-prefixed string from the buffer at the current position. |
Number
|
getShort()
Returns a two-byte number from the buffer at the current position. |
Number
|
getShortAt(index)
Returns a two-byte number from the buffer at the specified index. |
String
|
getString(cs)
Returns a string from the buffer at the current position. |
Number
|
getUnsigned()
Returns an unsigned single-byte number from the buffer at the current position. |
|
getUnsignedAt(index)
Returns an unsigned single-byte number from the buffer at the specified index. |
Number
|
getUnsignedInt()
Returns an unsigned four-byte number from the buffer at the current position. |
Number
|
getUnsignedIntAt(index)
Returns an unsigned four-byte number from the buffer at the specified position. |
Number
|
getUnsignedMediumInt()
Returns an unsigned three-byte number from the buffer at the current position. |
Number
|
getUnsignedShort()
Returns an unsigned two-byte number from the buffer at the current position. |
|
getUnsignedShortAt()
Returns an unsigned two-byte number from the buffer at the specified index. |
Boolean
|
hasRemaining()
Returns true if this buffer has remaining bytes, false otherwise. |
Number
|
indexOf(b)
Returns the index of the specified byte in the buffer. |
ByteBuffer
|
mark()
Marks a position in the buffer. |
ByteBuffer
|
put(v)
Puts a single byte number into the buffer at the current position. |
ByteBuffer
|
putAt(index, v)
Puts a single byte number into the buffer at the specified index. |
ByteBuffer
|
putBuffer(v)
Puts a buffer into the buffer at the current position. |
ByteBuffer
|
putBufferAt(index, v)
Puts a buffer into the buffer at the specified index. |
ByteBuffer
|
putByteArray(v)
Puts a ByteArray into the buffer at the current position. |
ByteBuffer
|
putBytes(v)
Puts a single-byte array into the buffer at the current position. |
ByteBuffer
|
putBytesAt(index, v)
Puts a byte array into the buffer at the specified index. |
ByteBuffer
|
putInt(v)
Puts a four-byte number into the buffer at the current position. |
ByteBuffer
|
putIntAt(index, v)
Puts a four-byte number into the buffer at the specified index. |
ByteBuffer
|
putMediumInt(v)
Puts a three-byte number into the buffer at the current position. |
ByteBuffer
|
putMediumIntAt(index, v)
Puts a three-byte number into the buffer at the specified index. |
ByteBuffer
|
putPrefixedString(fieldSize, v, cs)
Puts a string into the buffer at the specified index, using the character set to encode the string as bytes. |
ByteBuffer
|
putShort(v)
Puts a two-byte short into the buffer at the current position. |
ByteBuffer
|
putShortAt(index, v)
Puts a two-byte short into the buffer at the specified index. |
ByteBuffer
|
putString(v, cs)
Puts a string into the buffer at the current position, using the character set to encode the string as bytes. |
ByteBuffer
|
putUnsigned(v)
Puts an unsigned single-byte number into the buffer at the current position. |
ByteBuffer
|
putUnsignedAt(index, v)
Puts an unsigned single byte into the buffer at the specified position. |
ByteBuffer
|
putUnsignedInt(i)
Puts an unsigned four-byte number into the buffer at the current position. |
ByteBuffer
|
putUnsignedIntAt(index, v)
Puts an unsigned four-byte number into the buffer at the specified index. |
ByteBuffer
|
putUnsignedShort(v)
Puts a two-byte unsigned short into the buffer at the current position. |
ByteBuffer
|
putUnsignedShort(v)
Puts a two-byte unsigned short into the buffer at the current position. |
Number
|
remaining()
Returns the number of bytes remaining from the current position to the limit. |
ByteBuffer
|
reset()
Resets the buffer position using the mark. |
ByteBuffer
|
rewind()
Rewinds the buffer. |
ByteBuffer
|
skip(size)
Skips the specified number of bytes from the current position. |
ByteBuffer
|
slice()
Returns a sliced buffer, setting the position to zero, and decrementing the limit accordingly. |
String
|
toString()
Returns the string representation of this buffer. |
<static>
ByteBuffer
|
wrap(bytes)
Wraps a byte array as a new ByteBuffer instance. |
Field Detail |
Array array
Boolean autoExpand
Number capacity
Number limit
ByteOrder order
Number position
Constructor Detail |
ByteBuffer(bytes)
Array bytes
- the byte-valued Number array
Method Detail |
<static> ByteBuffer allocate(capacity)
Number capacity
- the maximum buffer capacity
ByteBuffer
the allocated ByteBuffer
ByteBuffer clear()
ByteBuffer
the buffer
ByteBuffer compact()
ByteBuffer
the buffer
ByteBuffer duplicate()
ByteBuffer
the duplicated buffer
ByteBuffer expand(expectedRemaining)
expectedRemaining
- {Number} the expected number of remaining bytes
ByteBuffer
the buffer
ByteBuffer expandAt(i, expectedRemaining)
i
- {Number} the index
expectedRemaining
- {Number} the expected number of remaining bytes
ByteBuffer
the buffer
ByteBuffer fill(size)
size
- {Number} the number of zeros to repeat
ByteBuffer
the buffer
ByteBuffer fillWith(b, size)
b
- {Number} the byte to repeat
size
- {Number} the number of times to repeat
ByteBuffer
the buffer
ByteBuffer flip()
ByteBuffer
the flipped buffer
Number get()
Number
the single-byte number
ArrayBuffer getArrayBuffer(size)
size
- {Number} size the size of the ArrayBuffer to be returned
ArrayBuffer
a new ArrayBuffer with bytes read from the buffer
Number getAt(index)
index
- {Number} the index
Number
the single-byte number
Blob getBlob(size)
size
- {Number} size the size of the Blob to be returned
Blob
a new Blob with bytes read from the buffer
Blob getBlobAt(index, size)
index
- {Number} the index
size
- {Number} size the size of the Blob to be returned
Blob
a new Blob with bytes read from the buffer
Array getBytes(index, size)
index
- {Number} the index
size
- {Number} size the size of the buffer to be returned
Array
a new byte array with bytes read from the buffer
Array getBytes(size)
size
- {Number} size the size of the buffer to be returned
Array
a new byte array with bytes read from the buffer
String getHexDump()
String
the hex dump
Number getInt()
Number
the four-byte number
Number getIntAt(index)
index
- {Number} the index
Number
the four-byte number
Number getMediumInt()
Number
the three-byte number
Number getMediumIntAt(i)
i
- {Number} the index
Number
the three-byte number
String getPrefixedString(fieldSize, cs)
fieldSize
- {Number} the width in bytes of the prefixed length field
cs
- {Charset} the character set
String
the length-prefixed string
Number getShort()
Number
the two-byte number
Number getShortAt(index)
index
- {Number} the index
Number
the two-byte number
String getString(cs)
cs
- {Charset} the character set
String
the string
Number getUnsigned()
Number
the unsigned single-byte number
getUnsignedAt(index)
index
- the index
the unsigned single-byte number
Number getUnsignedInt()
Number
the unsigned four-byte number
Number getUnsignedIntAt(index)
index
- the index
Number
the unsigned four-byte number
Number getUnsignedMediumInt()
Number
the unsigned three-byte number
Number getUnsignedShort()
Number
the unsigned two-byte number
getUnsignedShortAt()
the unsigned two-byte number
Boolean hasRemaining()
Boolean
whether this buffer has remaining bytes
Number indexOf(b)
b
- {Number} the byte to find
Number
the index of the byte in the buffer, or -1 if not found
ByteBuffer mark()
ByteBuffer
the buffer
ByteBuffer put(v)
v
- {Number} the single-byte number
ByteBuffer
the buffer
ByteBuffer putAt(index, v)
index
- {Number} the index
v
- {Number} the byte
ByteBuffer
the buffer
ByteBuffer putBuffer(v)
v
- {Array} the single-byte array
ByteBuffer
the buffer
ByteBuffer putBufferAt(index, v)
index
- {Number} the index
v
- {Array} the single-byte array
ByteBuffer
the buffer
ByteBuffer putByteArray(v)
v
- {ByteArray} the ByteArray
ByteBuffer
the buffer
ByteBuffer putBytes(v)
v
- {Array} the single-byte array
ByteBuffer
the buffer
ByteBuffer putBytesAt(index, v)
index
- {Number} the index
v
- {Array} the single-byte array
ByteBuffer
the buffer
ByteBuffer putInt(v)
v
- {Number} the four-byte number
ByteBuffer
the buffer
ByteBuffer putIntAt(index, v)
index
- {Number} the index
v
- {Number} the four-byte number
ByteBuffer
the buffer
ByteBuffer putMediumInt(v)
v
- {Number} the three-byte number
ByteBuffer
the buffer
ByteBuffer putMediumIntAt(index, v)
index
- {Number} the index
v
- {Number} the three-byte number
ByteBuffer
the buffer
ByteBuffer putPrefixedString(fieldSize, v, cs)
fieldSize
- {Number} the width in bytes of the prefixed length field
v
- {String} the string
cs
- {Charset} the character set
ByteBuffer
the buffer
ByteBuffer putShort(v)
v
- {Number} the two-byte number
ByteBuffer
the buffer
ByteBuffer putShortAt(index, v)
index
- {Number} the index
v
- {Number} the two-byte number
ByteBuffer
the buffer
ByteBuffer putString(v, cs)
v
- {String} the string
cs
- {Charset} the character set
ByteBuffer
the buffer
ByteBuffer putUnsigned(v)
v
- {Number} the single-byte number
ByteBuffer
the buffer
ByteBuffer putUnsignedAt(index, v)
index
- {Number} the index
v
- {Number} the single-byte number
ByteBuffer
the buffer
ByteBuffer putUnsignedInt(i)
i
- {Number} the index
ByteBuffer
the buffer
ByteBuffer putUnsignedIntAt(index, v)
index
- {Number} the index
v
- {Number} the four-byte number
ByteBuffer
the buffer
ByteBuffer putUnsignedShort(v)
v
- {Number} the two-byte number
ByteBuffer
the buffer
ByteBuffer putUnsignedShort(v)
v
- {Number} the two-byte number
ByteBuffer
the buffer
Number remaining()
Number
the number of bytes remaining
ByteBuffer reset()
ByteBuffer
the buffer
Error
if the mark is invalid
ByteBuffer rewind()
ByteBuffer
the buffer
ByteBuffer skip(size)
size
- {Number} the number of bytes to skip
ByteBuffer
the buffer
ByteBuffer slice()
ByteBuffer
the sliced buffer
String toString()
String
the string representation
<static> ByteBuffer wrap(bytes)
Array bytes
- an array of byte-sized numbers
ByteBuffer
the bytes wrapped as a ByteBuffer