Ignition Gazebo

API Reference

2.10.0
Serialization.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_GAZEBO_COMPONENTS_SERIALIZATION_HH_
18 #define IGNITION_GAZEBO_COMPONENTS_SERIALIZATION_HH_
19 
20 #include <ignition/msgs/double_v.pb.h>
21 
22 #include <vector>
23 #include <sdf/Sensor.hh>
24 
26 
27 // This header holds serialization operators which are shared among several
28 // components
29 
30 namespace ignition
31 {
32 namespace gazebo
33 {
34 // Inline bracket to help doxygen filtering.
35 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
54 
55 namespace serializers
56 {
69  template <typename DataType, typename MsgType>
71  {
76  public: static std::ostream &Serialize(std::ostream &_out,
77  const DataType &_data)
78  {
79  auto msg = ignition::gazebo::convert<MsgType>(_data);
80  msg.SerializeToOstream(&_out);
81  return _out;
82  }
83 
88  public: static std::istream &Deserialize(std::istream &_in,
89  DataType &_data)
90  {
91  MsgType msg;
92  msg.ParseFromIstream(&_in);
93 
94  _data = ignition::gazebo::convert<DataType>(msg);
95  return _in;
96  }
97  };
98 
101 
104  {
109  public: static std::ostream &Serialize(std::ostream &_out,
110  const std::vector<double> &_vec)
111  {
112  ignition::msgs::Double_V msg;
113  *msg.mutable_data() = {_vec.begin(), _vec.end()};
114  msg.SerializeToOstream(&_out);
115  return _out;
116  }
117 
122  public: static std::istream &Deserialize(std::istream &_in,
123  std::vector<double> &_vec)
124  {
125  ignition::msgs::Double_V msg;
126  msg.ParseFromIstream(&_in);
127 
128  _vec = {msg.data().begin(), msg.data().end()};
129  return _in;
130  }
131  };
132 }
133 }
134 }
135 }
136 
137 #endif
static std::istream & Deserialize(std::istream &_in, DataType &_data)
Deserialization.
Definition: Serialization.hh:88
static std::istream & Deserialize(std::istream &_in, std::vector< double > &_vec)
Deserialization.
Definition: Serialization.hh:122
static std::ostream & Serialize(std::ostream &_out, const std::vector< double > &_vec)
Serialization.
Definition: Serialization.hh:109
T end(T... args)
STL class.
T data(T... args)
static std::ostream & Serialize(std::ostream &_out, const DataType &_data)
Serialization.
Definition: Serialization.hh:76
T begin(T... args)
Serialization for that converts components data types to ignition::msgs. This assumes that convert<Da...
Definition: Serialization.hh:70
This library is part of the Ignition Robotics project.
STL class.
Serializer for components that hold std::vector<double>.
Definition: Serialization.hh:103