1 #ifndef __SERIALIZATION_H_INCLUDED 2 #define __SERIALIZATION_H_INCLUDED 9 #ifdef COMPRESSED_SERIALIZATION 17 if (reserved_size > 0)
data.reserve(reserved_size);
28 template<
typename Type>
30 size_t ptr =
data.size();
31 data.resize(
data.size() +
sizeof(Type));
32 *
reinterpret_cast<Type*
>(
data.data() + ptr) = value;
35 void append(
const std::vector<char>& new_data) {
36 data.reserve(
data.size() + new_data.size());
37 data.insert(
data.end(), new_data.begin(), new_data.end());
40 #ifdef COMPRESSED_SERIALIZATION 41 std::vector<char> compressed()
const {
42 std::vector<char> res;
43 char* output =
new char[
data.size()];
44 unsigned int output_size =
data.size();
46 res.assign(output, output + output_size);
57 template<
typename Type>
64 inline Serializer& operator<<(Serializer& s, const std::vector<char>&
data) {
71 Deserializer(
const std::vector<char>&
data,
size_t start_pos = 0) : ptr(start_pos), data(data) {}
77 template<
typename Type>
79 Type value = *
reinterpret_cast<const Type*
>(
data.data() + ptr);
84 #ifdef COMPRESSED_SERIALIZATION 85 static std::vector<char>
decompress(
const char*
data,
size_t data_size,
size_t expected_size) {
86 std::vector<char> res;
87 char *output =
new char[expected_size];
88 unsigned int output_size = expected_size;
90 res.reserve(output_size);
91 res.assign(output, output + output_size);
103 template<
typename Type>
Serializer & operator<<(Serializer &s, Type value)
void reserve(size_t size)
Serializer(size_t reserved_size=0)
Deserializer & operator>>(Deserializer &d, Type &value)
void append(const std::vector< char > &new_data)
const std::vector< char > & data
int roslz4_buffToBuffCompress(char *input, unsigned int input_size, char *output, unsigned int *output_size, int block_size_id)
Deserializer(const std::vector< char > &data, size_t start_pos=0)
void add_value(Type value)
std::vector< char > result() const
Serializer(const std::vector< char > &data)
int roslz4_buffToBuffDecompress(char *input, unsigned int input_size, char *output, unsigned int *output_size)