SST 15.0
Structural Simulation Toolkit
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
19namespace SST::Comms {
20
21template <typename dataType>
22std::vector<char>
23serialize(dataType& data)
24{
25 SST::Core::Serialization::serializer ser;
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
42template <typename dataType>
43dataType*
44deserialize(std::vector<char>& buffer)
45{
46 dataType* tgt = nullptr;
47
48 SST::Core::Serialization::serializer ser;
49
50 ser.start_unpacking(buffer.data(), buffer.size());
51 SST_SER(tgt);
52
53 return tgt;
54}
55
56template <typename dataType>
57void
58deserialize(std::vector<char>& buffer, dataType& tgt)
59{
60 SST::Core::Serialization::serializer ser;
61
62 ser.start_unpacking(buffer.data(), buffer.size());
63 SST_SER(tgt);
64}
65
66template <typename dataType>
67void
68deserialize(char* buffer, int blen, dataType& tgt)
69{
70 SST::Core::Serialization::serializer ser;
71
72 ser.start_unpacking(buffer, blen);
73 SST_SER(tgt);
74}
75
76} // namespace SST::Comms
77
78#endif // SST_CORE_OBJECTSERIALIZATION_H