SST 16.0.0
Structural Simulation Toolkit
objectSerialization.h
1// Copyright 2009-2026 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-2026, 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(size);
33
34 ser.start_packing(buffer.data(), size);
35 SST_SER(data);
36
37 return buffer;
38}
39
40
41template <typename dataType>
42dataType*
43deserialize(std::vector<char>& buffer)
44{
45 dataType* tgt = nullptr;
46
47 SST::Core::Serialization::serializer ser;
48
49 ser.start_unpacking(buffer.data(), buffer.size());
50 SST_SER(tgt);
51
52 return tgt;
53}
54
55template <typename dataType>
56void
57deserialize(std::vector<char>& buffer, dataType& tgt)
58{
59 SST::Core::Serialization::serializer ser;
60
61 ser.start_unpacking(buffer.data(), buffer.size());
62 SST_SER(tgt);
63}
64
65template <typename dataType>
66void
67deserialize(char* buffer, int blen, dataType& tgt)
68{
69 SST::Core::Serialization::serializer ser;
70
71 ser.start_unpacking(buffer, blen);
72 SST_SER(tgt);
73}
74
75} // namespace SST::Comms
76
77#endif // SST_CORE_OBJECTSERIALIZATION_H