Class: ByteArray
Constructors
constructor
• new ByteArray(buff?): ByteArray
Constructor.
Parameters
| Name | Type |
|---|---|
buff? | number[] | Buffer |
Returns
Example
const packet = new ByteArray();
Properties
buffer
• buffer: Buffer
readPosition
• readPosition: number
writePosition
• writePosition: number
Accessors
[toStringTag]
• get [toStringTag](): string
Returns
string
bytesAvailable
• get bytesAvailable(): number
Returns
number
length
• get length(): number
Returns
number
Methods
XXTEA
▸ XXTEA(v, n, k): number[]
Parameters
| Name | Type |
|---|---|
v | number[] |
n | number |
k | number[] |
Returns
number[]
blockCipher
▸ blockCipher(keys): ByteArray
Cipher the packet with the XXTEA algorithm.
Parameters
| Name | Type |
|---|---|
keys | number[] |
Returns
clear
▸ clear(): void
Clears the contents of the bytearray and resets the length and positions properties to 0.
Returns
void
expand
▸ expand(value): void
Expands the buffer
Parameters
| Name | Type |
|---|---|
value | number |
Returns
void
readBoolean
▸ readBoolean(): boolean
Reads a Boolean value from the byte stream.
Returns
boolean
readBufBytes
▸ readBufBytes(length): Buffer
Reads a buffer of bytes, specified by the length parameter, from the byte stream.
Parameters
| Name | Type |
|---|---|
length | number |
Returns
Buffer
readByte
▸ readByte(): number
Reads a signed byte from the byte stream.
Returns
number
readInt
▸ readInt(): number
Reads a signed 32-bit integer from the byte stream.
Returns
number
readShort
▸ readShort(): number
Reads a signed 16-bit integer from the byte stream.
Returns
number
readUTF
▸ readUTF(): string
Reads a UTF-8 string from the byte stream.
Returns
string
readUnsignedByte
▸ readUnsignedByte(): number
Reads an unsigned byte from the byte stream.
Returns
number
readUnsignedInt
▸ readUnsignedInt(): number
Reads an unsigned 32-bit integer from the byte stream.
Returns
number
readUnsignedShort
▸ readUnsignedShort(): number
Reads an unsigned 16-bit integer from the byte stream.
Returns
number
toJSON
▸ toJSON(): number[]
Returns
number[]
toString
▸ toString(encodingOrFormat): string
Converts the byte array to a string representation.
Parameters
| Name | Type |
|---|---|
encodingOrFormat | BufferEncoding | "printable" |
Returns
string
write
▸ write(data): ByteArray
Adds data to the buffer.
Parameters
| Name | Type |
|---|---|
data | string | ByteArray | Buffer | SharedArrayBuffer |
Returns
writeBoolean
▸ writeBoolean(value): ByteArray
Writes a Boolean value.
Parameters
| Name | Type |
|---|---|
value | boolean |
Returns
writeBufBytes
▸ writeBufBytes(data): ByteArray
Writes a sequence of bytes from the specified buffer into the byte stream.
Parameters
| Name | Type |
|---|---|
data | Buffer |
Returns
writeByte
▸ writeByte(value): ByteArray
Writes a byte to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
writeBytes
▸ writeBytes(bytes, offset?, length?): ByteArray
Writes a sequence of length bytes from the specified byte array, bytes, starting offset bytes into the byte stream.
Parameters
| Name | Type | Default value |
|---|---|---|
bytes | ByteArray | undefined |
offset | number | 0 |
length | number | 0 |
Returns
writeInt
▸ writeInt(value): ByteArray
Writes a 32-bit signed integer to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
writeShort
▸ writeShort(value): ByteArray
Writes a 16-bit integer to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
writeUTF
▸ writeUTF(value): ByteArray
Writes a UTF-8 string to the byte stream.
Parameters
| Name | Type |
|---|---|
value | string |
Returns
writeUnsignedByte
▸ writeUnsignedByte(value): ByteArray
Writes a unsigned byte to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
writeUnsignedInt
▸ writeUnsignedInt(value): ByteArray
Writes a 32-bit unsigned integer to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
writeUnsignedShort
▸ writeUnsignedShort(value): ByteArray
Writes a 16-bit unsigned integer to the byte stream.
Parameters
| Name | Type |
|---|---|
value | number |
Returns
xorCipher
▸ xorCipher(keys, fingerprint): ByteArray
Cipher the packet with the XOR algorithm.
Parameters
| Name | Type |
|---|---|
keys | number[] |
fingerprint | number |