SST  15.1.0
StructuralSimulationToolkit
objectSerialization.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_OBJECTSERIALIZATION_H
13 #define SST_CORE_OBJECTSERIALIZATION_H
14 
15 #include "sst/core/serialization/serializer.h"
16 
17 #include <vector>
18 
19 namespace SST::Comms {
20 
21 template <typename dataType>
22 std::vector<char>
23 serialize(dataType& data)
24 {
26 
27  ser.start_sizing();
28  SST_SER(data);
29 
30  size_t size = ser.size();
31 
32  std::vector<char> buffer;
33  buffer.resize(size);
34 
35  ser.start_packing(buffer.data(), size);
36  SST_SER(data);
37 
38  return buffer;
39 }
40 
41 
42 template <typename dataType>
43 dataType*
44 deserialize(std::vector<char>& buffer)
45 {
46  dataType* tgt = nullptr;
47 
49 
50  ser.start_unpacking(buffer.data(), buffer.size());
51  SST_SER(tgt);
52 
53  return tgt;
54 }
55 
56 template <typename dataType>
57 void
58 deserialize(std::vector<char>& buffer, dataType& tgt)
59 {
61 
62  ser.start_unpacking(buffer.data(), buffer.size());
63  SST_SER(tgt);
64 }
65 
66 template <typename dataType>
67 void
68 deserialize(char* buffer, int blen, dataType& tgt)
69 {
71 
72  ser.start_unpacking(buffer, blen);
73  SST_SER(tgt);
74 }
75 
76 } // namespace SST::Comms
77 
78 #endif // SST_CORE_OBJECTSERIALIZATION_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Definition: objectComms.h:21