ParsableBitArray
@UnstableApi
@CheckReturnValue
class ParsableBitArray
Wraps a byte array, providing methods that allow it to be read as a bitstream.
Summary
Public constructors |
|---|
|
Creates a new instance that initially has no backing data. |
ParsableBitArray(data: ByteArray!)Creates a new instance that wraps an existing array. |
ParsableBitArray(data: ByteArray!, limit: Int)Creates a new instance that wraps an existing array. |
Public functions |
|
|---|---|
Int |
bitsLeft()Returns the number of bits yet to be read. |
Unit |
Aligns the position to the next byte boundary. |
Int |
Returns the current byte offset. |
Int |
Returns the current bit offset. |
Unit |
Overwrites |
Boolean |
readBit()Reads a single bit. |
Int |
Reads up to 32 bits. |
Unit |
Reads |
Long |
readBitsToLong(numBits: Int)Reads up to 64 bits. |
Unit |
Reads the next |
String! |
readBytesAsString(length: Int)Reads the next |
String! |
readBytesAsString(length: Int, charset: Charset!)Reads the next |
Unit |
Updates the instance to wrap |
Unit |
reset(parsableByteArray: ParsableByteArray!)Sets this instance's data, position and limit to match the provided |
Unit |
Updates the instance to wrap |
Unit |
setPosition(position: Int)Sets the current bit offset. |
Unit |
skipBit()Skips a single bit. |
Unit |
Skips bits and moves current reading position forward. |
Unit |
Skips the next |
Public constructors
ParsableBitArray
ParsableBitArray(data: ByteArray!)
Creates a new instance that wraps an existing array.
| Parameters | |
|---|---|
data: ByteArray! |
The data to wrap. |
ParsableBitArray
ParsableBitArray(data: ByteArray!, limit: Int)
Creates a new instance that wraps an existing array.
Public functions
byteAlign
fun byteAlign(): Unit
Aligns the position to the next byte boundary. Does nothing if the position is already aligned.
getBytePosition
fun getBytePosition(): Int
Returns the current byte offset. Must only be called when the position is byte aligned.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the position isn't byte aligned. |
putInt
fun putInt(value: Int, numBits: Int): Unit
Overwrites numBits from this array using the numBits least significant bits from value. Bits are written in order from most significant to least significant. The read position is advanced by numBits.
readBits
fun readBits(numBits: Int): Int
Reads up to 32 bits.
| Parameters | |
|---|---|
numBits: Int |
The number of bits to read. |
| Returns | |
|---|---|
Int |
An integer whose bottom |
readBits
fun readBits(buffer: ByteArray!, offset: Int, numBits: Int): Unit
Reads numBits bits into buffer.
| Parameters | |
|---|---|
buffer: ByteArray! |
The array into which the read data should be written. The trailing |
offset: Int |
The offset in |
numBits: Int |
The number of bits to read. |
readBitsToLong
fun readBitsToLong(numBits: Int): Long
Reads up to 64 bits.
| Parameters | |
|---|---|
numBits: Int |
The number of bits to read. |
| Returns | |
|---|---|
Long |
A long whose bottom |
readBytes
fun readBytes(buffer: ByteArray!, offset: Int, length: Int): Unit
Reads the next length bytes into buffer. Must only be called when the position is byte aligned.
| Parameters | |
|---|---|
buffer: ByteArray! |
The array into which the read data should be written. |
offset: Int |
The offset in |
length: Int |
The number of bytes to read. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the position isn't byte aligned. |
| See also | |
|---|---|
arraycopy |
readBytesAsString
fun readBytesAsString(length: Int): String!
Reads the next length bytes as a UTF-8 string. Must only be called when the position is byte aligned.
| Parameters | |
|---|---|
length: Int |
The number of bytes to read. |
| Returns | |
|---|---|
String! |
The string encoded by the bytes in UTF-8. |
readBytesAsString
fun readBytesAsString(length: Int, charset: Charset!): String!
Reads the next length bytes as a string encoded in Charset. Must only be called when the position is byte aligned.
| Parameters | |
|---|---|
length: Int |
The number of bytes to read. |
charset: Charset! |
The character set of the encoded characters. |
| Returns | |
|---|---|
String! |
The string encoded by the bytes in the specified character set. |
reset
fun reset(data: ByteArray!): Unit
Updates the instance to wrap data, and resets the position to zero.
| Parameters | |
|---|---|
data: ByteArray! |
The array to wrap. |
reset
fun reset(parsableByteArray: ParsableByteArray!): Unit
Sets this instance's data, position and limit to match the provided parsableByteArray. Any modifications to the underlying data array will be visible in both instances
| Parameters | |
|---|---|
parsableByteArray: ParsableByteArray! |
The |
reset
fun reset(data: ByteArray!, limit: Int): Unit
Updates the instance to wrap data, and resets the position to zero.
setPosition
fun setPosition(position: Int): Unit
Sets the current bit offset.
| Parameters | |
|---|---|
position: Int |
The position to set. |
skipBits
fun skipBits(numBits: Int): Unit
Skips bits and moves current reading position forward.
| Parameters | |
|---|---|
numBits: Int |
The number of bits to skip. |
skipBytes
fun skipBytes(length: Int): Unit
Skips the next length bytes. Must only be called when the position is byte aligned.
| Parameters | |
|---|---|
length: Int |
The number of bytes to read. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the position isn't byte aligned. |