SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
Loading...
Searching...
No Matches
sfs3::entities::SFSArray Class Reference

A platform-neutral list of values, used to exchange data between client and server. More...

#include <SFSArray.h>

Public Member Functions

bool isNull (size_t index) const
 Tells if the value at the given position is a null value.
bool removeElement (size_t index)
 Removes the value at the given position.
size_t size () const
std::unique_ptr< ByteBuffertoBinary () const
std::string getDump () const
std::string getDump (bool noFormat) const
std::string getHexDump () const
std::optional< bool > getBool (size_t index) const
std::optional< uint8_t > getByte (size_t index) const
std::optional< int16_t > getShort (size_t index) const
std::optional< int32_t > getInt (size_t index) const
std::optional< int64_t > getLong (size_t index) const
std::optional< float > getFloat (size_t index) const
std::optional< double > getDouble (size_t index) const
std::optional< std::string > getShortString (size_t index) const
 Reads a UTF-8 string of at most 255 bytes.
std::optional< std::string > getString (size_t index) const
 Reads a UTF-8 string of at most 32767 bytes.
std::optional< std::string > getText (size_t index) const
 Reads a UTF-8 string of at most 2 GB.
std::optional< SFSVector2getVector2 (size_t index) const
std::optional< SFSVector3getVector3 (size_t index) const
std::optional< std::vector< bool > > getBoolArray (size_t index) const
std::optional< std::vector< uint8_t > > getByteArray (size_t index) const
const std::vector< uint8_t > * getByteArrayPtr (size_t index) const
 Reads an array of bytes without copying it.
std::optional< std::vector< int16_t > > getShortArray (size_t index) const
std::optional< std::vector< int32_t > > getIntArray (size_t index) const
std::optional< std::vector< int64_t > > getLongArray (size_t index) const
std::optional< std::vector< float > > getFloatArray (size_t index) const
std::optional< std::vector< double > > getDoubleArray (size_t index) const
std::optional< std::vector< std::string > > getStringArray (size_t index) const
 Reads an array of UTF-8 strings, each one of at most 32767 bytes.
std::optional< std::vector< std::string > > getShortStringArray (size_t index) const
 Reads an array of UTF-8 strings, each one of at most 255 bytes.
std::optional< std::vector< SFSVector2 > > getVector2Array (size_t index) const
std::optional< std::vector< SFSVector3 > > getVector3Array (size_t index) const
std::shared_ptr< SFSObjectgetSFSObject (size_t index) const
std::shared_ptr< SFSArray > getSFSArray (size_t index) const
void addNull ()
 Appends a null value.
void addBool (bool value)
 Appends a boolean.
void addByte (uint8_t value)
 Appends a byte (8 bit).
void addShort (int16_t value)
 Appends a short (signed 16 bit).
void addInt (int32_t value)
 Appends an integer (signed 32 bit).
void addLong (int64_t value)
 Appends a long (signed 64 bit).
void addFloat (float value)
 Appends a float (signed 32 bit).
void addDouble (double value)
 Appends a double (signed 64 bit).
void addString (std::string value)
 Appends a UTF-8 string, with a limit of 32767 bytes.
void addShortString (std::string value)
 Appends a UTF-8 string, with a limit of 255 bytes.
void addText (std::string value)
 Appends a UTF-8 string, with a limit of 2 GB.
void addVector2 (SFSVector2 value)
 Appends a 2D vector.
void addVector3 (SFSVector3 value)
 Appends a 3D vector.
void addBoolArray (std::vector< bool > value)
 Appends an array of booleans.
void addByteArray (std::vector< uint8_t > value)
 Appends an array of bytes.
void addByteArray (const uint8_t *data, size_t length)
 Appends an array of bytes read from raw memory.
void addShortArray (std::vector< int16_t > value)
 Appends an array of shorts.
void addIntArray (std::vector< int32_t > value)
 Appends an array of integers.
void addLongArray (std::vector< int64_t > value)
 Appends an array of longs.
void addFloatArray (std::vector< float > value)
 Appends an array of floats.
void addDoubleArray (std::vector< double > value)
 Appends an array of doubles.
void addShortStringArray (std::vector< std::string > value)
 Appends an array of UTF-8 strings, each one limited to 255 bytes.
void addStringArray (std::vector< std::string > value)
 Appends an array of UTF-8 strings, each one limited to 32767 bytes.
void addVector2Array (std::vector< SFSVector2 > value)
 Appends an array of 2D vectors.
void addVector3Array (std::vector< SFSVector3 > value)
 Appends an array of 3D vectors.
void addSFSObject (std::shared_ptr< SFSObject > value)
 Appends a nested SFSObject.
void addSFSArray (std::shared_ptr< SFSArray > value)
 Appends a nested SFSArray.

Detailed Description

A platform-neutral list of values, used to exchange data between client and server.

It is the list counterpart of SFSObject, and it carries the same data types with the same size limits. Read the description of SFSObject for the full table of types and for the notes on strings, nesting and thread safety.

Every getter takes the position of the value in the list, counted from zero.

See also
SFSObject

Member Function Documentation

◆ isNull()

bool sfs3::entities::SFSArray::isNull ( size_t index) const

Tells if the value at the given position is a null value.

Parameters
indexthe position of the value
Returns
true if the value is null

◆ removeElement()

bool sfs3::entities::SFSArray::removeElement ( size_t index)

Removes the value at the given position.

Parameters
indexthe position of the value to remove
Returns
true if there was a value at that position

◆ size()

size_t sfs3::entities::SFSArray::size ( ) const
inline
Returns
the number of values in this array

◆ toBinary()

std::unique_ptr< ByteBuffer > sfs3::entities::SFSArray::toBinary ( ) const
Returns
this array in its serialized, binary form

◆ getDump() [1/2]

std::string sfs3::entities::SFSArray::getDump ( ) const
Returns
a detailed, pretty-printed dump of the structure of this array

◆ getDump() [2/2]

std::string sfs3::entities::SFSArray::getDump ( bool noFormat) const
Parameters
noFormatif true the dump is not pretty-printed
Returns
a detailed dump of the structure of this array

◆ getHexDump()

std::string sfs3::entities::SFSArray::getHexDump ( ) const
Returns
a pretty-printed hexadecimal dump of this array

◆ getBool()

std::optional< bool > sfs3::entities::SFSArray::getBool ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a boolean, or an empty optional if there is no such value

◆ getByte()

std::optional< uint8_t > sfs3::entities::SFSArray::getByte ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a byte (8 bit), or an empty optional if there is no such value

◆ getShort()

std::optional< int16_t > sfs3::entities::SFSArray::getShort ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a short (signed 16 bit), or an empty optional if there is no such value

◆ getInt()

std::optional< int32_t > sfs3::entities::SFSArray::getInt ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an integer (signed 32 bit), or an empty optional if there is no such value

◆ getLong()

std::optional< int64_t > sfs3::entities::SFSArray::getLong ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a long (signed 64 bit), or an empty optional if there is no such value

◆ getFloat()

std::optional< float > sfs3::entities::SFSArray::getFloat ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a float (signed decimal 32 bit), or an empty optional if there is no such value

◆ getDouble()

std::optional< double > sfs3::entities::SFSArray::getDouble ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a double (signed decimal 64 bit), or an empty optional if there is no such value

◆ getShortString()

std::optional< std::string > sfs3::entities::SFSArray::getShortString ( size_t index) const

Reads a UTF-8 string of at most 255 bytes.

Parameters
indexthe position of the value
Returns
the value as a string, or an empty optional if there is no such value

◆ getString()

std::optional< std::string > sfs3::entities::SFSArray::getString ( size_t index) const

Reads a UTF-8 string of at most 32767 bytes.

Parameters
indexthe position of the value
Returns
the value as a string, or an empty optional if there is no such value

◆ getText()

std::optional< std::string > sfs3::entities::SFSArray::getText ( size_t index) const

Reads a UTF-8 string of at most 2 GB.

Parameters
indexthe position of the value
Returns
the value as a string, or an empty optional if there is no such value

◆ getVector2()

std::optional< SFSVector2 > sfs3::entities::SFSArray::getVector2 ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a 2D vector, or an empty optional if there is no such value

◆ getVector3()

std::optional< SFSVector3 > sfs3::entities::SFSArray::getVector3 ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as a 3D vector, or an empty optional if there is no such value

◆ getBoolArray()

std::optional< std::vector< bool > > sfs3::entities::SFSArray::getBoolArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of booleans, or an empty optional if there is no such value

◆ getByteArray()

std::optional< std::vector< uint8_t > > sfs3::entities::SFSArray::getByteArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of bytes, or an empty optional if there is no such value
See also
SFSArray::getByteArrayPtr

◆ getByteArrayPtr()

const std::vector< uint8_t > * sfs3::entities::SFSArray::getByteArrayPtr ( size_t index) const

Reads an array of bytes without copying it.

Use it in place of SFSArray::getByteArray for a large array. The pointer stays valid as long as this array holds the value and is not changed.

Parameters
indexthe position of the value
Returns
a pointer to the array, or nullptr if there is no such value

◆ getShortArray()

std::optional< std::vector< int16_t > > sfs3::entities::SFSArray::getShortArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of shorts, or an empty optional if there is no such value

◆ getIntArray()

std::optional< std::vector< int32_t > > sfs3::entities::SFSArray::getIntArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of integers, or an empty optional if there is no such value

◆ getLongArray()

std::optional< std::vector< int64_t > > sfs3::entities::SFSArray::getLongArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of longs, or an empty optional if there is no such value

◆ getFloatArray()

std::optional< std::vector< float > > sfs3::entities::SFSArray::getFloatArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of floats, or an empty optional if there is no such value

◆ getDoubleArray()

std::optional< std::vector< double > > sfs3::entities::SFSArray::getDoubleArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of doubles, or an empty optional if there is no such value

◆ getStringArray()

std::optional< std::vector< std::string > > sfs3::entities::SFSArray::getStringArray ( size_t index) const

Reads an array of UTF-8 strings, each one of at most 32767 bytes.

Parameters
indexthe position of the value
Returns
the value as an array of strings, or an empty optional if there is no such value

◆ getShortStringArray()

std::optional< std::vector< std::string > > sfs3::entities::SFSArray::getShortStringArray ( size_t index) const

Reads an array of UTF-8 strings, each one of at most 255 bytes.

Parameters
indexthe position of the value
Returns
the value as an array of strings, or an empty optional if there is no such value

◆ getVector2Array()

std::optional< std::vector< SFSVector2 > > sfs3::entities::SFSArray::getVector2Array ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of 2D vectors, or an empty optional if there is no such value

◆ getVector3Array()

std::optional< std::vector< SFSVector3 > > sfs3::entities::SFSArray::getVector3Array ( size_t index) const
Parameters
indexthe position of the value
Returns
the value as an array of 3D vectors, or an empty optional if there is no such value

◆ getSFSObject()

std::shared_ptr< SFSObject > sfs3::entities::SFSArray::getSFSObject ( size_t index) const
Parameters
indexthe position of the value
Returns
the nested SFSObject, or nullptr if there is no such value
See also
SFSObject

◆ getSFSArray()

std::shared_ptr< SFSArray > sfs3::entities::SFSArray::getSFSArray ( size_t index) const
Parameters
indexthe position of the value
Returns
the nested SFSArray, or nullptr if there is no such value

◆ addNull()

void sfs3::entities::SFSArray::addNull ( )

Appends a null value.

We recommend that you simply do not send a value that is null. This method adds one byte that marks the null value, so it makes the message bigger for nothing.

◆ addBool()

void sfs3::entities::SFSArray::addBool ( bool value)

Appends a boolean.

Parameters
valuethe value

◆ addByte()

void sfs3::entities::SFSArray::addByte ( uint8_t value)

Appends a byte (8 bit).

Parameters
valuethe value

◆ addShort()

void sfs3::entities::SFSArray::addShort ( int16_t value)

Appends a short (signed 16 bit).

Parameters
valuethe value

◆ addInt()

void sfs3::entities::SFSArray::addInt ( int32_t value)

Appends an integer (signed 32 bit).

Parameters
valuethe value

◆ addLong()

void sfs3::entities::SFSArray::addLong ( int64_t value)

Appends a long (signed 64 bit).

Parameters
valuethe value

◆ addFloat()

void sfs3::entities::SFSArray::addFloat ( float value)

Appends a float (signed 32 bit).

Parameters
valuethe value

◆ addDouble()

void sfs3::entities::SFSArray::addDouble ( double value)

Appends a double (signed 64 bit).

Parameters
valuethe value

◆ addString()

void sfs3::entities::SFSArray::addString ( std::string value)

Appends a UTF-8 string, with a limit of 32767 bytes.

Parameters
valuethe value
See also
SFSArray::addShortString
SFSArray::addText

◆ addShortString()

void sfs3::entities::SFSArray::addShortString ( std::string value)

Appends a UTF-8 string, with a limit of 255 bytes.

Parameters
valuethe value

◆ addText()

void sfs3::entities::SFSArray::addText ( std::string value)

Appends a UTF-8 string, with a limit of 2 GB.

Parameters
valuethe value

◆ addVector2()

void sfs3::entities::SFSArray::addVector2 ( SFSVector2 value)

Appends a 2D vector.

Parameters
valuethe value

◆ addVector3()

void sfs3::entities::SFSArray::addVector3 ( SFSVector3 value)

Appends a 3D vector.

Parameters
valuethe value

◆ addBoolArray()

void sfs3::entities::SFSArray::addBoolArray ( std::vector< bool > value)

Appends an array of booleans.

Parameters
valuethe value

◆ addByteArray() [1/2]

void sfs3::entities::SFSArray::addByteArray ( std::vector< uint8_t > value)

Appends an array of bytes.

Parameters
valuethe value

◆ addByteArray() [2/2]

void sfs3::entities::SFSArray::addByteArray ( const uint8_t * data,
size_t length )

Appends an array of bytes read from raw memory.

The bytes are copied, so the caller keeps the ownership of the memory it passes.

Parameters
datathe first byte to copy
lengthhow many bytes to copy

◆ addShortArray()

void sfs3::entities::SFSArray::addShortArray ( std::vector< int16_t > value)

Appends an array of shorts.

Parameters
valuethe value

◆ addIntArray()

void sfs3::entities::SFSArray::addIntArray ( std::vector< int32_t > value)

Appends an array of integers.

Parameters
valuethe value

◆ addLongArray()

void sfs3::entities::SFSArray::addLongArray ( std::vector< int64_t > value)

Appends an array of longs.

Parameters
valuethe value

◆ addFloatArray()

void sfs3::entities::SFSArray::addFloatArray ( std::vector< float > value)

Appends an array of floats.

Parameters
valuethe value

◆ addDoubleArray()

void sfs3::entities::SFSArray::addDoubleArray ( std::vector< double > value)

Appends an array of doubles.

Parameters
valuethe value

◆ addShortStringArray()

void sfs3::entities::SFSArray::addShortStringArray ( std::vector< std::string > value)

Appends an array of UTF-8 strings, each one limited to 255 bytes.

The array itself is limited to 32767 strings.

Parameters
valuethe value

◆ addStringArray()

void sfs3::entities::SFSArray::addStringArray ( std::vector< std::string > value)

Appends an array of UTF-8 strings, each one limited to 32767 bytes.

The array itself is limited to 32767 strings.

Parameters
valuethe value

◆ addVector2Array()

void sfs3::entities::SFSArray::addVector2Array ( std::vector< SFSVector2 > value)

Appends an array of 2D vectors.

Parameters
valuethe value

◆ addVector3Array()

void sfs3::entities::SFSArray::addVector3Array ( std::vector< SFSVector3 > value)

Appends an array of 3D vectors.

Parameters
valuethe value

◆ addSFSObject()

void sfs3::entities::SFSArray::addSFSObject ( std::shared_ptr< SFSObject > value)

Appends a nested SFSObject.

Parameters
valuethe value
See also
SFSObject

◆ addSFSArray()

void sfs3::entities::SFSArray::addSFSArray ( std::shared_ptr< SFSArray > value)

Appends a nested SFSArray.

Parameters
valuethe value

The documentation for this class was generated from the following files:
  • entities/SFSArray.h
  • entities/SFSArray.cpp