Interface ISFSObject
- All Known Implementing Classes:
SFSObject,SFSObjectLite
Let's consider this simple example: we need to send the data relative to a combat vehicle in a multiplayer game.
ISFSObject sfso = new SFSObject();
sfso.putByte("id", 10);
sfso.putShort("health", 5000);
sfso.putVec2D("pos", new SFSVector2(100f, 50f));
sfso.putShortString("name", "Hurricane");
The following is a list of type supported by the SFSObject class:
| Type | Item size | Array Len |
| null | --- | |
| bool | 1 byte | |
| byte | 1 byte | |
| short | 2 bytes | |
| int | 4 bytes | |
| long | 8 bytes | |
| float | 4 bytes | |
| double | 8 bytes | |
| SFSVector2 | 8 bytes | |
| SFSVector3 | 12 bytes | |
| short string | <= 255 bytes | |
| string | <= 2ˆ15 bytes | |
| text | <= 2ˆ31 bytes | |
| bool array | 1 byte | <= 2ˆ15 |
| byte array | 1 byte | <= 2ˆ31 |
| short array | 2 bytes | <= 2ˆ15 |
| int array | 4 bytes | <= 2ˆ15 |
| long array | 8 bytes | <= 2ˆ15 |
| float array | 4 bytes | <= 2ˆ15 |
| double array | 8 bytes | <= 2ˆ15 |
| SFSVector2 array | 8 bytes | <= 2ˆ15 |
| SFSVector3 array | 12 bytes | <= 2ˆ15 |
| short string array | <= 255 bytes | <= 2ˆ15 |
| string array | <= 2ˆ15 bytes | <= 2ˆ15 |
NOTE #1: all keys are encoded as Short String type and as such must be <= 255 bytes in size. It is recommended to keep key names as short as possible to avoid network overhead.
NOTE #2: all strings are treated as UTF-8 and therefore characters may be represented by multiple bytes. A String with 255 characters might use more than 255 bytes to be represented.
NOTE #3: SFSObject and SFSArray can be nested inside each other to create more complex data structures.
NOTE #4: SFSObject and SFSArray methods are not thread safe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String key) Looks for a specific key in the objectGet the element for the specified key as Boolean.getBoolArray(String key) Get the element for the specified key as a Collection of Booleans.Get the element for the specified key as Byte (signed 8 bit).byte[]getByteArray(String key) Get the element for the specified key as a Collection of Byte.Get the element for the specified key as Double (signed decimal 64 bit).getDoubleArray(String key) Get the element for the specified key as a Collection of Double.getDump()Get a detailed dump of the SFSObject structuregetDump(boolean noFormat) Get a detailed dump of the SFSObject structureGet the element for the specified key as Float (signed decimal 32 bit).getFloatArray(String key) Get the element for the specified key as a Collection of Float.Get a pretty-printed hex-dump of the objectGet the element for the specified key as Integer (signed 32 bit).getIntArray(String key) Get the element for the specified key as a Collection of Integer.getKeys()Get a set of all keysGet the element for the specified key as Long (signed 64 bit).getLongArray(String key) Get the element for the specified key as a Collection of Long.getSFSArray(String key) Get the element for the specified key as ISFSArray.getSFSObject(String key) Get the element for the specified key as ISFSObject.Get the element for the specified key as Short (signed 16 bit).getShortArray(String key) Get the element for the specified key as a Collection of Short.getShortString(String key) Get the element for the specified key as String using UTF-8 encoding.Get the element for the specified key as a Collection of Strings.Get the element for the specified key as String using UTF-8 encoding.getStringArray(String key) Get the element for the specified key as a Collection of Strings.Get the element for the specified key as String using UTF-8 encoding.Get the element for the specified key as a Collection of unsigned Byte.getVector2(String key) Get the element for the specified key as SFSVector2.getVector2Array(String key) Get the element for the specified key as a Collection of SFSVector2.getVector3(String key) Get the element for the specified key as SFSVector3.getVector3Array(String key) Get the element for the specified key as a Collection of SFSVector3.booleanChecks if a specific element is of SFSDataType.NULL.iterator()Return an Iterator to loop through the collection of valuesvoidput(String key, SFSDataWrapper wrappedObject) voidAdd a booleanvoidputBoolArray(String key, Collection<Boolean> value) Add a Collection of booleanvoidAdd a byte (signed 8-bit)voidputByteArray(String key, byte[] value) Add an array of bytesvoidAdd a double value (signed 64-bit)voidputDoubleArray(String key, Collection<Double> value) Add a Collection of doublevoidAdd a float value (signed 32-bit)voidputFloatArray(String key, Collection<Float> value) Add a Collection of floatvoidAdd a short value (signed 32-bit)voidputIntArray(String key, Collection<Integer> value) Add a Collection of intvoidAdd a long value (signed 64-bit)voidputLongArray(String key, Collection<Long> value) Add a Collection of longvoidAdd a null field to the Object.voidputSFSArray(String key, ISFSArray value) Add a nested ISFSArrayvoidputSFSObject(String key, ISFSObject value) Add a nested SFSObjectvoidAdd a short value (signed 16-bit)voidputShortArray(String key, Collection<Short> value) Add a Collection of shortvoidputShortString(String key, String value) Add a short string value (UTF encoded), with a limit of 255 bytesvoidputShortStringArray(String key, Collection<String> value) Add a collection of short strings (each string limited to 255 bytes) The collection is also limited to a max of 32768 short stringsvoidAdd a string value (encoded in UTF-8), with a limit of 32768 bytes.voidputStringArray(String key, Collection<String> value) Add a collection of strings (each string limited to 32768 bytes) The collection is also limited to a max of 32768 stringsvoidAdd a string value (UTF encoded), with a limit of 2 GBytesvoidputVector2(String key, SFSVector2 value) Add a SFSVector2voidputVector2Array(String key, Collection<SFSVector2> value) Add a collection of SFSVector2voidputVector3(String key, SFSVector3 value) Add a SFSVector3voidputVector3Array(String key, Collection<SFSVector3> value) Add a collection of SFSVector3booleanremoveElement(String key) Remove an element in the objectintsize()Get the size of the SFSObjectbyte[]toBinary()Serialize the SFSObject to a byte[]toJson()
-
Method Details
-
isNull
Checks if a specific element is of SFSDataType.NULL.- Parameters:
key- the property name- Returns:
- true if the item is null
-
containsKey
Looks for a specific key in the object- Returns:
- true if the element exists
-
removeElement
Remove an element in the object- Parameters:
key- the element name- Returns:
- true if the element was really present in the object
-
getKeys
Get a set of all keys- Returns:
- all the keys
-
size
int size()Get the size of the SFSObject- Returns:
- the number of elements contained in the SFSObject
-
iterator
Iterator<Map.Entry<String,SFSDataWrapper>> iterator()Return an Iterator to loop through the collection of valuesNOTE: SFSObject is not thread safe. Use synchronization if you need to iterate and write from different threads
- Returns:
- the SFSObject iterator
-
toBinary
byte[] toBinary()Serialize the SFSObject to a byte[]- Returns:
- the serialized form of the SFSObject
-
toJson
String toJson()- Internal
-
getDump
String getDump()Get a detailed dump of the SFSObject structure- Returns:
- a detailed dump of the SFSObject structure
-
getDump
Get a detailed dump of the SFSObject structure- Parameters:
noFormat- if true the dump will not be pretty-printed- Returns:
- a detailed dump of the SFSObject structure
-
getHexDump
String getHexDump()Get a pretty-printed hex-dump of the object- Returns:
- a pretty-printed hex-dump of the object
-
get
-
getBool
Get the element for the specified key as Boolean. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getByte
Get the element for the specified key as Byte (signed 8 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getShort
Get the element for the specified key as Short (signed 16 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getInt
Get the element for the specified key as Integer (signed 32 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getLong
Get the element for the specified key as Long (signed 64 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getFloat
Get the element for the specified key as Float (signed decimal 32 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getDouble
Get the element for the specified key as Double (signed decimal 64 bit). It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getString
Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.(The string is limited to 32768 characters)
- Parameters:
key-- Returns:
- the element, or null
-
getShortString
Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.(a ShortString is limited to 255 characters)
- Parameters:
key-- Returns:
- the element, or null
-
getText
Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.The string is limited to 2 GBytes
- Parameters:
key-- Returns:
- the element, or null
-
getBoolArray
Get the element for the specified key as a Collection of Booleans. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getByteArray
Get the element for the specified key as a Collection of Byte. It can be null if no element exists for the specified keyNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
- Parameters:
key-- Returns:
- the element, or null
-
getUnsignedByteArray
Get the element for the specified key as a Collection of unsigned Byte. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getShortArray
Get the element for the specified key as a Collection of Short. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getIntArray
Get the element for the specified key as a Collection of Integer. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getLongArray
Get the element for the specified key as a Collection of Long. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getFloatArray
Get the element for the specified key as a Collection of Float. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getDoubleArray
Get the element for the specified key as a Collection of Double. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getStringArray
Get the element for the specified key as a Collection of Strings. It can be null if no element exists for the specified key Each string is limited to 32768 bytes- Parameters:
key-- Returns:
- the element, or null
-
getShortStringArray
Get the element for the specified key as a Collection of Strings. It can be null if no element exists for the specified key Each string is limited to 255 bytes- Parameters:
key-- Returns:
- the element, or null
-
getSFSArray
Get the element for the specified key as ISFSArray. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
- See Also:
-
getSFSObject
Get the element for the specified key as ISFSObject. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getVector2
Get the element for the specified key as SFSVector2. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getVector3
Get the element for the specified key as SFSVector3. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getVector2Array
Get the element for the specified key as a Collection of SFSVector2. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
getVector3Array
Get the element for the specified key as a Collection of SFSVector3. It can be null if no element exists for the specified key- Parameters:
key-- Returns:
- the element, or null
-
putNull
Add a null field to the Object. Normally we recommend that null values are simply not sent. On the other end of the application you can simply check if a specific key exists or not to detect a null.This method will effectively add the key and a byte id to describe the Null value, thus "bloating" the message
- Parameters:
key- the property name
-
putBool
Add a boolean- Parameters:
key- the property namevalue- the value
-
putByte
Add a byte (signed 8-bit)- Parameters:
key- the property namevalue- the value
-
putShort
Add a short value (signed 16-bit)- Parameters:
key- the property namevalue- the value
-
putInt
Add a short value (signed 32-bit)- Parameters:
key- the property namevalue- the value
-
putLong
Add a long value (signed 64-bit)- Parameters:
key- the property namevalue- the value
-
putFloat
Add a float value (signed 32-bit)- Parameters:
key- the property namevalue- the value
-
putDouble
Add a double value (signed 64-bit)- Parameters:
key- the property namevalue- the value
-
putString
Add a string value (encoded in UTF-8), with a limit of 32768 bytes.- Parameters:
key- the property namevalue- the value- See Also:
-
putShortString
Add a short string value (UTF encoded), with a limit of 255 bytes- Parameters:
key- the property namevalue- the value
-
putText
Add a string value (UTF encoded), with a limit of 2 GBytes- Parameters:
key- the property namevalue- the value
-
putVector2
Add a SFSVector2- Parameters:
key- the property namevalue- the value
-
putVector3
Add a SFSVector3- Parameters:
key- the property namevalue- the value
-
putBoolArray
Add a Collection of boolean- Parameters:
key- the property namevalue- the value
-
putByteArray
Add an array of bytesNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
- Parameters:
key- the property namevalue- the value
-
putShortArray
Add a Collection of short- Parameters:
key- the property namevalue- the value
-
putIntArray
Add a Collection of int- Parameters:
key- the property namevalue- the value
-
putLongArray
Add a Collection of long- Parameters:
key- the property namevalue- the value
-
putFloatArray
Add a Collection of float- Parameters:
key- the property namevalue- the value
-
putDoubleArray
Add a Collection of double- Parameters:
key- the property namevalue- the value
-
putStringArray
Add a collection of strings (each string limited to 32768 bytes) The collection is also limited to a max of 32768 strings- Parameters:
key- the property namevalue- the value
-
putShortStringArray
Add a collection of short strings (each string limited to 255 bytes) The collection is also limited to a max of 32768 short strings- Parameters:
key- the property namevalue- the value
-
putVector2Array
Add a collection of SFSVector2- Parameters:
key- the property namevalue- the value
-
putVector3Array
Add a collection of SFSVector3- Parameters:
key- the property namevalue- the value
-
putSFSArray
Add a nested ISFSArray- Parameters:
key- the property namevalue- the value- See Also:
-
putSFSObject
Add a nested SFSObject- Parameters:
key- the property namevalue- the value
-
put
-