12 #ifndef SST_CORE_SERIALIZATION_SERIALIZER_H 13 #define SST_CORE_SERIALIZATION_SERIALIZER_H 15 #include "sst/core/serialization/serialize_packer.h" 16 #include "sst/core/serialization/serialize_sizer.h" 17 #include "sst/core/serialization/serialize_unpacker.h" 29 namespace Serialization {
38 typedef enum { SIZER, PACK, UNPACK } SERIALIZE_MODE;
65 unpacker_.unpack<T>(t);
71 mode()
const {
return mode_; }
73 void set_mode(SERIALIZE_MODE mode) { mode_ = mode; }
98 template <
class T,
int N>
104 sizer_.add(
sizeof(T) * N);
109 char* charstr = packer_.next_str(N *
sizeof(T));
110 ::memcpy(charstr, arr, N *
sizeof(T));
115 char* charstr = unpacker_.next_str(N *
sizeof(T));
116 ::memcpy(arr, charstr, N *
sizeof(T));
122 template <
typename T,
typename Int>
123 void binary(T*& buffer, Int& size)
128 sizer_.add(
sizeof(Int));
140 packer_.pack(nullsize);
146 unpacker_.unpack(size);
147 if ( size != 0 ) { unpacker_.
unpack_buffer(&buffer, size *
sizeof(T)); }
158 template <
typename Int>
159 void binary(
void*& buffer, Int& size)
161 char* tmp = (
char*)buffer;
162 binary<char>(tmp, size);
166 void string(std::string& str);
168 void start_packing(
char* buffer,
size_t size)
170 packer_.init(buffer, size);
172 ser_pointer_set.clear();
173 ser_pointer_map.clear();
180 ser_pointer_set.clear();
181 ser_pointer_map.clear();
184 void start_unpacking(
char* buffer,
size_t size)
186 unpacker_.init(buffer, size);
188 ser_pointer_set.clear();
189 ser_pointer_map.clear();
196 return sizer_.size();
198 return packer_.size();
200 return unpacker_.size();
205 inline bool check_pointer_pack(uintptr_t ptr)
207 if ( ser_pointer_set.count(ptr) == 0 ) {
208 ser_pointer_set.insert(ptr);
214 inline uintptr_t check_pointer_unpack(uintptr_t ptr)
216 auto it = ser_pointer_map.find(ptr);
217 if ( it != ser_pointer_map.end() ) {
return it->second; }
223 inline void report_new_pointer(uintptr_t real_ptr) { ser_pointer_map[split_key] = real_ptr; }
225 inline void report_real_pointer(uintptr_t ptr, uintptr_t real_ptr) { ser_pointer_map[ptr] = real_ptr; }
227 void enable_pointer_tracking(
bool value =
true) { enable_ptr_tracking_ = value; }
229 inline bool is_pointer_tracking_enabled() {
return enable_ptr_tracking_; }
237 SERIALIZE_MODE mode_;
238 bool enable_ptr_tracking_ =
false;
240 std::set<uintptr_t> ser_pointer_set;
241 std::map<uintptr_t, uintptr_t> ser_pointer_map;
249 #endif // SST_CORE_SERIALIZATION_SERIALIZER_H This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
void unpack_buffer(void *buf, int size)
unpack_buffer
Definition: serializer.cc:25
Definition: serialize_packer.h:24
void pack_buffer(void *buf, int size)
pack_buffer
Definition: serializer.cc:39
Definition: serialize_sizer.h:22
Definition: serialize_unpacker.h:22