Overte C++ Documentation
DataDeserializer Class Reference

Data deserializer. More...

#include <SerDes.h>

Classes

class  SizeTracker
 RAII tracker of advance position. More...
 

Public Member Functions

 DataDeserializer (const char *externalStore, size_t storeLength)
 Construct a Deserializer *. More...
 
 DataDeserializer (const uint8_t *externalStore, size_t storeLength)
 Construct a Deserializer. More...
 
 DataDeserializer (const DataSerializer &serializer)
 Construct a new Deserializer reading data from a Serializer. More...
 
void skipPadding (size_t bytes)
 Skips padding in the input. More...
 
DataDeserializeroperator>> (uint8_t &c)
 Read an uint8_t from the buffer. More...
 
DataDeserializeroperator>> (int8_t &c)
 Read an int8_t from the buffer. More...
 
DataDeserializeroperator>> (uint16_t &val)
 Read an uint16_t from the buffer. More...
 
DataDeserializeroperator>> (int16_t &val)
 Read an int16_t from the buffer. More...
 
DataDeserializeroperator>> (uint32_t &val)
 Read an uint32_t from the buffer. More...
 
DataDeserializeroperator>> (int32_t &val)
 Read an int32_t from the buffer. More...
 
DataDeserializeroperator>> (uint64_t &val)
 Read an uint64_t from the buffer. More...
 
DataDeserializeroperator>> (int64_t &val)
 Read an int64_t from the buffer. More...
 
DataDeserializeroperator>> (float &val)
 Read an float from the buffer. More...
 
DataDeserializeroperator>> (glm::vec3 &val)
 Read a glm::vec3 from the buffer. More...
 
DataDeserializeroperator>> (glm::vec4 &val)
 Read a glm::vec4 from the buffer. More...
 
DataDeserializeroperator>> (glm::ivec2 &val)
 Read a glm::ivec2 from the buffer. More...
 
const char * buffer () const
 Pointer to the start of the internal buffer. More...
 
size_t pos () const
 Current position in the buffer. Starts at 0. More...
 
size_t length () const
 Last position that was written to in the buffer. Starts at 0. More...
 
bool isEmpty () const
 Whether there's any data in the buffer. More...
 
bool isOverflow () const
 The buffer size limit has been reached. More...
 
void rewind ()
 Reset the serializer to the start, clear overflow bit.
 
size_t lastAdvance () const
 Size of the last advance. More...
 

Friends

QDebug operator<< (QDebug debug, const DataDeserializer &ds)
 Dump the contents of this object into QDebug. More...
 

Detailed Description

Data deserializer.

This class operates on a fixed size buffer. If an attempt to read past the end is made, the read fails, and the overflow flag is set.

The class was written for the maximum simplicity possible and inline friendliness.

Example of decoding:

// Incoming data has been placed in:
// char buffer[1024];
uint8_t version;
uint16_t count;
glm::vec3 pos;
des >> version;
des >> count;
des >> pos;
Data deserializer.
Definition: SerDes.h:573
const char * buffer() const
Pointer to the start of the internal buffer.
Definition: SerDes.h:873
size_t pos() const
Current position in the buffer. Starts at 0.
Definition: SerDes.h:880

This object should be modified directly to add support for any primitive and common datatypes in the code. To support deserializing classes and structures, implement an operator>> function for that object, eg:

des >> o._borderColor;
des >> o._maxAnisotropy;
des >> o._filter;
return des;
}
DataDeserializer & operator>>(uint8_t &c)
Read an uint8_t from the buffer.
Definition: SerDes.h:670

Constructor & Destructor Documentation

◆ DataDeserializer() [1/3]

DataDeserializer::DataDeserializer ( const char *  externalStore,
size_t  storeLength 
)
inline

Construct a Deserializer *.

Parameters
externalStoreExternal data store
storeLengthLength of the data store

◆ DataDeserializer() [2/3]

DataDeserializer::DataDeserializer ( const uint8_t *  externalStore,
size_t  storeLength 
)
inline

Construct a Deserializer.

Parameters
externalStoreExternal data store
storeLengthLength of the data store

◆ DataDeserializer() [3/3]

DataDeserializer::DataDeserializer ( const DataSerializer serializer)
inline

Construct a new Deserializer reading data from a Serializer.

This is a convenience function for testing.

Parameters
serializerSerializer with data

Member Function Documentation

◆ buffer()

const char* DataDeserializer::buffer ( ) const
inline

Pointer to the start of the internal buffer.

The allocated amount can be found with capacity().

The end of the stored data can be found with length().

Returns
Pointer to buffer

◆ isEmpty()

bool DataDeserializer::isEmpty ( ) const
inline

Whether there's any data in the buffer.

Returns
true Something has been written
false The buffer is empty

◆ isOverflow()

bool DataDeserializer::isOverflow ( ) const
inline

The buffer size limit has been reached.

This can only return true for a statically allocated buffer.

Returns
true Limit reached
false There is still room

◆ lastAdvance()

size_t DataDeserializer::lastAdvance ( ) const
inline

Size of the last advance.

This can be used to get how many bytes were added in the last operation. It is reset on rewind()

Returns
size_t

◆ length()

size_t DataDeserializer::length ( ) const
inline

Last position that was written to in the buffer. Starts at 0.

Returns
size_t

◆ operator>>() [1/12]

DataDeserializer& DataDeserializer::operator>> ( float &  val)
inline

Read an float from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [2/12]

DataDeserializer& DataDeserializer::operator>> ( glm::ivec2 &  val)
inline

Read a glm::ivec2 from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [3/12]

DataDeserializer& DataDeserializer::operator>> ( glm::vec3 &  val)
inline

Read a glm::vec3 from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [4/12]

DataDeserializer& DataDeserializer::operator>> ( glm::vec4 &  val)
inline

Read a glm::vec4 from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [5/12]

DataDeserializer& DataDeserializer::operator>> ( int16_t &  val)
inline

Read an int16_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [6/12]

DataDeserializer& DataDeserializer::operator>> ( int32_t &  val)
inline

Read an int32_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [7/12]

DataDeserializer& DataDeserializer::operator>> ( int64_t &  val)
inline

Read an int64_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [8/12]

DataDeserializer& DataDeserializer::operator>> ( int8_t &  c)
inline

Read an int8_t from the buffer.

Parameters
cCharacter to read
Returns
SerDes& This object

◆ operator>>() [9/12]

DataDeserializer& DataDeserializer::operator>> ( uint16_t &  val)
inline

Read an uint16_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [10/12]

DataDeserializer& DataDeserializer::operator>> ( uint32_t &  val)
inline

Read an uint32_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [11/12]

DataDeserializer& DataDeserializer::operator>> ( uint64_t &  val)
inline

Read an uint64_t from the buffer.

Parameters
valValue to read
Returns
SerDes& This object

◆ operator>>() [12/12]

DataDeserializer& DataDeserializer::operator>> ( uint8_t &  c)
inline

Read an uint8_t from the buffer.

Parameters
cCharacter to read
Returns
SerDes& This object

◆ pos()

size_t DataDeserializer::pos ( ) const
inline

Current position in the buffer. Starts at 0.

Returns
size_t

◆ skipPadding()

void DataDeserializer::skipPadding ( size_t  bytes)
inline

Skips padding in the input.

Parameters
bytesNumber of bytes to skip

Friends And Related Function Documentation

◆ operator<<

QDebug operator<< ( QDebug  debug,
const DataDeserializer ds 
)
friend

Dump the contents of this object into QDebug.

This produces a dump of the internal state, and an ASCII/hex dump of the contents, for debugging.

Parameters
debugQt QDebug stream
dsThis object
Returns
QDebug

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