APIs

Show:

a BinaryStreamSizeCalculator can be used to quickly evaluate the required size of a buffer by performing the same sequence of write operation.

a BinaryStreamSizeCalculator has the same writeXXX methods as the BinaryStream stream object.

Constructor

BinaryStreamSizeCalculator

()

Methods

BinaryStream.rewind

()

set the cursor to the begining of the stream

Returns:

null

calculateByteLength calculate the size in bytes of a utf8 string

(
  • str
)

Parameters:

  • str String

decodeArray

(
  • stream
  • decode_element_func
)
Array

Parameters:

  • stream BinaryStream

    the stream.

  • decode_element_func Function

    The function to decode a single array element. This function returns the element decoded from the stream

Returns:

Array:

encodeArray

(
  • arr
  • stream
  • encode_element_func
)

Parameters:

  • arr Array

    the array to encode.

  • stream BinaryStream

    the stream.

  • encode_element_func Function

    The function to encode a single array element.

getRandomInt

(
  • min
  • max
)
private

return a random float value in the range of min inclusive and max exclusive

Parameters:

  • min Object
  • max Object

Returns:

:

readArrayBuffer

(
  • length
)
Uint8Array

Parameters:

  • length Object

Returns:

Uint8Array:

readByte

() Number

read a single signed byte (8 bits) from the stream.

Returns:

Number:

readByteStream

() Buffer

read a byte stream to the stream. The method reads the length of the byte array from the stream as a 32 bits integer before reading the byte stream.

Returns:

Buffer:

readDouble

()

read a single 64-bit floating point number from the stream.

Returns:

the value read from the stream

readFloat

()

read a single 32-bit floating point number from the stream.

Returns:

the value read from the stream

readInt16

() Number

read a single signed 16-bit integer from the stream.

Returns:

Number:

readInteger

() Number

read a single signed 32-bit integer from the stream.

Returns:

Number:

readUInt16

() Number

read a single unsigned 16-bit integer from the stream.

Returns:

Number:

q

readUInt32

() Number

read a single unsigned 32-bit integer from the stream.

Returns:

Number:

the value read from the stream

readUInt8

() Number

read a single unsigned byte (8 bits) from the stream.

Returns:

Number:

writeArrayBuffer

(
  • arrayBuf
  • offset
  • length
)

Parameters:

  • arrayBuf ArrayBuffer
  • offset Number
  • length Number

writeByteStream

(
  • buf
)

write a byte stream to the stream. The method writes the length of the byte array into the stream as a 32 bits integer before the byte stream.

Parameters:

  • buf Buffer

    the buffer to write. the buffer buf.length the buffer to write

writeDouble

(
  • value
)

write a single 64 bit floating number to the stream.

Parameters:

  • value Object

writeFloat

(
  • value
)

write a single 32 bit floating number to the stream.

Parameters:

  • value Object

writeInt16

(
  • value
)

write a single 16 bit signed integer to the stream.

Parameters:

  • value Object

writeInt8

(
  • value
)

write a single signed byte (8 bits) to the stream. value must be in the range of [-127,128]

Parameters:

  • value Object

writeInteger

(
  • value
)

write a single 32 bit signed integer to the stream.

Parameters:

  • value Object

writeUInt16

(
  • value
)

write a single 16 bit unsigned integer to the stream.

Parameters:

  • value Object

writeUInt32

(
  • value
)

write a single 32 bit unsigned integer to the stream.

Parameters:

  • value Object

writeUInt8

(
  • value
)

write a single unsigned byte (8 bits) to the stream.

Parameters:

  • value Object