SuperTuxKart
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. More...
 
 BareNetworkString (const std::string &s)
 
 BareNetworkString (const char *data, int len)
 Initialises the string with a sequence of characters. More...
 
void reset ()
 Allows one to read a buffer from the beginning again. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
char * getData ()
 Returns a byte pointer to the content of the network string. More...
 
const char * getData () const
 Returns a byte pointer to the content of the network string. More...
 
char * getCurrentData ()
 Returns a byte pointer to the unread remaining content of the network string. More...
 
const char * getCurrentData () const
 Returns a byte pointer to the unread remaining content of the network string. More...
 
int getCurrentOffset () const
 
unsigned int size () const
 Returns the remaining length of the network string. More...
 
void skip (int n)
 Skips the specified number of bytes when reading. More...
 
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. More...
 
BareNetworkStringaddChar (const char value)
 Adds a single character to the string. More...
 
BareNetworkStringaddUInt16 (const uint16_t value)
 Adds 16 bit unsigned int. More...
 
BareNetworkStringaddInt24 (const int value)
 Adds signed 24 bit integer. More...
 
BareNetworkStringaddUInt32 (const uint32_t &value)
 Adds unsigned 32 bit integer. More...
 
BareNetworkStringaddUInt64 (const uint64_t &value)
 Adds unsigned 64 bit integer. More...
 
BareNetworkStringaddFloat (const float value)
 Adds a 4 byte floating point value. More...
 
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. More...
 
BareNetworkStringadd (const btQuaternion &quat)
 Adds the four components of a quaternion. More...
 
BareNetworkStringaddTime (int ticks)
 Adds a function to add a time ticks value. More...
 
uint64_t getUInt64 () const
 Returns a unsigned 64 bit integer. More...
 
uint32_t getUInt32 () const
 Returns a unsigned 32 bit integer. More...
 
int getInt24 () const
 Returns a signed 24 bit integer. More...
 
uint32_t getTime () const
 Returns a unsigned 32 bit integer. More...
 
uint16_t getUInt16 () const
 Returns an unsigned 16 bit integer. More...
 
int16_t getInt16 () const
 Returns an unsigned 16 bit integer. More...
 
uint8_t getUInt8 () const
 Returns an unsigned 8-bit integer. More...
 
int8_t getInt8 () const
 Returns an unsigned 8-bit integer. More...
 
float getFloat () const
 Gets a 4 byte floating point value. More...
 
Vec3 getVec3 () const
 Gets a Vec3. More...
 
btQuaternion getQuat () const
 Gets a bullet quaternion. More...
 

Protected Member Functions

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. More...
 
template<typename T >
get () const
 Another function for n == 1 to surpress warnings in clang. More...
 

Protected Attributes

std::vector< uint8_t > m_buffer
 The actual buffer. More...
 
int m_current_offset
 To avoid copying the buffer when bytes are deleted (which only happens at the front), use an offset index. More...
 

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)

Constructor & Destructor Documentation

◆ BareNetworkString() [1/2]

BareNetworkString::BareNetworkString ( int  capacity = 16)
inline

Constructor, sets the protocol type of this message.

◆ BareNetworkString() [2/2]

BareNetworkString::BareNetworkString ( const char *  data,
int  len 
)
inline

Initialises the string with a sequence of characters.

Member Function Documentation

◆ add() [1/2]

BareNetworkString& BareNetworkString::add ( const Vec3 xyz)
inline

Adds the xyz components of a Vec3 to the string.

◆ add() [2/2]

BareNetworkString& BareNetworkString::add ( const btQuaternion &  quat)
inline

Adds the four components of a quaternion.

◆ addChar()

BareNetworkString& BareNetworkString::addChar ( const char  value)
inline

Adds a single character to the string.

◆ addFloat()

BareNetworkString& BareNetworkString::addFloat ( const float  value)
inline

Adds a 4 byte floating point value.

◆ addInt24()

BareNetworkString& BareNetworkString::addInt24 ( const int  value)
inline

Adds signed 24 bit integer.

◆ 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).

◆ addUInt16()

BareNetworkString& BareNetworkString::addUInt16 ( const uint16_t  value)
inline

Adds 16 bit unsigned int.

◆ addUInt32()

BareNetworkString& BareNetworkString::addUInt32 ( const uint32_t &  value)
inline

Adds unsigned 32 bit integer.

◆ addUInt64()

BareNetworkString& BareNetworkString::addUInt64 ( const uint64_t &  value)
inline

Adds unsigned 64 bit integer.

◆ addUInt8()

BareNetworkString& BareNetworkString::addUInt8 ( const uint8_t  value)
inline

Add 8 bit unsigned int.

◆ 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.

◆ encodeString() [1/2]

BareNetworkString & BareNetworkString::encodeString ( 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.

◆ encodeString() [2/2]

BareNetworkString & BareNetworkString::encodeString ( 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.

◆ encodeString16()

BareNetworkString & BareNetworkString::encodeString16 ( const irr::core::stringw &  value,
uint16_t  max_len = 65535 
)

Encode string with max length of 16bit and utf32, used in motd or chat.

◆ get() [1/2]

template<typename T , size_t n>
T BareNetworkString::get ( ) const
inlineprotected

Template to get n bytes from a buffer into a single data type.

◆ get() [2/2]

template<typename T >
T BareNetworkString::get ( ) const
inlineprotected

Another function for n == 1 to surpress warnings in clang.

◆ getBuffer()

std::vector<uint8_t>& BareNetworkString::getBuffer ( )
inline

Returns the internal buffer of the network string.

◆ getCurrentData() [1/2]

char* BareNetworkString::getCurrentData ( )
inline

Returns a byte pointer to the unread remaining content of the network string.

◆ getCurrentData() [2/2]

const char* BareNetworkString::getCurrentData ( ) const
inline

Returns a byte pointer to the unread remaining content of the network string.

◆ getData() [1/2]

char* BareNetworkString::getData ( )
inline

Returns a byte pointer to the content of the network string.

◆ getData() [2/2]

const char* BareNetworkString::getData ( ) const
inline

Returns a byte pointer to the content of the network string.

◆ getFloat()

float BareNetworkString::getFloat ( ) const
inline

Gets a 4 byte floating point value.

◆ getInt16()

int16_t BareNetworkString::getInt16 ( ) const
inline

Returns an unsigned 16 bit integer.

◆ getInt24()

int BareNetworkString::getInt24 ( ) const
inline

Returns a signed 24 bit integer.

◆ getInt8()

int8_t BareNetworkString::getInt8 ( ) const
inline

Returns an unsigned 8-bit integer.

◆ 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-

◆ getQuat()

btQuaternion BareNetworkString::getQuat ( ) const
inline

Gets a bullet quaternion.

◆ 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.

◆ getTime()

uint32_t BareNetworkString::getTime ( ) const
inline

Returns a unsigned 32 bit integer.

◆ 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.

◆ getUInt16()

uint16_t BareNetworkString::getUInt16 ( ) const
inline

Returns an unsigned 16 bit integer.

◆ getUInt32()

uint32_t BareNetworkString::getUInt32 ( ) const
inline

Returns a unsigned 32 bit integer.

◆ getUInt64()

uint64_t BareNetworkString::getUInt64 ( ) const
inline

Returns a unsigned 64 bit integer.

◆ getUInt8()

uint8_t BareNetworkString::getUInt8 ( ) const
inline

Returns an unsigned 8-bit integer.

◆ getVec3()

Vec3 BareNetworkString::getVec3 ( ) const
inline

Gets a Vec3.

◆ 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).

◆ reset()

void BareNetworkString::reset ( )
inline

Allows one to read a buffer from the beginning again.

◆ size()

unsigned int BareNetworkString::size ( ) const
inline

Returns the remaining length of the network string.

◆ skip()

void BareNetworkString::skip ( int  n)
inline

Skips the specified number of bytes when reading.

Member Data Documentation

◆ m_buffer

std::vector<uint8_t> BareNetworkString::m_buffer
protected

The actual buffer.

◆ 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: