1 #ifndef INCLUDE_AL_SERIALIZE_HPP
2 #define INCLUDE_AL_SERIALIZE_HPP
47 #include "al_Serialize.h"
54 inline uint32_t encode(
char* b,
const T* v, uint32_t n) {
59 inline uint32_t encode(
char* b,
const float* v, uint32_t n) {
60 return serEncodeFloat32(b, v, n);
63 inline uint32_t encode(
char* b,
const double* v, uint32_t n) {
64 return serEncodeFloat64(b, v, n);
67 inline uint32_t encode(
char* b,
const char* v, uint32_t n) {
68 return serEncodeInt8(b, (
const int8_t*)v, n);
71 inline uint32_t encode(
char* b,
const int8_t* v, uint32_t n) {
72 return serEncodeInt8(b, v, n);
75 inline uint32_t encode(
char* b,
const int16_t* v, uint32_t n) {
76 return serEncodeInt16(b, v, n);
79 inline uint32_t encode(
char* b,
const int32_t* v, uint32_t n) {
80 return serEncodeInt32(b, v, n);
83 inline uint32_t encode(
char* b,
const int64_t* v, uint32_t n) {
84 return serEncodeInt64(b, v, n);
87 inline uint32_t encode(
char* b,
const bool* v, uint32_t n) {
88 return serEncodeUInt8(b, (
const uint8_t*)v, n);
91 inline uint32_t encode(
char* b,
const uint8_t* v, uint32_t n) {
92 return serEncodeUInt8(b, v, n);
95 inline uint32_t encode(
char* b,
const uint16_t* v, uint32_t n) {
96 return serEncodeUInt16(b, v, n);
99 inline uint32_t encode(
char* b,
const uint32_t* v, uint32_t n) {
100 return serEncodeUInt32(b, v, n);
103 inline uint32_t encode(
char* b,
const uint64_t* v, uint32_t n) {
104 return serEncodeUInt64(b, v, n);
110 inline uint8_t getType<float>() {
114 inline uint8_t getType<double>() {
118 inline uint8_t getType<bool>() {
122 inline uint8_t getType<uint8_t>() {
126 inline uint8_t getType<uint16_t>() {
130 inline uint8_t getType<uint32_t>() {
134 inline uint8_t getType<uint64_t>() {
138 inline uint8_t getType<int8_t>() {
142 inline uint8_t getType<int16_t>() {
146 inline uint8_t getType<int32_t>() {
150 inline uint8_t getType<int64_t>() {
170 const std::vector<char>& buf()
const;
173 std::vector<char> mBuf, mTemp;
176 void checkSize(uint32_t n = 1);
193 const std::vector<char>& buf()
const;
197 std::vector<char> mBuf;
211 Serializer& Serializer::add(
const T* v, uint32_t num) {
213 uint32_t n = ser::encode(&mTemp[0], v, num);
214 mBuf.insert(mBuf.end(), mTemp.begin(), mTemp.begin() + n);
219 void Serializer::checkSize(uint32_t n) {
220 uint32_t need = n *
sizeof(T) + serHeaderSize();
221 if (mTemp.size() < need) mTemp.resize(need);
225 Deserializer& Deserializer::operator>>(T& v) {
226 uint32_t n = serDecode(bufDec(), &v);