SFSArray
The SFSArray class is used by SmartFoxServer in client-server data transfer.
Methods
new SFSArray()
Creates a new SFSArray instance.
This is a sort of specialized list object that can contain any type of data. The advantage of using the SFSArray class
(for example as a nested object inside a SFSObject object) 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 related arrays of primitives; see the SFSDataType class.
- See also
- SFSObject
- SFSDataType
Methods
add(value, typeId)
Appends a value of the passed type to the end of this array.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
value |
any type |
|
The value to be appended to this array. |
typeId |
number |
|
The value's type identifier; must be one of the constants set in the SFSDataType class. |
- See also
- SFSDataType
addBool(value)
Appends a boolean value to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
boolean |
|
The value to be appended to this array. |
addBoolArray(array)
Appends an array of booleans to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of boolean |
|
The array to be appended to this array. |
addByte(value)
Appends a number to the end of this array as a byte (8 bit).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addByteArray(array)
Appends a byte array to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Uint8Array |
|
The byte array to be appended to this array. |
addDouble(value)
Appends a number to the end of this array as a double precision value (64 bit).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addDoubleArray(array)
Appends an array of numbers to the end of this array as double precision values.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of number |
|
The array to be appended to this array. |
addFloat(value)
Appends a number to the end of this array as a floating point value (32 bit).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addFloatArray(array)
Appends an array of numbers to the end of this array as floating point values.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of number |
|
The array to be appended to this array. |
addInt(value)
Appends a number to the end of this array as an integer (32 bit).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addIntArray(array)
Appends an array of numbers to the end of this array as integers.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of number |
|
The array to be appended to this array. |
addLong(value)
Appends a number to the end of this array as a long integer.
IMPORTANT: in JavaScript, long integer numbers are limited to Number.MAX_SAFE_INTEGER (positive and negative, inclusive).
This is inconsistent with the max and min Long values available in Java, which are down to -2^63
and up to 2^63 - 1
.
So if you are developing your server side Extension in Java, make sure you take this limitation into account when dealing with integers.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addLongArray(array)
Appends an array of numbers to the end of this array as long integers.
This is a shortcut for the add() method.
Read important note in the add() method description.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of number |
|
The array to be appended to this array. |
addNull()
Appends a null value to the end of this array.
This is a shortcut for the add() method.
addSFSArray(value)
Appends a nested SFSArray to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
|
The SFSArray to be appended to this array. |
addSFSObject(value)
Appends a nested SFSObject to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
|
The SFSObject to be appended to this array. |
addShort(value)
Appends a number to the end of this array as a short integer (16 bit).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
number |
|
The value to be appended to this array. |
addShortArray(array)
Appends an array of numbers to the end of this array as short integers.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of number |
|
The array to be appended to this array. |
addText(value)
Appends a UTF-8 string to the end of this array (max length: 2 GBytes).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
string |
|
The value to be appended to this array. |
addUtfString(value)
Appends a UTF-8 string to the end of this array (max length: 32 KBytes).
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
value |
string |
|
The value to be appended to this array. |
addUtfStringArray(array)
Appends an array of UTF-8 strings to the end of this array.
This is a shortcut for the add() method.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array of string |
|
The array to be appended to this array. |
contains(object) → boolean
Indicates whether this SFSArray contains the specified object or not.
NOTE: this method doesn't support checking the presence of a nested SFSObject or SFSArray.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
object |
any type |
|
The object whose presence in this array is to be tested. |
- Returns
-
boolean
true
if the specified object is present in the SFSArray.
get(index[, typeId]) → any type
Returns the element at the specified index.
If the typeId parameter is passed, this method also executes a type check, to make sure the requested value has the expected type. In particular this is used by the other specialized get...() methods.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
typeId |
number |
Yes |
The identifier of the expected value's type; must be one of the constants set in the SFSDataType class.
Defaults to |
- Returns
-
any type
The element of this array at the specified index.
getBool(index) → boolean
Returns the boolean value at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
boolean
The element of this array at the specified index.
getBoolArray(index) → Array
Returns the array of boolean values at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getByte(index) → number
Returns the byte value at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getByteArray(index) → Uint8Array
Returns the byte array at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the byte array to return. |
- Returns
-
Uint8Array
The byte array at the specified index.
getDouble(index) → number
Returns the double precision number at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getDoubleArray(index) → Array
Returns the array of double precision numbers at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getDump([format]) → string
Provides a formatted string representing this array.
The returned string can be logged or traced in the console for debugging purposes.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
format |
boolean |
Yes |
If Defaults to |
- Returns
-
string
The string representation of this array.
getFloat(index) → number
Returns the floating point number at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getFloatArray(index) → Array
Returns the array of floating point numbers at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getHexDump() → string
Provides a detailed hexadecimal representation of this array.
The returned string can be logged or traced in the console for debugging purposes.
- Returns
-
string
The hexadecimal string representation of this array.
getInt(index) → number
Returns the integer at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getIntArray(index) → Array
Returns the array of integers at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getLong(index) → number
Returns the long at the specified index.
IMPORTANT: in JavaScript, long integer numbers are limited to Number.MAX_SAFE_INTEGER (positive and negative, inclusive).
This is inconsistent with the max and min Long values available in Java, which are down to -2^63
and up to 2^63 - 1
.
In case a number greater than Number.MAX_SAFE_INTEGER is returned, this could differ from the actual value set on the server side (a warning will be logged on the client).
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getLongArray(index) → Array
Returns the array of long integers at the specified index.
IMPORTANT: in JavaScript, long integer numbers are limited to Number.MAX_SAFE_INTEGER (positive and negative, inclusive).
This is inconsistent with the max and min Long values available in Java, which are down to -2^63
and up to 2^63 - 1
.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getSFSArray(index) → SFSArray
Returns the SFSArray at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
SFSArray
The SFSArray at the specified index.
getSFSObject(index) → SFSObject
Returns the SFSObject at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
SFSObject
The SFSObject at the specified index.
getShort(index) → number
Returns the short integer at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
number
The element of this array at the specified index.
getShortArray(index) → Array
Returns the array of short integers at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
getText(index) → string
Returns the UTF-8 string at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
string
The element of this array at the specified index.
getUtfString(index) → string
Returns the UTF-8 string at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to return. |
- Returns
-
string
The element of this array at the specified index.
getUtfStringArray(index) → Array
Returns the array of UTF-8 strings at the specified index.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the array to return. |
- Returns
-
Array
The array at the specified index.
isNull(index) → boolean
Indicates if the element at the specified index is of type SFSDataType.NULL.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The position of the element to be checked. |
- Returns
-
boolean
true
if the element at the specified index is of type SFSDataType.NULL.
size() → number
Indicates the number of elements in this array.
- Returns
-
number
The number of elements in this array.