Constructor
new SFSObject()
Creates a new instance of the SFSObject class.
Methods
containsKey(key) → {boolean}
Indicates whether the object contains a mapping for the specified key.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose presence in the object should be checked. |
Returns:true if the object contains a mapping for the specified key.
- Type:
- boolean
getBigInt(key) → {bigint}
Returns the element corresponding to the specified key as a BigInt.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- bigint
getBigIntArray(key) → {Array.<bigint>}
Returns the element corresponding to the specified key as an array of BigInts.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<bigint>
getBool(key) → {boolean}
Returns the element corresponding to the specified key as a boolean.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- boolean
getBoolArray(key) → {Array.<boolean>}
Returns the element corresponding to the specified key as an array of booleans.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<boolean>
getDump(formatopt) → {string}
Provides a formatted string representing the object.
The returned string can be logged or printed in the console for debugging purposes.
Parameters:| Name | Type | Attributes | Default | Description |
|---|
format | boolean | <optional>
| true | If true, the output is formatted in a human-readable way. |
Returns:The string representation of the object.
- Type:
- string
getHexDump() → {string}
Provides a detailed hexadecimal representation of the object.
The returned string can be logged or traced in the console for debugging purposes.
Returns:The hexadecimal string representation of the object.
- Type:
- string
getKeys() → {Array.<string>}
Retrieves an array of all the keys contained in the object.
Returns:The list of all the keys in the object.
- Type:
- Array.<string>
getNumber(key) → {number}
Returns the element corresponding to the specified key 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 SFSObject#getBigInt method to get the precise value.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- number
getNumberArray(key) → {Array.<number>}
Returns the element corresponding to the specified key 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 SFSObject#getBigIntArray method to get the precise values.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<number>
getSFSArray(key) → {SFSArray}
Returns the element corresponding to the specified key as an SFSArray.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- SFSArray
getSFSObject(key) → {SFSObject}
Returns the element corresponding to the specified key as an SFSObject.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- SFSObject
getString(key) → {string}
Returns the element corresponding to the specified key as an UTF-8 string.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- string
getStringArray(key) → {Array.<string>}
Returns the element corresponding to the specified key as an array of UTF-8 strings.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated value is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<string>
Returns the element corresponding to the specified key as a SFSVector2.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated object is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- SFSVector2
getVector2Array(key) → {Array.<SFSVector2>}
Returns the element corresponding to the specified key as an array of SFSVector2.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated object is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<SFSVector2>
Returns the element corresponding to the specified key as a SFSVector3.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated object is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- SFSVector3
getVector3Array(key) → {Array.<SFSVector3>}
Returns the element corresponding to the specified key as an array of SFSVector3.
Parameters:| Name | Type | Description |
|---|
key | string | The key whose associated object is to be returned. |
Returns:The element of the object associated with the specified key; null if a mapping for the passed key doesn't exist.
- Type:
- Array.<SFSVector3>
isNull(key) → {boolean}
Indicates whether the value mapped by the specified key is null.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be checked. |
Returns:true if the value mapped by the passed key is null or the mapping doesn't exist for that key.
- Type:
- boolean
putBool(key, value)
Associates a boolean value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | boolean | The value to be associated with the specified key. |
putBoolArray(key, array)
Associates an array of boolean values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<boolean> | The array of booleans to be associated with the specified key. |
putByte(key, value)
Associates a byte (8 bits) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | The value to be associated with the specified key. |
putByteArray(key, array)
Associates a byte array with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Uint8Array | The byte array to be associated with the specified key. |
putDouble(key, value)
Associates a double precision number (64 bits) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | The value to be associated with the specified key. |
putDoubleArray(key, array)
Associates an array of double precision number values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<number> | The array of doubles to be associated with the specified key. |
putFloat(key, value)
Associates a floating point number (32 bits) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | The value to be associated with the specified key. |
putFloatArray(key, array)
Associates an array of floating point number values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<number> | The array of floats to be associated with the specified key. |
putInt(key, value)
Associates an integer (32 bits) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | The value to be associated with the specified key. |
putIntArray(key, array)
Associates an array of integer values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<number> | The array of integers to be associated with the specified key. |
putLong(key, value)
Associates a long integer (64 bits) value with the specified key in the object.
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:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | bigint | The value to be associated with the specified key. |
putLongArray(key, array)
Associates an array of long integer values with the specified key in the object.
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:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<number> | Array.<bigint> | The array of longs to be associated with the specified key. |
putNull(key)
Associates a null value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the null value. |
putSFSArray(key, value)
Associates an SFSArray with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified object. |
value | SFSArray | The object to be associated with the specified key. |
putSFSObject(key, value)
Associates an SFSObject with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified object. |
value | SFSObject | The object to be associated with the specified key. |
putShort(key, value)
Associates a short integer (16 bits) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | number | The value to be associated with the specified key. |
putShortArray(key, array)
Associates an array of short integer values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<number> | The array of shorts to be associated with the specified key. |
putShortString(key, value)
Associates a UTF-8 string (with max length of 255 bytes) value with the specified key in the object.
Use this method if you're sure your strings are short enough and you want to save a few bytes during the encoding.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | string | The value to be associated with the specified key. |
putShortStringArray(key, array)
Associates an array of short UTF-8 string values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<string> | The array of short UTF-8 strings to be associated with the specified key. |
putString(key, value)
Associates a UTF-8 string (with max length of 32767 bytes) value with the specified key in the object.
This is the default choice for strings and uses 2 bytes to define the string length.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | string | The value to be associated with the specified key. |
putStringArray(key, array)
Associates an array of UTF-8 string values with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
array | Array.<string> | The array of UTF-8 strings to be associated with the specified key. |
putText(key, value)
Associates a UTF-8 string (with max length of 2 GBytes) value with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified value. |
value | string | The value to be associated with the specified key. |
putVector2(key, value)
Associates a SFSVector2 object with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified object. |
value | SFSVector2 | The object to be associated with the specified key. |
putVector2Array(key, value)
Associates an array of SFSVector2 objects with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
value | Array.<SFSVector2> | The array of SFSVector2 objects to be associated with the specified key. |
putVector3(key, value)
Associates a SFSVector3 object with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified object. |
value | SFSVector3 | The object to be associated with the specified key. |
putVector3Array(key, value)
Associates an array of SFSVector3 objects with the specified key in the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key to be associated with the specified array. |
value | Array.<SFSVector3> | The array of SFSVector3 objects to be associated with the specified key. |
removeElement(key)
Removes the element corresponding to the passed key from the object.
Parameters:| Name | Type | Description |
|---|
key | string | The key of the element to be removed. |
size() → {number}
Number of elements mapped in the object.
Returns:The number of elements in the object.
- Type:
- number
toBinary() → {Uint8Array}
Provides the binary form of the object.
Returns:The binary data representing the object.
- Type:
- Uint8Array
(static) newFromBinaryData(binData) → {SFSObject}
Returns a new SFSObject instance.
This method is a static alternative to the standard class constructor that builds an SFSObject from a valid SFSObject binary representation.
Parameters:| Name | Type | Description |
|---|
binData | Uint8Array | The byte array representation of the SFSObject. |
Returns:A new SFSObject instance.
- Type:
- SFSObject