Class SFSArray
- All Implemented Interfaces:
ISFSArray,Serializable
Let's consider this simple example: we need to send the data relative to a combat vehicle in a multiplayer game. In order reduce the amount of bytes sent to a minimum we will send the data as an array avoiding the overhead of key names for each item.
ISFSArray sfsa = new SFSArray();
sfsa.addByte(10); // the vehicle id
sfsa.addShort(5000); // the vehicle current health
sfsa.addIntArray(Arrays.asList(120,150)); // the x,y position on the terrain as int[]
sfsa.addShortString("Hurricane"); // the vehicle name
In the above code we can use a single Byte (signed 8-bit) to send any small integer value, a Short (signed 16-bit)
for larger values and integers for any number that should be represented as regular 32-bit value. In this example we imagined to have a wide
RTS environment and we used an int[] to transmit the x,y position of the vehicle.
The following is a list of type supported by the SFSArray 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 | |
| Vector2 | 8 bytes | |
| Vector3 | 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 |
| Vector2 array | 8 bytes | <= 2ˆ15 |
| Vector3 array | 12 bytes | <= 2ˆ15 |
| short string array | <= 255 bytes | <= 2ˆ15 |
| string array | <= 2ˆ15 bytes | <= 2ˆ15 |
NOTE #1: 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 #2: SFSObject and SFSArray can be nested inside each other to create more complex data structures.
NOTE #3: SFSObject and SFSArray methods are not thread safe.
NOTE #4: An SFSArray can contain a maximum of 32768 elements.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(SFSDataWrapper wrappedObject) voidaddBool(boolean value) Add a booleanvoidaddBoolArray(Collection<Boolean> value) Add an collection of booleanvoidaddByte(byte value) Add a byte (signed 8-bit)voidaddByteArray(byte[] value) Add an array of bytesvoidaddDouble(double value) Add a byte (signed decimal 64-bit)voidaddDoubleArray(Collection<Double> value) Add a collection of doublevoidaddFloat(float value) Add a byte (signed decimal 32-bit)voidaddFloatArray(Collection<Float> value) Add a collection of floatvoidaddInt(int value) Add a byte (signed 32-bit)voidaddIntArray(Collection<Integer> value) Add a collection of intvoidaddLong(long value) Add a byte (signed 64-bit)voidaddLongArray(Collection<Long> value) Add a collection of longvoidaddNull()Add a null field to the Object.voidaddSFSArray(ISFSArray value) Add a nested ISFSArrayvoidaddSFSObject(ISFSObject value) Add a nested ISFSObjectvoidaddShort(short value) Add a byte (signed 16-bit)voidaddShortArray(Collection<Short> value) Add a collection of shortvoidaddShortString(String value) Add a UTF encoded string with max length of 255 bytesvoidaddShortStringArray(Collection<String> value) Add a collection of UTF encoded strings, each string limited to a max of 255 bytes The collection is also limited to a max of 32768 elementsvoidAdd a UTF encoded string with max length of 32768 bytesvoidaddStringArray(Collection<String> value) Add a collection of UTF encoded strings, each string limited to a max of 32768 bytes The collection is also limited to a max of 32768 elementsvoidAdd a UTF encoded long String with max length of 2 GBytesvoidaddVector2(SFSVector2 value) Add a SFSVector2 (2x float 32bit)voidaddVector2Array(Collection<SFSVector2> value) Add a collection of SFSVector2voidaddVector3(SFSVector3 value) Add a SFSVector3 (3x float 32bit)voidaddVector3Array(Collection<SFSVector3> value) Add a collection of SFSVector3booleanChecks if a specific element is contained in the arrayget(int index) getBool(int index) Get the element at the specified index as Boolean.getBoolArray(int index) Get the element at the specified index as Collection of Boolean.getByte(int index) Get the element at the specified index as Byte.byte[]getByteArray(int index) Get the element at the specified index as byte array.getDouble(int index) Get the element at the specified index as Double.getDoubleArray(int index) Get the element at the specified index as Collection of Double.getDump()Get a detailed dump of the SFSArray structuregetDump(boolean noFormat) Get a detailed dump of the SFSArray structuregetElementAt(int index) getFloat(int index) Get the element at the specified index as Float.getFloatArray(int index) Get the element at the specified index as Collection of Float.Get a pretty-printed hex-dump of the arraygetInt(int index) Get the element at the specified index as Integer.getIntArray(int index) Get the element at the specified index as Collection of Int.getLong(int index) Get the element at the specified index as Long.getLongArray(int index) Get the element at the specified index as Collection of Long.getSFSArray(int index) Get the element at the specified index as ISFSArray.getSFSObject(int index) Get the element at the specified index as ISFSObject.getShort(int index) Get the element at the specified index as Short.getShortArray(int index) Get the element at the specified index as Collection of Short.getShortString(int index) Get the element at the specified index as short string, with a max length of 255 bytes It can be null if no element exists for the specified indexgetShortStringArray(int index) Get the element at the specified index as Collection of String.getString(int index) Get the element at the specified index as string, with a max length of 32768 bytes It can be null if no element exists for the specified indexgetStringArray(int index) Get the element at the specified index as Collection of String.getText(int index) Get the element at the specified index as long String, with a max length of 2 GBytes.getUnsignedByte(int index) Get the element at the specified index as an unsigned Integer (bytes are always signed, -127 < b < 127)
It can be null if no element exists for the specified indexgetUnsignedByteArray(int index) Get the element at the specified index as a Collection of unsigned integers.getVector2(int index) Get the element at the specified index as SFSVector2.getVector2Array(int index) Get the element at the specified index as Collection of SFSVector2.getVector3(int index) Get the element at the specified index as SFSVector3.getVector3Array(int index) Get the element at the specified index as Collection of SFSVector3.booleanisNull(int index) Checks if a specific element is null.iterator()static SFSArraynewFromBinaryData(byte[] bytes) Rebuild an SFSArray form its binary formstatic SFSArraynewFromJsonData(String jsonStr) static SFSArraynewFromResultSet(ResultSet rset) static SFSArrayStatic constructor, similar to new SFSArray();voidremoveElementAt(int index) Remove an element at a specific indexintsize()Return the number of elements contained in the arraybyte[]toBinary()Return the binary representation of the SFSArraytoJson()Return the JSON representation of the SFSArraytoString()
-
Constructor Details
-
SFSArray
public SFSArray()
-
-
Method Details
-
newFromBinaryData
Rebuild an SFSArray form its binary form- Parameters:
bytes- the binary data- Returns:
- the original SFSArray
- Throws:
IllegalStateException- if there's any problem with decoding the binary data
-
newFromResultSet
- Throws:
SQLException
-
newFromJsonData
- Internal
-
newInstance
Static constructor, similar to new SFSArray();- Returns:
- a new SFSArray
-
getDump
Description copied from interface:ISFSArrayGet a detailed dump of the SFSArray structure -
getDump
Description copied from interface:ISFSArrayGet a detailed dump of the SFSArray structure -
getHexDump
Description copied from interface:ISFSArrayGet a pretty-printed hex-dump of the array- Specified by:
getHexDumpin interfaceISFSArray- Returns:
- a pretty-printed hex-dump of the array
-
toBinary
public byte[] toBinary()Description copied from interface:ISFSArrayReturn the binary representation of the SFSArray -
toJson
Description copied from interface:ISFSArrayReturn the JSON representation of the SFSArray -
isNull
public boolean isNull(int index) Description copied from interface:ISFSArrayChecks if a specific element is null. -
get
-
getBool
Description copied from interface:ISFSArrayGet the element at the specified index as Boolean. It can be null if no element exists for the specified index -
getByte
Description copied from interface:ISFSArrayGet the element at the specified index as Byte. It can be null if no element exists for the specified index -
getUnsignedByte
Description copied from interface:ISFSArrayGet the element at the specified index as an unsigned Integer (bytes are always signed, -127 < b < 127)
It can be null if no element exists for the specified index- Specified by:
getUnsignedBytein interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getShort
Description copied from interface:ISFSArrayGet the element at the specified index as Short. It can be null if no element exists for the specified index -
getInt
Description copied from interface:ISFSArrayGet the element at the specified index as Integer. It can be null if no element exists for the specified index -
getLong
Description copied from interface:ISFSArrayGet the element at the specified index as Long. It can be null if no element exists for the specified index -
getFloat
Description copied from interface:ISFSArrayGet the element at the specified index as Float. It can be null if no element exists for the specified index -
getDouble
Description copied from interface:ISFSArrayGet the element at the specified index as Double. It can be null if no element exists for the specified index -
getString
Description copied from interface:ISFSArrayGet the element at the specified index as string, with a max length of 32768 bytes It can be null if no element exists for the specified index -
getShortString
Description copied from interface:ISFSArrayGet the element at the specified index as short string, with a max length of 255 bytes It can be null if no element exists for the specified index- Specified by:
getShortStringin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getText
Description copied from interface:ISFSArrayGet the element at the specified index as long String, with a max length of 2 GBytes. It can be null if no element exists for the specified index -
getVector2
Description copied from interface:ISFSArrayGet the element at the specified index as SFSVector2.- Specified by:
getVector2in interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getVector3
Description copied from interface:ISFSArrayGet the element at the specified index as SFSVector3.- Specified by:
getVector3in interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getBoolArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Boolean. It can be null if no element exists for the specified index- Specified by:
getBoolArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getByteArray
public byte[] getByteArray(int index) Description copied from interface:ISFSArrayGet the element at the specified index as byte array. It can be null if no element exists for the specified indexNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
- Specified by:
getByteArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getUnsignedByteArray
Description copied from interface:ISFSArrayGet the element at the specified index as a Collection of unsigned integers. It can be null if no element exists for the specified index- Specified by:
getUnsignedByteArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getShortArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Short. It can be null if no element exists for the specified index- Specified by:
getShortArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getIntArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Int. It can be null if no element exists for the specified index- Specified by:
getIntArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getLongArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Long. It can be null if no element exists for the specified index- Specified by:
getLongArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getFloatArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Float. It can be null if no element exists for the specified index- Specified by:
getFloatArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getDoubleArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of Double. It can be null if no element exists for the specified index- Specified by:
getDoubleArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getStringArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of String. It can be null if no element exists for the specified index Each string is limited to 32768 bytes- Specified by:
getStringArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getShortStringArray
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of String. It can be null if no element exists for the specified index Each string is limited to 255 bytes- Specified by:
getShortStringArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getVector2Array
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of SFSVector2. It can be null if no element exists for the specified index- Specified by:
getVector2Arrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getVector3Array
Description copied from interface:ISFSArrayGet the element at the specified index as Collection of SFSVector3. It can be null if no element exists for the specified index Each string is limited to 255 bytes- Specified by:
getVector3Arrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getSFSArray
Description copied from interface:ISFSArrayGet the element at the specified index as ISFSArray. It can be null if no element exists for the specified index- Specified by:
getSFSArrayin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
-
getSFSObject
Description copied from interface:ISFSArrayGet the element at the specified index as ISFSObject. It can be null if no element exists for the specified index- Specified by:
getSFSObjectin interfaceISFSArray- Parameters:
index-- Returns:
- the element, or null
- See Also:
-
addBool
public void addBool(boolean value) Description copied from interface:ISFSArrayAdd a boolean -
addBoolArray
Description copied from interface:ISFSArrayAdd an collection of boolean- Specified by:
addBoolArrayin interfaceISFSArray- Parameters:
value-
-
addByte
public void addByte(byte value) Description copied from interface:ISFSArrayAdd a byte (signed 8-bit) -
addByteArray
public void addByteArray(byte[] value) Description copied from interface:ISFSArrayAdd an array of bytesNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
- Specified by:
addByteArrayin interfaceISFSArray- Parameters:
value-
-
addDouble
public void addDouble(double value) Description copied from interface:ISFSArrayAdd a byte (signed decimal 64-bit) -
addDoubleArray
Description copied from interface:ISFSArrayAdd a collection of double- Specified by:
addDoubleArrayin interfaceISFSArray- Parameters:
value-
-
addFloat
public void addFloat(float value) Description copied from interface:ISFSArrayAdd a byte (signed decimal 32-bit) -
addFloatArray
Description copied from interface:ISFSArrayAdd a collection of float- Specified by:
addFloatArrayin interfaceISFSArray- Parameters:
value-
-
addInt
public void addInt(int value) Description copied from interface:ISFSArrayAdd a byte (signed 32-bit) -
addIntArray
Description copied from interface:ISFSArrayAdd a collection of int- Specified by:
addIntArrayin interfaceISFSArray- Parameters:
value-
-
addLong
public void addLong(long value) Description copied from interface:ISFSArrayAdd a byte (signed 64-bit) -
addLongArray
Description copied from interface:ISFSArrayAdd a collection of long- Specified by:
addLongArrayin interfaceISFSArray- Parameters:
value-
-
addNull
public void addNull()Description copied from interface:ISFSArrayAdd 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
-
addSFSArray
Description copied from interface:ISFSArrayAdd a nested ISFSArray- Specified by:
addSFSArrayin interfaceISFSArray- Parameters:
value-
-
addSFSObject
Description copied from interface:ISFSArrayAdd a nested ISFSObject- Specified by:
addSFSObjectin interfaceISFSArray- Parameters:
value-
-
addShort
public void addShort(short value) Description copied from interface:ISFSArrayAdd a byte (signed 16-bit) -
addShortArray
Description copied from interface:ISFSArrayAdd a collection of short- Specified by:
addShortArrayin interfaceISFSArray- Parameters:
value-
-
addString
Description copied from interface:ISFSArrayAdd a UTF encoded string with max length of 32768 bytes -
addShortString
Description copied from interface:ISFSArrayAdd a UTF encoded string with max length of 255 bytes- Specified by:
addShortStringin interfaceISFSArray- Parameters:
value-
-
addText
Description copied from interface:ISFSArrayAdd a UTF encoded long String with max length of 2 GBytes -
addVector2
Description copied from interface:ISFSArrayAdd a SFSVector2 (2x float 32bit)- Specified by:
addVector2in interfaceISFSArray- Parameters:
value-
-
addVector3
Description copied from interface:ISFSArrayAdd a SFSVector3 (3x float 32bit)- Specified by:
addVector3in interfaceISFSArray- Parameters:
value-
-
addStringArray
Description copied from interface:ISFSArrayAdd a collection of UTF encoded strings, each string limited to a max of 32768 bytes The collection is also limited to a max of 32768 elements- Specified by:
addStringArrayin interfaceISFSArray- Parameters:
value-
-
addShortStringArray
Description copied from interface:ISFSArrayAdd a collection of UTF encoded strings, each string limited to a max of 255 bytes The collection is also limited to a max of 32768 elements- Specified by:
addShortStringArrayin interfaceISFSArray- Parameters:
value-
-
addVector2Array
Description copied from interface:ISFSArrayAdd a collection of SFSVector2- Specified by:
addVector2Arrayin interfaceISFSArray- Parameters:
value-
-
addVector3Array
Description copied from interface:ISFSArrayAdd a collection of SFSVector3- Specified by:
addVector3Arrayin interfaceISFSArray- Parameters:
value-
-
add
-
contains
Description copied from interface:ISFSArrayChecks if a specific element is contained in the array -
getElementAt
- Specified by:
getElementAtin interfaceISFSArray
-
iterator
-
removeElementAt
public void removeElementAt(int index) Description copied from interface:ISFSArrayRemove an element at a specific index- Specified by:
removeElementAtin interfaceISFSArray- Parameters:
index- the index of the element to remove
-
size
public int size()Description copied from interface:ISFSArrayReturn the number of elements contained in the array -
toString
-