SuperTuxKart
|
Describes a chain of 8-bit unsigned integers. More...
#include <network_string.hpp>
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... | |
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. More... | |
int | decodeString16 (irr::core::stringw *out, uint16_t max_len=65535) |
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. More... | |
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. 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... | |
BareNetworkString & | addUInt8 (const uint8_t value) |
Add 8 bit unsigned int. More... | |
BareNetworkString & | addChar (const char value) |
Adds a single character to the string. More... | |
BareNetworkString & | addUInt16 (const uint16_t value) |
Adds 16 bit unsigned int. More... | |
BareNetworkString & | addInt24 (const int value) |
Adds signed 24 bit integer. More... | |
BareNetworkString & | addUInt32 (const uint32_t &value) |
Adds unsigned 32 bit integer. More... | |
BareNetworkString & | addUInt64 (const uint64_t &value) |
Adds unsigned 64 bit integer. More... | |
BareNetworkString & | addFloat (const float value) |
Adds a 4 byte floating point value. More... | |
BareNetworkString & | operator+= (BareNetworkString const &value) |
Adds the content of another network string. More... | |
BareNetworkString & | add (float f) |
Adds a floating point number. | |
BareNetworkString & | add (const Vec3 &xyz) |
Adds the xyz components of a Vec3 to the string. More... | |
BareNetworkString & | add (const btQuaternion &quat) |
Adds the four components of a quaternion. More... | |
BareNetworkString & | addTime (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... | |
BareNetworkString & | addString (const std::string &value) |
Adds a std::string. More... | |
template<typename T , size_t n> | |
T | get () const |
Template to get n bytes from a buffer into a single data type. More... | |
template<typename T > | |
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 |
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)
|
inline |
Constructor, sets the protocol type of this message.
|
inline |
Initialises the string with a sequence of characters.
|
inline |
Adds the xyz components of a Vec3 to the string.
|
inline |
Adds the four components of a quaternion.
|
inline |
Adds a single character to the string.
|
inline |
Adds a 4 byte floating point value.
|
inline |
Adds signed 24 bit integer.
|
inlineprotected |
Adds a std::string.
Internal use only.
|
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).
|
inline |
Adds 16 bit unsigned int.
|
inline |
Adds unsigned 32 bit integer.
|
inline |
Adds unsigned 64 bit integer.
|
inline |
Add 8 bit unsigned int.
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).
[in] | pos | Buffer position where the encoded string starts. |
[out] | out | The decoded string. |
int BareNetworkString::decodeStringW | ( | irr::core::stringw * | out | ) | const |
Returns an irrlicht wide string from the utf8 encoded string at the given position.
[out] | out | The decoded string. |
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.
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.
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.
|
inlineprotected |
Template to get n bytes from a buffer into a single data type.
|
inlineprotected |
Another function for n == 1 to surpress warnings in clang.
|
inline |
Returns the internal buffer of the network string.
|
inline |
Returns a byte pointer to the unread remaining content of the network string.
|
inline |
Returns a byte pointer to the unread remaining content of the network string.
|
inline |
Returns a byte pointer to the content of the network string.
|
inline |
Returns a byte pointer to the content of the network string.
|
inline |
Gets a 4 byte floating point value.
|
inline |
Returns an unsigned 16 bit integer.
|
inline |
Returns a signed 24 bit integer.
|
inline |
Returns an unsigned 8-bit integer.
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-
|
inline |
Gets a bullet quaternion.
|
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.
pos | First position to be in the string. |
len | Number of bytes to copy. |
|
inline |
Returns a unsigned 32 bit integer.
|
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.
|
inline |
Returns an unsigned 16 bit integer.
|
inline |
Returns a unsigned 32 bit integer.
|
inline |
Returns a unsigned 64 bit integer.
|
inline |
Returns an unsigned 8-bit integer.
|
inline |
Adds the content of another network string.
It only copies data which has not been 'removed' (i.e. skipped).
|
inline |
Allows one to read a buffer from the beginning again.
|
inline |
Returns the remaining length of the network string.
|
inline |
Skips the specified number of bytes when reading.
|
protected |
The actual buffer.
|
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).