SST  15.1.0
StructuralSimulationToolkit
unpacker.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_SERIALIZATION_IMPL_UNPACKER_H
13 #define SST_CORE_SERIALIZATION_IMPL_UNPACKER_H
14 
15 #ifndef SST_INCLUDING_SERIALIZER_H
16 #warning \
17  "The header file sst/core/serialization/impl/unpacker.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serializer.h"
18 #endif
19 
20 #include "sst/core/serialization/impl/ser_buffer_accessor.h"
21 #include "sst/core/serialization/impl/ser_shared_ptr_tracker.h"
22 
23 #include <cstdint>
24 #include <cstring>
25 #include <map>
26 #include <string>
27 #include <type_traits>
28 
30 
32 {
33  std::map<uintptr_t, uintptr_t> ser_pointer_map;
34  uintptr_t split_key = 0;
35 
36 public:
37  // inherit ser_buffer_accessor constructors
38  using ser_buffer_accessor::ser_buffer_accessor;
39 
40  template <typename T>
41  void unpack(T& t)
42  {
43  memcpy(&t, buf_next(sizeof(t)), sizeof(t));
44  }
45 
46  template <typename T, typename SIZE_T>
47  void unpack_buffer(T*& buffer, SIZE_T& size)
48  {
49  size = 0;
50  unpack(size);
51  if ( size != 0 ) {
52  using ELEM_T = std::conditional_t<std::is_void_v<T>, char, T>; // Use char if T == void
53  buffer = new ELEM_T[size];
54  memcpy(buffer, buf_next(size * sizeof(ELEM_T)), size * sizeof(ELEM_T));
55  }
56  else
57  buffer = nullptr;
58  }
59 
60  uintptr_t check_pointer_unpack(uintptr_t ptr);
61  void unpack_string(std::string& str);
62  void report_new_pointer(uintptr_t real_ptr) { ser_pointer_map[split_key] = real_ptr; }
63  void report_real_pointer(uintptr_t ptr, uintptr_t real_ptr) { ser_pointer_map[ptr] = real_ptr; }
64 }; // class ser_unpacker
65 
66 } // namespace SST::Core::Serialization::pvt
67 
68 #endif // SST_CORE_SERIALIZATION_IMPL_UNPACKER_H
Definition: ser_buffer_accessor.h:25
Definition: baseComponent.cc:1107
Definition: ser_shared_ptr_tracker.h:60