Interface ISFSObject

All Known Implementing Classes:
SFSObject

public interface ISFSObject
SFSObject and SFSArray represent a platform-neutral, high level object used to exchange data between client and server. Respectively, they are used to represent data in form of a Map or List and they can transport many different data types (from a single byte to arrays of doubles, strings, etc...)

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:

TypeItem sizeArray Len
null--- 
bool1 byte 
byte1 byte 
short2 bytes 
int4 bytes 
long8 bytes 
float4 bytes 
double8 bytes 
SFSVector28 bytes 
SFSVector312 bytes 
short string<= 255 bytes 
string<= 2ˆ15 bytes 
text<= 2ˆ31 bytes 
bool array1 byte<= 2ˆ15
byte array1 byte<= 2ˆ31
short array2 bytes<= 2ˆ15
int array4 bytes<= 2ˆ15
long array8 bytes<= 2ˆ15
float array4 bytes<= 2ˆ15
double array8 bytes<= 2ˆ15
SFSVector2 array8 bytes<= 2ˆ15
SFSVector3 array12 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 Details

    • isNull

      boolean isNull(String key)
      Checks if a specific element is of SFSDataType.NULL.
      Parameters:
      key - the property name
      Returns:
      true if the item is null
    • containsKey

      boolean containsKey(String key)
      Looks for a specific key in the object
      Returns:
      true if the element exists
    • removeElement

      boolean removeElement(String key)
      Remove an element in the object
      Parameters:
      key - the element name
      Returns:
      true if the element was really present in the object
    • getKeys

      Set<String> 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

      Return an Iterator to loop through the collection of values

      NOTE: 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

      String getDump(boolean noFormat)
      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

      Boolean getBool(String key)
      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

      Byte getByte(String key)
      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

      Short getShort(String key)
      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

      Integer getInt(String key)
      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

      Long getLong(String key)
      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

      Float getFloat(String key)
      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

      Double getDouble(String key)
      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

      String getString(String key)
      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

      String getShortString(String key)
      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

      String getText(String key)
      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

      Collection<Boolean> getBoolArray(String key)
      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

      byte[] getByteArray(String key)
      Get the element for the specified key as a Collection of Byte. It can be null if no element exists for the specified key

      NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.

      Parameters:
      key -
      Returns:
      the element, or null
    • getUnsignedByteArray

      Collection<Integer> getUnsignedByteArray(String key)
      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

      Collection<Short> getShortArray(String key)
      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

      Collection<Integer> getIntArray(String key)
      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

      Collection<Long> getLongArray(String key)
      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

      Collection<Float> getFloatArray(String key)
      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

      Collection<Double> getDoubleArray(String key)
      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

      Collection<String> getStringArray(String key)
      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

      Collection<String> getShortStringArray(String key)
      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

      ISFSArray getSFSArray(String key)
      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

      ISFSObject getSFSObject(String key)
      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

      SFSVector2 getVector2(String key)
      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

      SFSVector3 getVector3(String key)
      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

      Collection<SFSVector2> getVector2Array(String key)
      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

      Collection<SFSVector3> getVector3Array(String key)
      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

      void putNull(String key)
      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

      void putBool(String key, boolean value)
      Add a boolean
      Parameters:
      key - the property name
      value - the value
    • putByte

      void putByte(String key, byte value)
      Add a byte (signed 8-bit)
      Parameters:
      key - the property name
      value - the value
    • putShort

      void putShort(String key, short value)
      Add a short value (signed 16-bit)
      Parameters:
      key - the property name
      value - the value
    • putInt

      void putInt(String key, int value)
      Add a short value (signed 32-bit)
      Parameters:
      key - the property name
      value - the value
    • putLong

      void putLong(String key, long value)
      Add a long value (signed 64-bit)
      Parameters:
      key - the property name
      value - the value
    • putFloat

      void putFloat(String key, float value)
      Add a float value (signed 32-bit)
      Parameters:
      key - the property name
      value - the value
    • putDouble

      void putDouble(String key, double value)
      Add a double value (signed 64-bit)
      Parameters:
      key - the property name
      value - the value
    • putString

      void putString(String key, String value)
      Add a string value (encoded in UTF-8), with a limit of 32768 bytes.
      Parameters:
      key - the property name
      value - the value
      See Also:
    • putShortString

      void putShortString(String key, String value)
      Add a short string value (UTF encoded), with a limit of 255 bytes
      Parameters:
      key - the property name
      value - the value
    • putText

      void putText(String key, String value)
      Add a string value (UTF encoded), with a limit of 2 GBytes
      Parameters:
      key - the property name
      value - the value
    • putVector2

      void putVector2(String key, SFSVector2 value)
      Add a SFSVector2
      Parameters:
      key - the property name
      value - the value
    • putVector3

      void putVector3(String key, SFSVector3 value)
      Add a SFSVector3
      Parameters:
      key - the property name
      value - the value
    • putBoolArray

      void putBoolArray(String key, Collection<Boolean> value)
      Add a Collection of boolean
      Parameters:
      key - the property name
      value - the value
    • putByteArray

      void putByteArray(String key, byte[] value)
      Add an array of bytes

      NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.

      Parameters:
      key - the property name
      value - the value
    • putShortArray

      void putShortArray(String key, Collection<Short> value)
      Add a Collection of short
      Parameters:
      key - the property name
      value - the value
    • putIntArray

      void putIntArray(String key, Collection<Integer> value)
      Add a Collection of int
      Parameters:
      key - the property name
      value - the value
    • putLongArray

      void putLongArray(String key, Collection<Long> value)
      Add a Collection of long
      Parameters:
      key - the property name
      value - the value
    • putFloatArray

      void putFloatArray(String key, Collection<Float> value)
      Add a Collection of float
      Parameters:
      key - the property name
      value - the value
    • putDoubleArray

      void putDoubleArray(String key, Collection<Double> value)
      Add a Collection of double
      Parameters:
      key - the property name
      value - the value
    • putStringArray

      void putStringArray(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 strings
      Parameters:
      key - the property name
      value - the value
    • putShortStringArray

      void putShortStringArray(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 strings
      Parameters:
      key - the property name
      value - the value
    • putVector2Array

      void putVector2Array(String key, Collection<SFSVector2> value)
      Add a collection of SFSVector2
      Parameters:
      key - the property name
      value - the value
    • putVector3Array

      void putVector3Array(String key, Collection<SFSVector3> value)
      Add a collection of SFSVector3
      Parameters:
      key - the property name
      value - the value
    • putSFSArray

      void putSFSArray(String key, ISFSArray value)
      Add a nested ISFSArray
      Parameters:
      key - the property name
      value - the value
      See Also:
    • putSFSObject

      void putSFSObject(String key, ISFSObject value)
      Add a nested SFSObject
      Parameters:
      key - the property name
      value - the value
    • put

      void put(String key, SFSDataWrapper wrappedObject)