|
SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
|
A platform-neutral container of named values, used to exchange data between client and server. More...
#include <SFSObject.h>
Public Member Functions | |
| bool | isNull (const std::string &key) const |
| Tells if the value stored under a key is a null value. | |
| bool | containsKey (const std::string &key) const |
| bool | removeElement (const std::string &key) |
| Removes a value from this object. | |
| std::vector< std::string > | getKeys () const |
| size_t | size () const |
| std::unique_ptr< ByteBuffer > | toBinary () const |
| std::string | getDump () const |
| std::string | getDump (bool noFormat) const |
| std::string | getHexDump () const |
| std::optional< bool > | getBool (const std::string &key) const |
| std::optional< uint8_t > | getByte (const std::string &key) const |
| std::optional< int16_t > | getShort (const std::string &key) const |
| std::optional< int32_t > | getInt (const std::string &key) const |
| std::optional< int64_t > | getLong (const std::string &key) const |
| std::optional< float > | getFloat (const std::string &key) const |
| std::optional< double > | getDouble (const std::string &key) const |
| std::optional< std::string > | getShortString (const std::string &key) const |
| Reads a UTF-8 string of at most 255 bytes. | |
| std::optional< std::string > | getString (const std::string &key) const |
| Reads a UTF-8 string of at most 32767 bytes. | |
| std::optional< std::string > | getText (const std::string &key) const |
| Reads a UTF-8 string of at most 2 GB. | |
| std::optional< SFSVector2 > | getVector2 (const std::string &key) const |
| std::optional< SFSVector3 > | getVector3 (const std::string &key) const |
| std::optional< std::vector< bool > > | getBoolArray (const std::string &key) const |
| std::optional< std::vector< uint8_t > > | getByteArray (const std::string &key) const |
| const std::vector< uint8_t > * | getByteArrayPtr (const std::string &key) const |
| Reads an array of bytes without copying it. | |
| std::optional< std::vector< int16_t > > | getShortArray (const std::string &key) const |
| std::optional< std::vector< int32_t > > | getIntArray (const std::string &key) const |
| std::optional< std::vector< int64_t > > | getLongArray (const std::string &key) const |
| std::optional< std::vector< float > > | getFloatArray (const std::string &key) const |
| std::optional< std::vector< double > > | getDoubleArray (const std::string &key) const |
| std::optional< std::vector< std::string > > | getStringArray (const std::string &key) const |
| Reads an array of UTF-8 strings, each one of at most 32767 bytes. | |
| std::optional< std::vector< std::string > > | getShortStringArray (const std::string &key) const |
| Reads an array of UTF-8 strings, each one of at most 255 bytes. | |
| std::optional< std::vector< SFSVector2 > > | getVector2Array (const std::string &key) const |
| std::optional< std::vector< SFSVector3 > > | getVector3Array (const std::string &key) const |
| std::shared_ptr< SFSObject > | getSFSObject (const std::string &key) const |
| std::shared_ptr< SFSArray > | getSFSArray (const std::string &key) const |
| void | putNull (std::string key) |
| Adds a null value. | |
| void | putBool (std::string key, bool value) |
| Adds a boolean. | |
| void | putByte (std::string key, uint8_t value) |
| Adds a byte (8 bit). | |
| void | putShort (std::string key, int16_t value) |
| Adds a short (signed 16 bit). | |
| void | putInt (std::string key, int32_t value) |
| Adds an integer (signed 32 bit). | |
| void | putLong (std::string key, int64_t value) |
| Adds a long (signed 64 bit). | |
| void | putFloat (std::string key, float value) |
| Adds a float (signed 32 bit). | |
| void | putDouble (std::string key, double value) |
| Adds a double (signed 64 bit). | |
| void | putString (std::string key, std::string value) |
| Adds a UTF-8 string, with a limit of 32767 bytes. | |
| void | putShortString (std::string key, std::string value) |
| Adds a UTF-8 string, with a limit of 255 bytes. | |
| void | putText (std::string key, std::string value) |
| Adds a UTF-8 string, with a limit of 2 GB. | |
| void | putVector2 (std::string key, SFSVector2 value) |
| Adds a 2D vector. | |
| void | putVector3 (std::string key, SFSVector3 value) |
| Adds a 3D vector. | |
| void | putSFSObject (std::string key, std::shared_ptr< SFSObject > value) |
| Adds a nested SFSObject. | |
| void | putSFSArray (std::string key, std::shared_ptr< SFSArray > value) |
| Adds a nested SFSArray. | |
| void | putSFSObject (std::string key, const SFSObject *value) |
| Adds a copy of a nested SFSObject. | |
| void | putSFSArray (std::string key, const SFSArray *value) |
| Adds a copy of a nested SFSArray. | |
| void | putBoolArray (std::string key, std::vector< bool > value) |
| Adds an array of booleans. | |
| void | putByteArray (std::string key, std::vector< uint8_t > value) |
| Adds an array of bytes. | |
| void | putByteArray (std::string key, const uint8_t *data, size_t length) |
| Adds an array of bytes read from raw memory. | |
| void | putShortArray (std::string key, std::vector< int16_t > value) |
| Adds an array of shorts. | |
| void | putIntArray (std::string key, std::vector< int32_t > value) |
| Adds an array of integers. | |
| void | putLongArray (std::string key, std::vector< int64_t > value) |
| Adds an array of longs. | |
| void | putFloatArray (std::string key, std::vector< float > value) |
| Adds an array of floats. | |
| void | putDoubleArray (std::string key, std::vector< double > value) |
| Adds an array of doubles. | |
| void | putShortStringArray (std::string key, std::vector< std::string > value) |
| Adds an array of UTF-8 strings, each one limited to 255 bytes. | |
| void | putStringArray (std::string key, std::vector< std::string > value) |
| Adds an array of UTF-8 strings, each one limited to 32767 bytes. | |
| void | putVector2Array (std::string key, std::vector< SFSVector2 > value) |
| Adds an array of 2D vectors. | |
| void | putVector3Array (std::string key, std::vector< SFSVector3 > value) |
| Adds an array of 3D vectors. | |
A platform-neutral container of named values, used to exchange data between client and server.
SFSObject holds the data as a map of keys and values; SFSArray holds it as a list. Both carry many different data types, from a single byte to arrays of doubles, strings and more.
These are the supported types and their size limits:
| Type | Item size | Array length |
|---|---|---|
| null | — | |
| bool | 1 byte | |
| byte | 1 byte | |
| short | 2 bytes | |
| int | 4 bytes | |
| long | 8 bytes | |
| float | 4 bytes | |
| double | 8 bytes | |
| SFSVector2 | 8 bytes | |
| SFSVector3 | 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 |
| SFSVector2 array | 8 bytes | <= 2^15 |
| SFSVector3 array | 12 bytes | <= 2^15 |
| short string array | <= 255 bytes | <= 2^15 |
| string array | <= 2^15 bytes | <= 2^15 |
NOTE 1: every key is sent as a short string, so it must be 255 bytes or shorter. Keep the key names as short as you can, to keep the network overhead low.
NOTE 2: every string is UTF-8, so one character can take more than one byte. A string of 255 characters can need more than 255 bytes.
NOTE 3: an SFSObject and an SFSArray can be nested one inside the other, to build more complex data structures.
NOTE 4: the methods of SFSObject and SFSArray are not thread safe.
| bool sfs3::entities::SFSObject::isNull | ( | const std::string & | key | ) | const |
Tells if the value stored under a key is a null value.
| key | the name of the value |
| bool sfs3::entities::SFSObject::containsKey | ( | const std::string & | key | ) | const |
| key | the name to look for |
| bool sfs3::entities::SFSObject::removeElement | ( | const std::string & | key | ) |
Removes a value from this object.
| key | the name of the value to remove |
| std::vector< std::string > sfs3::entities::SFSObject::getKeys | ( | ) | const |
| size_t sfs3::entities::SFSObject::size | ( | ) | const |
| std::unique_ptr< ByteBuffer > sfs3::entities::SFSObject::toBinary | ( | ) | const |
| std::string sfs3::entities::SFSObject::getDump | ( | ) | const |
| std::string sfs3::entities::SFSObject::getDump | ( | bool | noFormat | ) | const |
| noFormat | if true the dump is not pretty-printed |
| std::string sfs3::entities::SFSObject::getHexDump | ( | ) | const |
| std::optional< bool > sfs3::entities::SFSObject::getBool | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< uint8_t > sfs3::entities::SFSObject::getByte | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< int16_t > sfs3::entities::SFSObject::getShort | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< int32_t > sfs3::entities::SFSObject::getInt | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< int64_t > sfs3::entities::SFSObject::getLong | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< float > sfs3::entities::SFSObject::getFloat | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< double > sfs3::entities::SFSObject::getDouble | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::string > sfs3::entities::SFSObject::getShortString | ( | const std::string & | key | ) | const |
Reads a UTF-8 string of at most 255 bytes.
| key | the name of the value |
| std::optional< std::string > sfs3::entities::SFSObject::getString | ( | const std::string & | key | ) | const |
Reads a UTF-8 string of at most 32767 bytes.
| key | the name of the value |
| std::optional< std::string > sfs3::entities::SFSObject::getText | ( | const std::string & | key | ) | const |
Reads a UTF-8 string of at most 2 GB.
| key | the name of the value |
| std::optional< SFSVector2 > sfs3::entities::SFSObject::getVector2 | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< SFSVector3 > sfs3::entities::SFSObject::getVector3 | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< bool > > sfs3::entities::SFSObject::getBoolArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< uint8_t > > sfs3::entities::SFSObject::getByteArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| const std::vector< uint8_t > * sfs3::entities::SFSObject::getByteArrayPtr | ( | const std::string & | key | ) | const |
Reads an array of bytes without copying it.
Use it in place of SFSObject::getByteArray for a large array. The pointer stays valid as long as this object holds the value and is not changed.
| key | the name of the value |
nullptr if there is no such value | std::optional< std::vector< int16_t > > sfs3::entities::SFSObject::getShortArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< int32_t > > sfs3::entities::SFSObject::getIntArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< int64_t > > sfs3::entities::SFSObject::getLongArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< float > > sfs3::entities::SFSObject::getFloatArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< double > > sfs3::entities::SFSObject::getDoubleArray | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< std::string > > sfs3::entities::SFSObject::getStringArray | ( | const std::string & | key | ) | const |
Reads an array of UTF-8 strings, each one of at most 32767 bytes.
| key | the name of the value |
| std::optional< std::vector< std::string > > sfs3::entities::SFSObject::getShortStringArray | ( | const std::string & | key | ) | const |
Reads an array of UTF-8 strings, each one of at most 255 bytes.
| key | the name of the value |
| std::optional< std::vector< SFSVector2 > > sfs3::entities::SFSObject::getVector2Array | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::optional< std::vector< SFSVector3 > > sfs3::entities::SFSObject::getVector3Array | ( | const std::string & | key | ) | const |
| key | the name of the value |
| std::shared_ptr< SFSObject > sfs3::entities::SFSObject::getSFSObject | ( | const std::string & | key | ) | const |
| key | the name of the value |
nullptr if there is no such value | std::shared_ptr< SFSArray > sfs3::entities::SFSObject::getSFSArray | ( | const std::string & | key | ) | const |
| void sfs3::entities::SFSObject::putNull | ( | std::string | key | ) |
Adds a null value.
We recommend that you simply do not send a value that is null. On the other side of the connection, check if the key exists instead. This method adds the key and one byte that marks the null value, so it makes the message bigger for nothing.
| key | the name of the value |
| void sfs3::entities::SFSObject::putBool | ( | std::string | key, |
| bool | value ) |
Adds a boolean.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putByte | ( | std::string | key, |
| uint8_t | value ) |
Adds a byte (8 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putShort | ( | std::string | key, |
| int16_t | value ) |
Adds a short (signed 16 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putInt | ( | std::string | key, |
| int32_t | value ) |
Adds an integer (signed 32 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putLong | ( | std::string | key, |
| int64_t | value ) |
Adds a long (signed 64 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putFloat | ( | std::string | key, |
| float | value ) |
Adds a float (signed 32 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putDouble | ( | std::string | key, |
| double | value ) |
Adds a double (signed 64 bit).
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putString | ( | std::string | key, |
| std::string | value ) |
Adds a UTF-8 string, with a limit of 32767 bytes.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putShortString | ( | std::string | key, |
| std::string | value ) |
Adds a UTF-8 string, with a limit of 255 bytes.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putText | ( | std::string | key, |
| std::string | value ) |
Adds a UTF-8 string, with a limit of 2 GB.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putVector2 | ( | std::string | key, |
| SFSVector2 | value ) |
Adds a 2D vector.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putVector3 | ( | std::string | key, |
| SFSVector3 | value ) |
Adds a 3D vector.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putSFSObject | ( | std::string | key, |
| std::shared_ptr< SFSObject > | value ) |
Adds a nested SFSObject.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putSFSArray | ( | std::string | key, |
| std::shared_ptr< SFSArray > | value ) |
| void sfs3::entities::SFSObject::putSFSObject | ( | std::string | key, |
| const SFSObject * | value ) |
| void sfs3::entities::SFSObject::putSFSArray | ( | std::string | key, |
| const SFSArray * | value ) |
| void sfs3::entities::SFSObject::putBoolArray | ( | std::string | key, |
| std::vector< bool > | value ) |
Adds an array of booleans.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putByteArray | ( | std::string | key, |
| std::vector< uint8_t > | value ) |
Adds an array of bytes.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putByteArray | ( | std::string | key, |
| const uint8_t * | data, | ||
| size_t | length ) |
Adds an array of bytes read from raw memory.
The bytes are copied, so the caller keeps the ownership of the memory it passes.
| key | the name of the value |
| data | the first byte to copy |
| length | how many bytes to copy |
| void sfs3::entities::SFSObject::putShortArray | ( | std::string | key, |
| std::vector< int16_t > | value ) |
Adds an array of shorts.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putIntArray | ( | std::string | key, |
| std::vector< int32_t > | value ) |
Adds an array of integers.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putLongArray | ( | std::string | key, |
| std::vector< int64_t > | value ) |
Adds an array of longs.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putFloatArray | ( | std::string | key, |
| std::vector< float > | value ) |
Adds an array of floats.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putDoubleArray | ( | std::string | key, |
| std::vector< double > | value ) |
Adds an array of doubles.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putShortStringArray | ( | std::string | key, |
| std::vector< std::string > | value ) |
Adds an array of UTF-8 strings, each one limited to 255 bytes.
The array itself is limited to 32767 strings.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putStringArray | ( | std::string | key, |
| std::vector< std::string > | value ) |
Adds an array of UTF-8 strings, each one limited to 32767 bytes.
The array itself is limited to 32767 strings.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putVector2Array | ( | std::string | key, |
| std::vector< SFSVector2 > | value ) |
Adds an array of 2D vectors.
| key | the name of the value |
| value | the value |
| void sfs3::entities::SFSObject::putVector3Array | ( | std::string | key, |
| std::vector< SFSVector3 > | value ) |
Adds an array of 3D vectors.
| key | the name of the value |
| value | the value |