12 #ifndef SST_CORE_SERIALIZATION_SERIALIZER_H 13 #define SST_CORE_SERIALIZATION_SERIALIZER_H 18 #define SST_INCLUDING_SERIALIZER_H 19 #include "sst/core/serialization/impl/mapper.h" 20 #include "sst/core/serialization/impl/packer.h" 21 #include "sst/core/serialization/impl/sizer.h" 22 #include "sst/core/serialization/impl/unpacker.h" 25 #undef SST_INCLUDING_SERIALIZER_H 37 namespace Serialization {
46 enum SERIALIZE_MODE { SIZER, PACK, UNPACK, MAP };
75 unpacker_.unpack<T>(t);
81 mode()
const {
return mode_; }
83 void set_mode(SERIALIZE_MODE mode) { mode_ = mode; }
110 template <
class T,
int N>
116 sizer_.add(
sizeof(T) * N);
121 char* charstr = packer_.next_str(N *
sizeof(T));
122 ::memcpy(charstr, arr, N *
sizeof(T));
127 char* charstr = unpacker_.next_str(N *
sizeof(T));
128 ::memcpy(arr, charstr, N *
sizeof(T));
136 template <
typename T,
typename Int>
137 void binary(T*& buffer, Int& size)
142 sizer_.add(
sizeof(Int));
154 packer_.pack(nullsize);
160 unpacker_.unpack(size);
161 if ( size != 0 ) { unpacker_.
unpack_buffer(&buffer, size *
sizeof(T)); }
174 template <
typename Int>
175 void binary(
void*& buffer, Int& size)
177 char* tmp = (
char*)buffer;
178 binary<char>(tmp, size);
182 void string(std::string& str);
184 void start_packing(
char* buffer,
size_t size)
186 packer_.init(buffer, size);
188 ser_pointer_set.clear();
189 ser_pointer_map.clear();
196 ser_pointer_set.clear();
197 ser_pointer_map.clear();
200 void start_unpacking(
char* buffer,
size_t size)
202 unpacker_.init(buffer, size);
204 ser_pointer_set.clear();
205 ser_pointer_map.clear();
218 return sizer_.size();
220 return packer_.size();
222 return unpacker_.size();
229 inline bool check_pointer_pack(uintptr_t ptr)
231 if ( ser_pointer_set.count(ptr) == 0 ) {
232 ser_pointer_set.insert(ptr);
238 inline uintptr_t check_pointer_unpack(uintptr_t ptr)
240 auto it = ser_pointer_map.find(ptr);
241 if ( it != ser_pointer_map.end() ) {
return it->second; }
247 ObjectMap* check_pointer_map(uintptr_t ptr)
249 auto it = ser_pointer_map.find(ptr);
250 if ( it != ser_pointer_map.end() ) {
return reinterpret_cast<ObjectMap*
>(it->second); }
254 inline void report_new_pointer(uintptr_t real_ptr) { ser_pointer_map[split_key] = real_ptr; }
256 inline void report_real_pointer(uintptr_t ptr, uintptr_t real_ptr) { ser_pointer_map[ptr] = real_ptr; }
258 void enable_pointer_tracking(
bool value =
true) { enable_ptr_tracking_ = value; }
260 inline bool is_pointer_tracking_enabled() {
return enable_ptr_tracking_; }
262 inline void report_object_map(
ObjectMap* ptr)
264 ser_pointer_map[
reinterpret_cast<uintptr_t
>(ptr->
getAddr())] = reinterpret_cast<uintptr_t>(ptr);
274 SERIALIZE_MODE mode_;
275 bool enable_ptr_tracking_ =
false;
277 std::set<uintptr_t> ser_pointer_set;
279 std::map<uintptr_t, uintptr_t> ser_pointer_map;
287 #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:43
void unpack_buffer(void *buf, int size)
unpack_buffer
Definition: serializer.cc:25
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
virtual void * getAddr()=0
Get the address of the variable represented by the ObjectMap.
void pack_buffer(void *buf, int size)
pack_buffer
Definition: serializer.cc:39
Definition: unpacker.h:27