SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
BareNetworkString Class Reference

Describes a chain of 8-bit unsigned integers. More...

#include <network_string.hpp>

Inheritance diagram for BareNetworkString:
Inheritance graph
[legend]

Public Member Functions

 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.
 
int decodeStringW (irr::core::stringw *out) const
 Returns an irrlicht wide string from the utf8 encoded string at the given position.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Protected Member Functions

std::string getString (int len) const
 Returns a part of the network string as a std::string.
 
BareNetworkStringaddString (const std::string &value)
 Adds a std::string.
 
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

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.
 

Private Member Functions

 LEAK_CHECK ()
 

Friends

class Crypto
 

Detailed Description

Describes a chain of 8-bit unsigned integers.

This class allows you to easily create and parse 8-bit strings, has functions to add and read other data types (e.g. int, strings). It does not enforce any structure on the sequence (NetworkString uses this as a base class, and enforces a protocol type in the first byte)

Member Function Documentation

◆ addString()

BareNetworkString & BareNetworkString::addString ( const std::string &  value)
inlineprotected

Adds a std::string.

Internal use only.

◆ addTime()

BareNetworkString & BareNetworkString::addTime ( int  ticks)
inline

Adds a function to add a time ticks value.

Use this function instead of addUInt32 because we might decide later to compress time values (e.g. sending 16 bytes for as long as possible).

◆ decodeString()

int BareNetworkString::decodeString ( std::string *  out) const

Returns a string at the given position.

The first byte indicates the length, followed by the actual string (not 0 terminated).

Parameters
[in]posBuffer position where the encoded string starts.
[out]outThe decoded string.
Returns
number of bytes read = 1+length of string

◆ decodeStringW()

int BareNetworkString::decodeStringW ( irr::core::stringw *  out) const

Returns an irrlicht wide string from the utf8 encoded string at the given position.

Parameters
[out]outThe decoded string.
Returns
number of bytes read. If there are no special characters in the string that will be 1+length of string, but multi-byte encoded characters can mean that the length of the returned string is less than the number of bytes read.

◆ getLogMessage()

std::string BareNetworkString::getLogMessage ( const std::string &  indent = "") const

Returns a string representing this message suitable to be printed to stdout or via the Log mechanism.

Format 0000 : 1234 5678 9abc ... ASCII-

◆ getString()

std::string BareNetworkString::getString ( int  len) const
inlineprotected

Returns a part of the network string as a std::string.

This is an internal function only, the user should call decodeString(W) instead.

Parameters
posFirst position to be in the string.
lenNumber of bytes to copy.

◆ getTotalSize()

unsigned int BareNetworkString::getTotalSize ( ) const
inline

Returns the send size, which is the full length of the buffer.

A difference to size() happens if the string to be sent was previously read, and has m_current_offset != 0. Even in this case the whole string must be sent.

◆ operator+=()

BareNetworkString & BareNetworkString::operator+= ( BareNetworkString const &  value)
inline

Adds the content of another network string.

It only copies data which has not been 'removed' (i.e. skipped).

Member Data Documentation

◆ m_current_offset

int BareNetworkString::m_current_offset
mutableprotected

To avoid copying the buffer when bytes are deleted (which only happens at the front), use an offset index.

All positions given by the user will be relative to this index. Note that the type should be left as signed, otherwise certain arithmetic will be done unsigned).


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