NETSIM 1.2.0
Hardware-in-the-loop acoustic network simulator
 
Loading...
Searching...
No Matches
boost_serialization.h
Go to the documentation of this file.
1// Copyright 2016-2021:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_MARSHALLING_BOOST_SERIALIZATION_H
25#define GOBY_MIDDLEWARE_MARSHALLING_BOOST_SERIALIZATION_H
26
27#include <boost/archive/binary_iarchive.hpp>
28#include <boost/archive/binary_oarchive.hpp>
29#include <boost/iostreams/device/back_inserter.hpp>
30#include <boost/iostreams/stream.hpp>
31#include <boost/serialization/shared_ptr.hpp>
32#include <boost/serialization/string.hpp>
33#include <boost/serialization/vector.hpp>
34
35#include <vector>
36
37#include "goby/middleware/marshalling/interface.h"
38
39#include "netsim/core/common.h"
40
41namespace goby
42{
43namespace middleware
44{
45
46// update when moved into Goby
48
49template <typename T, class Enable = void> constexpr const char* boost_serialization_type_name()
50{
51 return T::goby_boost_serialization_type;
52}
53
54template <typename T> struct SerializerParserHelper<T, BOOST_SERIALIZATION_SCHEME>
55{
56 static std::vector<char> serialize(const T& msg)
57 {
58 std::vector<char> data;
59 boost::iostreams::back_insert_device<std::vector<char>> inserter(data);
60 boost::iostreams::stream<boost::iostreams::back_insert_device<std::vector<char>>> stream(
61 inserter);
62 boost::archive::binary_oarchive oa(stream);
63
64 oa << msg;
65 stream.flush();
66 return data;
67 }
68
69 static std::string type_name(const T& t = T()) { return boost_serialization_type_name<T>(); }
70
71 template <typename CharIterator>
73 CharIterator& actual_end, const std::string& type = type_name())
74 {
75 std::shared_ptr<T> t = std::make_shared<T>();
76
77 boost::iostreams::basic_array_source<char> device(&(*bytes_begin), &(*bytes_end));
78 boost::iostreams::stream<boost::iostreams::basic_array_source<char>> stream(device);
79 boost::archive::binary_iarchive ia(stream);
80
81 ia >> *t;
83
84 return t;
85 }
86};
87
88template <typename T,
89 typename std::enable_if<T::goby_boost_serialization_type != nullptr>::type* = nullptr>
90constexpr int scheme()
91{
93}
94
95} // namespace middleware
96} // namespace goby
97
98// Serialization for TaggedAudioBuffer
99
100namespace boost
101{
102namespace serialization
103{
104
105template <class Archive>
106void serialize(Archive& ar, netsim::AudioBuffer& b, const unsigned int version)
107{
108 ar& b.buffer_start_time;
109 ar& b.jack_frame_time;
110 ar& b.samples;
111}
112
113template <class Archive>
114void serialize(Archive& ar, netsim::TaggedAudioBuffer& t, const unsigned int version)
115{
116 ar& t.buffer;
117 ar& t.marker;
118 ar& t.packet_id;
119}
120
121} // namespace serialization
122} // namespace boost
123
124namespace goby
125{
126namespace middleware
127{
128
130{
131 return "TaggedAudioBuffer";
132}
133} // namespace middleware
134} // namespace goby
135
136#endif
void serialize(Archive &ar, netsim::AudioBuffer &b, const unsigned int version)
constexpr int BOOST_SERIALIZATION_SCHEME
constexpr const char * boost_serialization_type_name()
constexpr int scheme()
constexpr const char * boost_serialization_type_name< netsim::TaggedAudioBuffer >()
static std::shared_ptr< T > parse(CharIterator bytes_begin, CharIterator bytes_end, CharIterator &actual_end, const std::string &type=type_name())
double buffer_start_time
Definition common.h:49
jack_nframes_t jack_frame_time
Definition common.h:50
std::vector< netsim::sample_t > samples
Definition common.h:52
std::shared_ptr< const AudioBuffer > buffer
Definition common.h:57