Serializer.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_SERIALIZER_H
24 #define VARIANT_TOPIC_TOOLS_SERIALIZER_H
25 
26 #include <ros/ros.h>
27 
30 
31 namespace variant_topic_tools {
34  class Serializer {
35  public:
38  Serializer();
39 
45  Serializer(const DataType& dataType);
46 
49  Serializer(const Serializer& src);
50 
53  ~Serializer();
54 
57  size_t getSerializedLength(const Variant& value) const;
58 
61  bool isValid() const;
62 
65  void clear();
66 
69  void serialize(ros::serialization::OStream& stream, const Variant& value);
70 
73  void deserialize(ros::serialization::IStream& stream, Variant& value);
74 
77  void advance(ros::serialization::Stream& stream, const Variant& value);
78 
81  inline operator void*() const {
82  return (impl) ? (void*)1 : (void*)0;
83  };
84 
85  protected:
88  class Impl {
89  public:
92  Impl();
93 
96  virtual ~Impl();
97 
101  virtual size_t getSerializedLength(const Variant& value) const = 0;
102 
105  virtual void serialize(ros::serialization::OStream& stream, const
106  Variant& value) = 0;
107 
110  virtual void deserialize(ros::serialization::IStream& stream,
111  Variant& value) = 0;
112 
115  void advance(ros::serialization::Stream& stream, const Variant& value);
116  };
117 
121 
124  typedef boost::weak_ptr<Impl> ImplWPtr;
125 
128  ImplPtr impl;
129  };
130 
133  std::ostream& operator<<(std::ostream& stream, const Serializer& serializer);
134 };
135 
136 #endif
bool isValid() const
True, if this serializer is valid.
Definition: Serializer.cpp:61
ImplPtr impl
The serializer&#39;s implementation.
Definition: Serializer.h:128
Header file providing forward declarations for the variant topic tools.
void serialize(ros::serialization::OStream &stream, const Variant &value)
Serialize a variant value to an output stream.
Definition: Serializer.cpp:73
boost::weak_ptr< Impl > ImplWPtr
Declaration of the serializer implementation weak pointer type.
Definition: Serializer.h:124
boost::shared_ptr< Impl > ImplPtr
Declaration of the serializer implementation pointer type.
Definition: Serializer.h:120
Header file providing the data type traits.
void advance(ros::serialization::Stream &stream, const Variant &value)
Advance a stream by the length of a serialized value.
Definition: Serializer.cpp:89
size_t getSerializedLength(const Variant &value) const
Retrieve the serialized length of a variant value.
Definition: Serializer.cpp:54
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
virtual size_t getSerializedLength(const Variant &value) const =0
Retrieve the serialized length of a variant value (abstract declaration)
virtual void deserialize(ros::serialization::IStream &stream, Variant &value)=0
Deserialize a variant value (abstract declaration)
Serializer implementation.
Definition: Serializer.h:88
void deserialize(ros::serialization::IStream &stream, Variant &value)
Deserialize a variant value from an input stream.
Definition: Serializer.cpp:81
virtual void serialize(ros::serialization::OStream &stream, const Variant &value)=0
Serialize a variant value (abstract declaration)
Serializer()
Default constructor.
Definition: Serializer.cpp:29
void clear()
Clear the serializer.
Definition: Serializer.cpp:69
void advance(ros::serialization::Stream &stream, const Variant &value)
Advance a stream by the length of a serialized value.
Definition: Serializer.cpp:97


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:50