Core. Byte

Byte Class provides methods and properties for optimizing reads, writes, and processing binary data.

Be careful: Byte Classes apply to high-level developers who need access to data at the byte level.

Constructor

new Byte(dataopt)

Create a Byte Class instance.
Parameters:
Name Type Attributes Default Description
data Object <optional>
null data Specifies the number of elements to initialize, or the TypedArray object, ArrayBuffer object, used for initialization. If NULL, a certain amount of memory space is pre allocated, and when the available space is insufficient, this part of memory is used preferentially, and if not enough, the memory needed is redistributed.

Member

(static) BIG_ENDIAN :String

Default Value:
  • "bigEndian"

(static) LITTLE_ENDIAN :String

Default Value:
  • "littleEndian"

buffer :ArrayBuffer

Gets the ArrayBuffer data for this object, which contains only valid data parts.

bytesAvailable :int

The number of bytes that can be read from the current position of the byte stream to the end.

endian :String

Byte Byte order of an instance. Value as: BIG_ENDIAN or BIG_ENDIAN .

The host byte order, are two different sequence of CPU stored data, including little endian and big endian. adopt getSystemEndian You can get the byte order of the current system.

BIG_ENDIAN Address: big endian, low storage value high, high value and low storage. Sometimes called a network byte order. < LITTLE_ENDIAN

length :int

pos :int

Move or return Byte The current position (in bytes) of the read and write pointer of an object. The next call to read the method will start reading at this location, or when the next call is written to the method, it will start writing at this location.

Methods

clear()

Clears the contents of the byte array and resets the length and POS attributes to 0. Call this method will release Byte Memory occupied by an instance.

ensureWrite(lengthToEnsure)

Ensure that the length of the byte stream is not less than the available length lengthToEnsure Parameter specified value.

Parameters:
Name Type Description
lengthToEnsure int Specified length.

getByte() → {int}

Reads signed bytes from a byte stream.

The range of return values is from -128 to 127.

Returns:
Type:
int
An integer between -128 and 127.

getFloat32() → {Number}

Reads a IEEE 754 single precision (32 bit) floating-point from the current byte offset of the byte stream.
Returns:
Type:
Number
Single precision (32 bit) floating point numbers.

getFloat32Array(start, len) → {Object}

From byte stream start Parameter specifies the location to start and read len The number of bytes specified by the parameter, used to create one Float32Array Object and return this object.
Parameters:
Name Type Description
start int Starting position.
len int The length of bytes to read. If the length of the read exceeds the readable range, only the value in the readable range is returned.
Returns:
Type:
Object
The Float32Array object to read.

getFloat64() → {Number}

Reads a IEEE 754 double precision (64 bit) float from the current byte offset of the byte stream.
Returns:
Type:
Number
Double precision (64 bit) floating point number.

getInt16() → {int}

Reads a Int16 value from the current byte offset position of the byte stream.
Returns:
Type:
int
Int16 value.

getInt16Array(start, len) → {Object}

From byte stream start Parameter specifies the location to start and read len The number of bytes specified by the parameter, used to create one Int16Array Object and return this object.
Parameters:
Name Type Description
start int The byte offset position to start reading.
len int The length of bytes to read. If the length of the read exceeds the readable range, only the value in the readable range is returned.
Returns:
Type:
Object
The Uint8Array object to read.

getInt32() → {int}

Reads a Int32 value from the current byte offset position of the byte stream.
Returns:
Type:
int
Int32 value.

getString() → {String}

A stream of bytes commonly used to parse fixed formats.

First read a byte from the current byte offset of the byte stream Uint16 Value, and then read the string of this length as the length of this value.

Returns:
Type:
String
String to read.

getSystemEndian() → {String}

Gets the order of bytes for the current host.

The host byte order, are two different sequence of CPU stored data, including little endian and big endian.

BIG_ENDIAN Address: big endian, low storage value high, high value and low storage. Sometimes called a network byte order. < LITTLE_ENDIAN

Returns:
Type:
String
The current system byte order.

getUint8() → {uint}

Reads a Uint8 value from the current byte offset position of the byte stream.
Returns:
Type:
uint
Uint8 value.

getUint8Array(start, len) → {Uint8Array}

From byte stream start Parameter specifies the location to start and read len The number of bytes specified by the parameter, used to create one Uint8Array Object and return this object.
Parameters:
Name Type Description
start int Starting position.
len int The length of bytes to read. If the length of the read exceeds the readable range, only the value in the readable range is returned.
Returns:
Type:
Uint8Array
The Uint8Array object to read.

getUint16() → {uint}

Reads a Uint16 value from the current byte offset position of the byte stream.
Returns:
Type:
uint
Uint16 value.

getUint32() → {uint}

Reads a Uint32 value from the current byte offset position of the byte stream.
Returns:
Type:
uint
Uint32 value.

getUTFBytes(len) → {String}

Reads a UTF-8 byte sequence specified by the length parameter from the byte stream and returns a string.

Normally read is a string written by the writeUTFBytes method.

Parameters:
Name Type Description
len int The length of the buffer to read, and the default will read all the data for the buffer.
Returns:
Type:
String
String to read.

getUTFString() → {String}

Reads a UTF-8 string from the byte stream. Suppose the prefix of a string is a unsigned short integer (in bytes indicating the length to read).

The corresponding write method is: writeUTFString.

Returns:
Type:
String
String to read.

writeArrayBuffer(arraybuffer, offsetopt, lengthopt)

Writes a byte sequence in the specified arraybuffer object with offset as the start offset and length as the length.

If the length parameter is omitted, the default length 0 is used, and the method starts writing the entire buffer from the offset; if the offset parameter is omitted, the entire buffer is written.

If offset or length is less than 0, this function throws an exception.

$NEXTBIG because of legitimacy without judgment, length and arraybuffer, when developers fill in the wrong length value, will cause a write blank data redundant and even memory overflow, in order to avoid the influence of developers are using this method, the next major version will fix these problems.
Parameters:
Name Type Attributes Default Description
arraybuffer Object The Arraybuffer object to write to.
offset uint <optional>
0 offset Offset (in bytes) of the index of the Arraybuffer object
length uint <optional>
0 length Writes from the Arraybuffer object to Byte Object length (in bytes)

writeByte(value)

Writes a byte in a byte stream.

Use the low 8 bits of the parameter. Ignore the high 24 bit.

Parameters:
Name Type Description
value int

writeFloat32(value)

Writes a IEEE 754 single precision (32 bit) floating-point number at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value Number Single precision (32 bit) floating point numbers.

writeFloat64(value)

A IEEE 754 double precision (64 bit) floating-point number is written at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value Number Double precision (64 bit) floating point number.

writeInt16(value)

Writes the specified Int16 value at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value int The Int16 value to write to.

writeInt32(value)

Writes the specified Int32 value at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value int The Int32 value to write to.

writeUint8(value)

Writes the specified Uint8 value at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value int The Uint8 value to write to.

writeUint16(value)

Writes the specified Uint16 value at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value int The Uint16 value to write to.

writeUint32(value)

Writes the Uint32 value at the current byte offset position of the byte stream.
Parameters:
Name Type Description
value int The Uint32 value to write to.

writeUTFBytes(value)

Writes a UTF-8 string to a byte stream. Similar to the writeUTF () method, but writeUTFBytes () does not use 16 bit length words to prefix the strings.

The corresponding read method is: getUTFBytes.

Parameters:
Name Type Description
value String String to write to.

writeUTFString(value)

Writes a UTF-8 string to a byte stream. First write the length of the UTF-8 string represented by bytes (as the 16 bit integer), and then write the bytes that represent string characters.

The corresponding read method is: getUTFString.

Parameters:
Name Type Description
value String The string value to write to.