SFSArray

Specialized array used by SmartFoxServer for client-server data transfer.


This class can be thought of as a specialized Array that can contain any type of data.

The advantage of using the SFSArray class (for example as a nested object inside a SFSObject) is that you can fine tune the way your data is transmitted over the network. For instance, when transmitting a list of numbers between 0 and 100, those values can be treated as normal integers (which take 32 bits each), but also as shorts (16 bit) or even as bytes (8 bit).

SFSArray supports many primitive data types and their relative arrays (see the SFSDataType class) and nested objects.

Constructor

new SFSArray()

Creates a new instance of the SFSArray class.

Methods

addBool(value)

Appends a boolean value to the end of the array.
Parameters:
NameTypeDescription
valuebooleanThe value to be appended to the array.

addBoolArray(array)

Appends an array of boolean values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<boolean>The array of booleans to be appended to the array.

addByte(value)

Appends a byte (8 bits) value to the end of the array.
Parameters:
NameTypeDescription
valuenumberThe value to be appended to the array.

addByteArray(array)

Appends a byte array to the end of the array.
Parameters:
NameTypeDescription
arrayUint8ArrayThe byte array to be appended to the array.

addDouble(value)

Appends a double precision number (64 bits) value to the end of the array.
Parameters:
NameTypeDescription
valuenumberThe value to be appended to the array.

addDoubleArray(array)

Appends an array of double precision number values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<number>The array of doubles to be appended to the array.

addFloat(value)

Appends a floating point number (32 bits) value to the end of the array.
Parameters:
NameTypeDescription
valuenumberThe value to be appended to the array.

addFloatArray(array)

Appends an array of floating point number values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<number>The array of floats to be appended to the array.

addInt(value)

Appends an integer (32 bits) value to the end of the array.
Parameters:
NameTypeDescription
valuenumberThe value to be appended to the array.

addIntArray(array)

Appends an array of integer values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<number>The array of integers to be appended to the array.

addLong(value)

Appends a long integer (64 bits) value to the end of the array.

IMPORTANT: in this API, long integers are represented by BigInt values, but SmartFoxServer supports long integers up to 64-bit signed. Make sure to take this limitation (and others, see BigInt documentation) into account when dealing with long integers.

Parameters:
NameTypeDescription
valuenumber | bigintThe value to be appended to the array.

addLongArray(array)

Appends an array of long integer values to the end of the array.

IMPORTANT: in this API, long integers are represented by BigInt values, but SmartFoxServer supports long integers up to 64-bit signed. Make sure to take this limitation (and others, see BigInt documentation) into account when dealing with long integers.

Parameters:
NameTypeDescription
arrayArray.<number> | Array.<bigint>The array of longs to be appended to the array.

addNull()

Appends a null value to the end of the array.

addSFSArray(value)

Appends an SFSArray object to the end of the array.
Parameters:
NameTypeDescription
valueSFSArrayThe SFSArray to be appended to the array.

addSFSObject(value)

Appends an SFSObject object to the end of the array.
Parameters:
NameTypeDescription
valueSFSObjectThe SFSObject to be appended to the array.

addShort(value)

Appends a short integer (16 bits) value to the end of the array.
Parameters:
NameTypeDescription
valuenumberThe value to be appended to the array.

addShortArray(array)

Appends an array of short integer values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<number>The array of shorts to be appended to the array.

addShortString(value)

Appends a UTF-8 string (with max length of 255 bytes) value to the end of the array.
Parameters:
NameTypeDescription
valuestringThe value to be appended to the array.

addShortStringArray(array)

Appends an array of short UTF-8 string values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<string>The array of strings to be appended to the array.

addString(value)

Appends a UTF-8 string (with max length of 32767 bytes) value to the end of the array.
Parameters:
NameTypeDescription
valuestringThe value to be appended to the array.

addStringArray(array)

Appends an array of UTF-8 string values to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<string>The array of strings to be appended to the array.

addText(value)

Appends a UTF-8 string (with max length of 2 GBytes) value to the end of the array.
Parameters:
NameTypeDescription
valuestringThe value to be appended to the array.

addVector2(value)

Appends a SFSVector2 object to the end of the array.
Parameters:
NameTypeDescription
valueSFSVector2The SFSVector2 to be appended to the array.

addVector2Array(array)

Appends an array of SFSVector2 objects to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<SFSVector2>The array of SFSVector2 to be appended to the array.

addVector3(value)

Appends a SFSVector3 object to the end of the array.
Parameters:
NameTypeDescription
valueSFSVector3The SFSVector3 to be appended to the array.

addVector3Array(array)

Appends an array of SFSVector3 objects to the end of the array.
Parameters:
NameTypeDescription
arrayArray.<SFSVector3>The array of SFSVector3 to be appended to the array.

contains(obj) → {boolean}

Indicates whether the array contains the specified object.

IMPORTANT: checking if the SFSArray contains a nested SFSObject or SFSArray is not supported.

Parameters:
NameTypeDescription
obj*The object whose presence in the array should be checked.
Returns:
true if the specified object is present in the array.
Type: 
boolean

getBigInt(index) → {bigint}

Returns the element at the specified position as a BigInt.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
bigint

getBigIntArray(index) → {Array.<bigint>}

Returns the element at the specified position as an array of BigInts.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<bigint>

getBool(index) → {boolean}

Returns the element at the specified position as a boolean.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
boolean

getBoolArray(index) → {Array.<boolean>}

Returns the element at the specified position as an array of booleans.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<boolean>

getDump(formatopt) → {string}

Provides a formatted string representing the array.

The returned string can be logged or printed in the console for debugging purposes.

Parameters:
NameTypeAttributesDefaultDescription
formatboolean<optional>
trueIf true, the output is formatted in a human-readable way.
Returns:
The string representation of the array.
Type: 
string

getElementAt(index) → {*}

Returns the element at the specified position in the array.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element at the specified index in the array.
Type: 
*

getHexDump() → {string}

Provides a detailed hexadecimal representation of the array.

The returned string can be logged or printed in the console for debugging purposes.

Returns:
The hexadecimal string representation of the array.
Type: 
string

getNumber(index) → {number}

Returns the element at the specified position as a number.

IMPORTANT: in case the original value is of type long, it will be cast to number, with possible loss of precision. Use SFSArrayt#getBigInt method to get the precise value.

Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
number

getNumberArray(index) → {Array.<number>}

Returns the element at the specified position as an array of numbers.

IMPORTANT: in case the original values in the array are of type long, they will be cast to number, with possible loss of precision. Use SFSArray#getBigIntArray method to get the precise values.

Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<number>

getSFSArray(index) → {SFSArray}

Returns the element at the specified position as an SFSArray.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
SFSArray

getSFSObject(index) → {SFSObject}

Returns the element at the specified position as an SFSObject.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
SFSObject

getString(index) → {string}

Returns the element at the specified position as an UTF-8 string.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
string

getStringArray(index) → {Array.<string>}

Returns the element at the specified position as an array of UTF-8 strings.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<string>

getVector2(index) → {SFSVector2}

Returns the element at the specified position as a SFSVector2.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
SFSVector2

getVector2Array(index) → {Array.<SFSVector2>}

Returns the element at the specified position as an array of SFSVector2.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<SFSVector2>

getVector3(index) → {SFSVector3}

Returns the element at the specified position as a SFSVector3.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
SFSVector3

getVector3Array(index) → {Array.<SFSVector3>}

Returns the element at the specified position as an array of SFSVector3.
Parameters:
NameTypeDescription
indexnumberThe position of the element to return.
Returns:
The element of the array at the specified index.
Type: 
Array.<SFSVector3>

isNull(index) → {boolean}

Indicates whether the element at the specified position in the array is null.
Parameters:
NameTypeDescription
indexnumberThe position of the element to be checked.
Returns:
true if the element of the array at the specified position is null.
Type: 
boolean

removeElementAt(index) → {*}

Removes the element at the specified position in the array.
Parameters:
NameTypeDescription
indexnumberThe position of the element to be removed.
Returns:
The element that was removed.
Type: 
*

size() → {number}

Number of elements in the array.
Returns:
The number of elements in the array.
Type: 
number

toBinary() → {Uint8Array}

Provides the binary form of the array.
Returns:
The binary data representing the array.
Type: 
Uint8Array

(static) newFromBinaryData(binData) → {SFSArray}

Returns a new SFSArray instance.

This method is a static alternative to the standard class constructor that builds an SFSArray from a valid SFSArray binary representation.

Parameters:
NameTypeDescription
binDataUint8ArrayThe byte array representation of the SFSArray.
Returns:
A new SFSArray instance.
Type: 
SFSArray