SuperTuxKart
Public Member Functions | Static Public Member Functions | List of all members
NetworkString Class Reference

A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message, which is actually a bit field: bit 7: if set, the message needs to be handled synchronously, otherwise it can be handled by the separate protocol manager thread. More...

#include <network_string.hpp>

Inheritance diagram for NetworkString:
Inheritance graph
[legend]

Public Member Functions

 NetworkString (ProtocolType type, int capacity=16)
 Constructor for a message to be sent. More...
 
 NetworkString (const uint8_t *data, int len)
 Constructor for a received message. More...
 
void clear ()
 Empties the string, but does not reset the pre-allocated size.
 
ProtocolType getProtocolType () const
 Returns the protocol type of this message.
 
void setSynchronous (bool b)
 Sets if this message is to be sent synchronous or asynchronous.
 
bool isSynchronous () const
 Returns if this message is synchronous or not.
 
- Public Member Functions inherited from BareNetworkString
 BareNetworkString (int capacity=16)
 Constructor, sets the protocol type of this message.
 
 BareNetworkString (const std::string &s)
 
 BareNetworkString (const char *data, int len)
 Initialises the string with a sequence of characters.
 
void reset ()
 Allows one to read a buffer from the beginning again.
 
BareNetworkStringencodeString16 (const irr::core::stringw &value, uint16_t max_len=65535)
 Encode string with max length of 16bit and utf32, used in motd or chat.
 
int decodeString16 (irr::core::stringw *out, uint16_t max_len=65535)
 
BareNetworkStringencodeString (const std::string &value)
 Adds one byte for the length of the string, and then (up to 255 of) the characters of the given string.
 
BareNetworkStringencodeString (const irr::core::stringw &value)
 Adds one byte for the length of the string, and then (up to 255 of) the characters of the given string.
 
int decodeString (std::string *out) const
 Returns a string at the given position. More...
 
int decodeStringW (irr::core::stringw *out) const
 Returns an irrlicht wide string from the utf8 encoded string at the given position. More...
 
std::string getLogMessage (const std::string &indent="") const
 Returns a string representing this message suitable to be printed to stdout or via the Log mechanism. More...
 
std::vector< uint8_t > & getBuffer ()
 Returns the internal buffer of the network string.
 
char * getData ()
 Returns a byte pointer to the content of the network string.
 
const char * getData () const
 Returns a byte pointer to the content of the network string.
 
char * getCurrentData ()
 Returns a byte pointer to the unread remaining content of the network string.
 
const char * getCurrentData () const
 Returns a byte pointer to the unread remaining content of the network string.
 
int getCurrentOffset () const
 
unsigned int size () const
 Returns the remaining length of the network string.
 
void skip (int n)
 Skips the specified number of bytes when reading.
 
unsigned int getTotalSize () const
 Returns the send size, which is the full length of the buffer. More...
 
BareNetworkStringaddUInt8 (const uint8_t value)
 Add 8 bit unsigned int.
 
BareNetworkStringaddChar (const char value)
 Adds a single character to the string.
 
BareNetworkStringaddUInt16 (const uint16_t value)
 Adds 16 bit unsigned int.
 
BareNetworkStringaddInt24 (const int value)
 Adds signed 24 bit integer.
 
BareNetworkStringaddUInt32 (const uint32_t &value)
 Adds unsigned 32 bit integer.
 
BareNetworkStringaddUInt64 (const uint64_t &value)
 Adds unsigned 64 bit integer.
 
BareNetworkStringaddFloat (const float value)
 Adds a 4 byte floating point value.
 
BareNetworkStringoperator+= (BareNetworkString const &value)
 Adds the content of another network string. More...
 
BareNetworkStringadd (float f)
 Adds a floating point number.
 
BareNetworkStringadd (const Vec3 &xyz)
 Adds the xyz components of a Vec3 to the string.
 
BareNetworkStringadd (const btQuaternion &quat)
 Adds the four components of a quaternion.
 
BareNetworkStringaddTime (int ticks)
 Adds a function to add a time ticks value. More...
 
uint64_t getUInt64 () const
 Returns a unsigned 64 bit integer.
 
uint32_t getUInt32 () const
 Returns a unsigned 32 bit integer.
 
int getInt24 () const
 Returns a signed 24 bit integer.
 
uint32_t getTime () const
 Returns a unsigned 32 bit integer.
 
uint16_t getUInt16 () const
 Returns an unsigned 16 bit integer.
 
int16_t getInt16 () const
 Returns an unsigned 16 bit integer.
 
uint8_t getUInt8 () const
 Returns an unsigned 8-bit integer.
 
int8_t getInt8 () const
 Returns an unsigned 8-bit integer.
 
float getFloat () const
 Gets a 4 byte floating point value.
 
Vec3 getVec3 () const
 Gets a Vec3.
 
btQuaternion getQuat () const
 Gets a bullet quaternion.
 

Static Public Member Functions

static void unitTesting ()
 Unit testing function.
 

Additional Inherited Members

- Protected Member Functions inherited from BareNetworkString
std::string getString (int len) const
 Returns a part of the network string as a std::string. More...
 
BareNetworkStringaddString (const std::string &value)
 Adds a std::string. More...
 
template<typename T , size_t n>
get () const
 Template to get n bytes from a buffer into a single data type.
 
template<typename T >
get () const
 Another function for n == 1 to surpress warnings in clang.
 
- Protected Attributes inherited from BareNetworkString
std::vector< uint8_t > m_buffer
 The actual buffer.
 
int m_current_offset
 To avoid copying the buffer when bytes are deleted (which only happens at the front), use an offset index. More...
 

Detailed Description

A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message, which is actually a bit field: bit 7: if set, the message needs to be handled synchronously, otherwise it can be handled by the separate protocol manager thread.

bits 6-0: The protocol ID, which identifies the receiving protocol for this message.

Otherwise this class offers template functions to add arbitrary variables, and retrieve them again. It kept the functionality of 'removing' bytes (e.g. the ProtocolManager would remove the first byte - protocol type - so that the protocols would not see this byte). But this is implemented now by using a base pointer (and not by moving the buffer content).

Constructor & Destructor Documentation

◆ NetworkString() [1/2]

NetworkString::NetworkString ( ProtocolType  type,
int  capacity = 16 
)
inline

Constructor for a message to be sent.

It sets the protocol type of this message. It adds 1 byte to the capacity: 1 byte for the protocol type.

◆ NetworkString() [2/2]

NetworkString::NetworkString ( const uint8_t *  data,
int  len 
)
inline

Constructor for a received message.

It automatically ignored the first 5 bytes which contain the type. Those will be accessed using special functions.


The documentation for this class was generated from the following files: