Class: SFSArray


SFSObject and SFSArray classes represent a platform-neutral, high level Java objects that abstract the data transport between client and server. They are used to respectively represent data in form of a map and a list; they can be nested and transport many different data types.

These objects provide high speed serialization using the default SmartFoxServer binary protocol and the types distinction grants a fine-grained size control of data sent over the network.

The following is a list of types supported by the SFSArray class:

  • null
  • boolean
  • byte (8 bit integer)
  • short (16 bit integer)
  • int (32 bit integer)
  • long (64 bit integer)
  • float (32 bit floating point number)
  • double (64 bit double precision number)
  • utf-string (UTF-8 encoded string, with length up to 32 KBytes)
  • text (UTF-8 encoded string, with length up to 2 GBytes)
  • boolean array
  • byte array
  • short array
  • int array
  • long array
  • float array
  • double array
  • utf-string array
  • SFSObject
  • SFSArray

SFSObjects and SFSArrays can be nested to create complex data structures.
Using a SFSArray can help to further reduce to a minimum the amount of bytes sent, because it avoids the overhead of key names for each item like in a SFSObject.


  • For members of the SFSArray class, please refer to its Javadoc.
  • Strings are handled via UTF-8 encoding, to support all languages and character sets.
  • In JavaScript, long integer numbers are limited to Number.MAX_SAFE_INTEGER (positive and negative, inclusive). This is inconsistent with the max and min Long values available in Java, which are down to -2^63 and up to (2^63)-1.

See also


new SFSArray()

Creates a new SFSArray instance.

In this simple example we create a new SFSArray to send the data of a combat vehicle to clients in a multiplayer game.
We use a single Byte (signed 8-bit) to send the small integer value representing the vehicle's id, a Short (signed 16-bit) for the larger health value and an array of Int to transmit the x/y position of the vehicle.

var sfsa = new SFSArray();
sfsa.addByte(10);               // the vehicle id
sfsa.addShort(5000);            // the vehicle current health
sfsa.addIntArray([120,150]);    // the vehicle x,y position on the terrain, as a nested array
sfsa.addUtfString("Hurricane"); // the vehicle name