DataDeserializer is an utility class that walks through and deserializes data in a stream of raw bytes. More...
#include <DataDeserializer.h>
Public Member Functions | |
| DataDeserializer (const char *data, size_t size) | |
| Constructs a DataDeserializer that reads its data from the given buffer. | |
| DataDeserializer (const char *data, size_t size, const SerializedMessageDesc *msgTemplate) | |
| Constructs a DataDeserializer that reads its data from the given buffer. | |
| void | ResetTraversal () |
| Moves the bit offset position counter to the beginning of the data buffer. | |
| template<typename T > | |
| T | Read () |
| Deserializes a single value of type T off the stream and advances the internal read offset. | |
| template<typename VLEType > | |
| u32 | ReadVLE () |
| Reads a variable-length encoded integer off the stream and advances the internal read offset. | |
| template<typename T > | |
| void | ReadArray (T *dst, size_t numElems) |
| Deserializes an array of values of type T off the stream and advances the internal read offset. | |
| std::string | ReadString () |
| Reads an ASCII string from the stream. | |
| u32 | ReadBits (int numBits) |
| Reads the given amount of bits and packs them into a u32, which is returned. | |
| u32 | GetDynamicElemCount () |
| Need to have a message template to use this function. | |
| u32 | BytesLeft () const |
| u32 | BitsLeft () const |
| u32 | BytePos () const |
| u32 | BitPos () const |
| size_t | BitsReadTotal () const |
| const char * | CurrentData () const |
| void | SkipBits (size_t numBits) |
| Advances the read pointer with the given amount of bits. Can only be used in nontemplate read mode. | |
| void | SkipBytes (size_t numBytes) |
| Advances the read pointer with the given amount of bytes. Can only be used in nontemplate read mode. | |
DataDeserializer is an utility class that walks through and deserializes data in a stream of raw bytes.
The stream itself does not contain information about what types of data is contained within, but the user of DataDeserializer must know the contents of the data. DataDeserializer never copies the data it is given to read into an internal memory buffer, but instead it reads the given existing memory buffers. DataDeserializer maintains an internal bit offset position to keep track the position that is currently being read.
| kNet::DataDeserializer::DataDeserializer | ( | const char * | data, | |
| size_t | size | |||
| ) |
Constructs a DataDeserializer that reads its data from the given buffer.
DataDeserializer will not copy the contents of the buffer to its own memory area, so be sure to keep the data alive and unmoved for the duration DataDeserializer exists.
References ResetTraversal().
| kNet::DataDeserializer::DataDeserializer | ( | const char * | data, | |
| size_t | size, | |||
| const SerializedMessageDesc * | msgTemplate | |||
| ) |
Constructs a DataDeserializer that reads its data from the given buffer.
DataDeserializer will not copy the contents of the buffer to its own memory area, so be sure to keep the data alive and unmoved for the duration DataDeserializer exists.
| msgTemplate | A pointer to an existing message template structure, which is used to validate that deserialization of the data proceeds in the defined order. DataDeserializer does not make a copy of this description, but dereferences it directly. Be sure to keep it alive for the duration that DataDeserializer exists. Do not pass in a zero pointer here. |
References ResetTraversal().
| void kNet::DataDeserializer::ReadArray | ( | T * | dst, | |
| size_t | numElems | |||
| ) |
Deserializes an array of values of type T off the stream and advances the internal read offset.
| dst | [out] Pointer to an array to receive the read data. | |
| numElems | The number of elements to read. The array dst must be able to hold that many elements. |
| std::string kNet::DataDeserializer::ReadString | ( | ) |
Reads an ASCII string from the stream.
If we are using a template, the template tells how the string is stored. Otherwise, we are assuming the string was stored length-prepended, using a single byte to denote the length (no null padding). Use the 's8' data type with dynamicCount set in the message template description for a string variable. The returned string will only contain ascii values in the range [32, 253], 0x0D, 0x0A, 0x09. Other values will be replaced with a space bar character (0x20). Because of this string validation method, do not use this function to extract binary data of any kind (base64-encoded is fine).
References BitsLeft(), and GetDynamicElemCount().
| u32 kNet::DataDeserializer::ReadBits | ( | int | numBits | ) |
Reads the given amount of bits and packs them into a u32, which is returned.
| numBits | the number of bits to read, [1, 32]. |
Referenced by ReadVLE().
| u32 kNet::DataDeserializer::BytesLeft | ( | ) | const [inline] |
Referenced by kNet::MessageConnection::HandleInboundMessage().
| u32 kNet::DataDeserializer::BitsLeft | ( | ) | const [inline] |
Referenced by GetDynamicElemCount(), ReadString(), and ReadVLE().
| u32 kNet::DataDeserializer::BytePos | ( | ) | const [inline] |
Referenced by kNet::MessageConnection::HandleInboundMessage().
| u32 kNet::DataDeserializer::BitPos | ( | ) | const [inline] |
Referenced by kNet::MessageConnection::HandleInboundMessage().
| size_t kNet::DataDeserializer::BitsReadTotal | ( | ) | const [inline] |
| const char* kNet::DataDeserializer::CurrentData | ( | ) | const [inline] |
1.7.1