SST  12.0.1
StructuralSimulationToolkit
objectSerialization.h
1 // Copyright 2009-2022 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-2022, 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 {
20 
21 namespace Comms {
22 
23 template <typename dataType>
24 std::vector<char>
25 serialize(dataType& data)
26 {
28 
29  ser.start_sizing();
30  ser& data;
31 
32  size_t size = ser.size();
33 
34  std::vector<char> buffer;
35  buffer.resize(size);
36 
37  ser.start_packing(buffer.data(), size);
38  ser& data;
39 
40  return buffer;
41 }
42 
43 
44 template <typename dataType>
45 dataType*
46 deserialize(std::vector<char>& buffer)
47 {
48  dataType* tgt = nullptr;
49 
51 
52  ser.start_unpacking(buffer.data(), buffer.size());
53  ser& tgt;
54 
55  return tgt;
56 }
57 
58 template <typename dataType>
59 void
60 deserialize(std::vector<char>& buffer, dataType& tgt)
61 {
63 
64  ser.start_unpacking(buffer.data(), buffer.size());
65  ser& tgt;
66 }
67 
68 template <typename dataType>
69 void
70 deserialize(char* buffer, int blen, dataType& tgt)
71 {
73 
74  ser.start_unpacking(buffer, blen);
75  ser& tgt;
76 }
77 
78 } // namespace Comms
79 
80 } // namespace SST
81 
82 #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:34