Constructor
new Byte(dataopt)
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
bytesAvailable :int
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
Methods
clear()
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
getFloat32() → {Number}
Returns:
- Type:
-
Number
getFloat32Array(start, len) → {Object}
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
getFloat64() → {Number}
Returns:
- Type:
-
Number
getInt16() → {int}
Returns:
- Type:
-
int
getInt16Array(start, len) → {Object}
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
getInt32() → {int}
Returns:
- Type:
-
int
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
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
getUint8() → {uint}
Returns:
- Type:
-
uint
getUint8Array(start, len) → {Uint8Array}
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
getUint16() → {uint}
Returns:
- Type:
-
uint
getUint32() → {uint}
Returns:
- Type:
-
uint
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
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
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)
Parameters:
Name | Type | Description |
---|---|---|
value |
Number
|
Single precision (32 bit) floating point numbers. |
writeFloat64(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
Number
|
Double precision (64 bit) floating point number. |
writeInt16(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
int
|
The Int16 value to write to. |
writeInt32(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
int
|
The Int32 value to write to. |
writeUint8(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
int
|
The Uint8 value to write to. |
writeUint16(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
int
|
The Uint16 value to write to. |
writeUint32(value)
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. |