public class SFSArray extends java.lang.Object implements ISFSArray
These two classes provide a fine-grained control over each data item sent over the network and provide high speed serialization using the default SFS2X binary protocol.
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.addUtfString("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:
NOTE: SFSArray is not thread safe.
Limitations: An SFSArray can contain a maximum of 32768 elements, also the UTF Strings length is expressed using a signed short integer which means that a string can be long up to 32768 characters.
SFSObject| Constructor and Description |
|---|
SFSArray() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(SFSDataWrapper wrappedObject) |
void |
addBool(boolean value)
Add a boolean
|
void |
addBoolArray(java.util.Collection<java.lang.Boolean> value)
Add an collection of boolean
|
void |
addByte(byte value)
Add a byte (signed 8-bit)
|
void |
addByteArray(byte[] value)
Add an array of bytes
NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
|
void |
addClass(java.lang.Object o)
Add a Class instance.
|
void |
addDouble(double value)
Add a byte (signed decimal 64-bit)
|
void |
addDoubleArray(java.util.Collection<java.lang.Double> value)
Add a collection of double
|
void |
addFloat(float value)
Add a byte (signed decimal 32-bit)
|
void |
addFloatArray(java.util.Collection<java.lang.Float> value)
Add a collection of float
|
void |
addInt(int value)
Add a byte (signed 32-bit)
|
void |
addIntArray(java.util.Collection<java.lang.Integer> value)
Add a collection of int
|
void |
addLong(long value)
Add a byte (signed 64-bit)
|
void |
addLongArray(java.util.Collection<java.lang.Long> value)
Add a collection of long
|
void |
addNull()
Add a null field to the Object.
|
void |
addSFSArray(ISFSArray value)
Add a nested ISFSArray
|
void |
addSFSObject(ISFSObject value)
Add a nested ISFSObject
|
void |
addShort(short value)
Add a byte (signed 16-bit)
|
void |
addShortArray(java.util.Collection<java.lang.Short> value)
Add a collection of short
|
void |
addText(java.lang.String value)
Add a long String encoded in UTF-8 with max length of 2 GBytes
|
void |
addUtfString(java.lang.String value)
Add a String encoded in UTF-8 with max length of 32 KBytes
|
void |
addUtfStringArray(java.util.Collection<java.lang.String> value)
Add a collection of string
|
boolean |
contains(java.lang.Object obj)
Checks if a specific element is contained in the array
|
SFSDataWrapper |
get(int index) |
java.lang.Boolean |
getBool(int index)
Get the element at the specified index as Boolean.
|
java.util.Collection<java.lang.Boolean> |
getBoolArray(int index)
Get the element at the specified index as Collection of Boolean.
|
java.lang.Byte |
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.
|
java.lang.Object |
getClass(int index)
Get the element at the specified index as Class instance.
|
java.lang.Double |
getDouble(int index)
Get the element at the specified index as Double.
|
java.util.Collection<java.lang.Double> |
getDoubleArray(int index)
Get the element at the specified index as Collection of Double.
|
java.lang.String |
getDump()
Get a detailed dump of the SFSArray structure
|
java.lang.String |
getDump(boolean noFormat)
Get a detailed dump of the SFSArray structure
|
java.lang.Object |
getElementAt(int index) |
java.lang.Float |
getFloat(int index)
Get the element at the specified index as Float.
|
java.util.Collection<java.lang.Float> |
getFloatArray(int index)
Get the element at the specified index as Collection of Float.
|
java.lang.String |
getHexDump()
Get a pretty-printed hex-dump of the array
|
java.lang.Integer |
getInt(int index)
Get the element at the specified index as Integer.
|
java.util.Collection<java.lang.Integer> |
getIntArray(int index)
Get the element at the specified index as Collection of Int.
|
java.lang.Long |
getLong(int index)
Get the element at the specified index as Long.
|
java.util.Collection<java.lang.Long> |
getLongArray(int index)
Get the element at the specified index as Collection of Long.
|
ISFSArray |
getSFSArray(int index)
Get the element at the specified index as ISFSArray.
|
ISFSObject |
getSFSObject(int index)
Get the element at the specified index as ISFSObject.
|
java.lang.Short |
getShort(int index)
Get the element at the specified index as Short.
|
java.util.Collection<java.lang.Short> |
getShortArray(int index)
Get the element at the specified index as Collection of Short.
|
java.lang.String |
getText(int index)
Get the element at the specified index as long String, with a max length of 2 GBytes.
|
java.lang.Integer |
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 index |
java.util.Collection<java.lang.Integer> |
getUnsignedByteArray(int index)
Get the element at the specified index as a Collection of unsigned integers.
|
java.lang.String |
getUtfString(int index)
Get the element at the specified index as String, with a max length of 32 KBytes.
|
java.util.Collection<java.lang.String> |
getUtfStringArray(int index)
Get the element at the specified index as Collection of String.
|
boolean |
isNull(int index)
Checks if a specific element is null.
|
java.util.Iterator<SFSDataWrapper> |
iterator() |
static SFSArray |
newFromBinaryData(byte[] bytes)
Rebuild an SFSArray form its binary form
|
static SFSArray |
newFromJsonData(java.lang.String jsonStr)
Creates an SFSObject from a JSON literal.
|
static SFSArray |
newFromResultSet(java.sql.ResultSet rset) |
static SFSArray |
newInstance()
Static constructor, similar to new SFSArray();
|
void |
removeElementAt(int index)
Remove an element at a specific index
|
int |
size()
Return the number of elements contained in the array
|
byte[] |
toBinary()
Return the binary representation of the SFSArray
|
java.lang.String |
toJson()
Return the JSON representation of the SFSArray
|
java.lang.String |
toString() |
public static SFSArray newFromBinaryData(byte[] bytes)
bytes - the binary datajava.lang.IllegalStateException - if there's any problem with decoding the binary datapublic static SFSArray newFromResultSet(java.sql.ResultSet rset) throws java.sql.SQLException
java.sql.SQLExceptionpublic static SFSArray newFromJsonData(java.lang.String jsonStr)
| JSON | SFSObject
| Bool
| Bool
| Number
| Integer, Long, Double (autodetect)
| String
| UTF String
| Array
| SFSArray
| Object
| SFSObject
| |
jsonStr - the JSON literalpublic static SFSArray newInstance()
public java.lang.String getDump()
ISFSArraypublic java.lang.String getDump(boolean noFormat)
ISFSArraypublic java.lang.String getHexDump()
ISFSArraygetHexDump in interface ISFSArraypublic byte[] toBinary()
ISFSArraypublic java.lang.String toJson()
ISFSArraypublic boolean isNull(int index)
ISFSArraypublic SFSDataWrapper get(int index)
public java.lang.Boolean getBool(int index)
ISFSArraypublic java.lang.Byte getByte(int index)
ISFSArraypublic java.lang.Integer getUnsignedByte(int index)
ISFSArraygetUnsignedByte in interface ISFSArraypublic java.lang.Short getShort(int index)
ISFSArraypublic java.lang.Integer getInt(int index)
ISFSArraypublic java.lang.Long getLong(int index)
ISFSArraypublic java.lang.Float getFloat(int index)
ISFSArraypublic java.lang.Double getDouble(int index)
ISFSArraypublic java.lang.String getUtfString(int index)
ISFSArraygetUtfString in interface ISFSArraypublic java.lang.String getText(int index)
ISFSArraypublic java.util.Collection<java.lang.Boolean> getBoolArray(int index)
ISFSArraygetBoolArray in interface ISFSArraypublic byte[] getByteArray(int index)
ISFSArrayNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
getByteArray in interface ISFSArraypublic java.util.Collection<java.lang.Integer> getUnsignedByteArray(int index)
ISFSArraygetUnsignedByteArray in interface ISFSArraypublic java.util.Collection<java.lang.Short> getShortArray(int index)
ISFSArraygetShortArray in interface ISFSArraypublic java.util.Collection<java.lang.Integer> getIntArray(int index)
ISFSArraygetIntArray in interface ISFSArraypublic java.util.Collection<java.lang.Long> getLongArray(int index)
ISFSArraygetLongArray in interface ISFSArraypublic java.util.Collection<java.lang.Float> getFloatArray(int index)
ISFSArraygetFloatArray in interface ISFSArraypublic java.util.Collection<java.lang.Double> getDoubleArray(int index)
ISFSArraygetDoubleArray in interface ISFSArraypublic java.util.Collection<java.lang.String> getUtfStringArray(int index)
ISFSArraygetUtfStringArray in interface ISFSArraypublic ISFSArray getSFSArray(int index)
ISFSArraygetSFSArray in interface ISFSArraypublic ISFSObject getSFSObject(int index)
ISFSArraygetSFSObject in interface ISFSArrayISFSObjectpublic java.lang.Object getClass(int index)
ISFSArrayNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
getClass in interface ISFSArraySFSObject.newFromObject(Object)public void addBool(boolean value)
ISFSArraypublic void addBoolArray(java.util.Collection<java.lang.Boolean> value)
ISFSArrayaddBoolArray in interface ISFSArraypublic void addByte(byte value)
ISFSArraypublic void addByteArray(byte[] value)
ISFSArrayNOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
addByteArray in interface ISFSArraypublic void addDouble(double value)
ISFSArraypublic void addDoubleArray(java.util.Collection<java.lang.Double> value)
ISFSArrayaddDoubleArray in interface ISFSArraypublic void addFloat(float value)
ISFSArraypublic void addFloatArray(java.util.Collection<java.lang.Float> value)
ISFSArrayaddFloatArray in interface ISFSArraypublic void addInt(int value)
ISFSArraypublic void addIntArray(java.util.Collection<java.lang.Integer> value)
ISFSArrayaddIntArray in interface ISFSArraypublic void addLong(long value)
ISFSArraypublic void addLongArray(java.util.Collection<java.lang.Long> value)
ISFSArrayaddLongArray in interface ISFSArraypublic void addNull()
ISFSArrayThis method will effectively add the key and a byte id to describe the Null value, thus "bloating" the message
public void addSFSArray(ISFSArray value)
ISFSArrayaddSFSArray in interface ISFSArraypublic void addSFSObject(ISFSObject value)
ISFSArrayaddSFSObject in interface ISFSArraypublic void addShort(short value)
ISFSArraypublic void addShortArray(java.util.Collection<java.lang.Short> value)
ISFSArrayaddShortArray in interface ISFSArraypublic void addUtfString(java.lang.String value)
ISFSArrayaddUtfString in interface ISFSArraypublic void addText(java.lang.String value)
ISFSArraypublic void addUtfStringArray(java.util.Collection<java.lang.String> value)
ISFSArrayaddUtfStringArray in interface ISFSArraypublic void addClass(java.lang.Object o)
ISFSArraySerializableSFSType interface.
NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.
addClass in interface ISFSArrayo - the instanceSFSObject.newFromObject(Object)public void add(SFSDataWrapper wrappedObject)
public boolean contains(java.lang.Object obj)
ISFSArraypublic java.lang.Object getElementAt(int index)
getElementAt in interface ISFSArraypublic java.util.Iterator<SFSDataWrapper> iterator()
public void removeElementAt(int index)
ISFSArrayremoveElementAt in interface ISFSArrayindex - the index of the element to removepublic int size()
ISFSArraypublic java.lang.String toString()
toString in class java.lang.Object