17 #ifndef SERIALIZE_HELPERS_H
18 #define SERIALIZE_HELPERS_H
46 return cursor - buffer;
58 const unsigned char *buffer;
59 const unsigned char *cursor;
65 for (
int i = 0; i < (int)(
sizeof(T)/2); i++) {
66 std::swap(buffer[i], buffer[
sizeof(T)-1-i]);
76 SwapEndianness<T>(buffer);
85 SwapEndianness<decimal>(buffer);
97 DeserializePadding<T>(des);
104 template <
typename T>
106 DeserializePadding<T>(des);
113 template <
typename T>
115 for (
int i = ser->
buffer.size(); i%
sizeof(T) != 0; i++) {
120 template <
typename T>
122 unsigned char buf[
sizeof(T)];
123 memcpy(&buf, &val,
sizeof(T));
124 SwapEndiannessIfNecessary<T>(buf, ser);
125 SerializePadding<T>(ser);
126 std::copy(buf, buf+
sizeof(T), std::back_inserter(ser->
buffer));
DeserializeContext(const unsigned char *buffer)
const unsigned char * GetCursor()
void MoveForward(size_t howMuch)
bool swapDecimalEndianness
std::vector< unsigned char > buffer
bool swapIntegerEndianness
SerializeContext(bool swapIntegerEndianness, bool swapDecimalEndianness)
void SerializePadding(SerializeContext *ser)
void SwapEndiannessIfNecessary< decimal >(unsigned char *buffer, SerializeContext *ser)
T DeserializePrimitive(DeserializeContext *des)
void SwapEndiannessIfNecessary(unsigned char *buffer, SerializeContext *ser)
Swap the endianness of a value if necessary.
void SerializePrimitive(SerializeContext *ser, const T &val)
void SwapEndianness(unsigned char *buffer)
Unconditionally swap the endianness of a value (uses sizeof T).
void DeserializePadding(DeserializeContext *des)
Move the cursor forward past any padding that would appear before a value of type T.
const T * DeserializeArray(DeserializeContext *des, long arrLength)
return an array of items as a pointer. Will point into the buffer (mmap style).