Serializer.cpp
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 
22 
23 namespace variant_topic_tools {
24 
25 /*****************************************************************************/
26 /* Constructors and Destructor */
27 /*****************************************************************************/
28 
30 }
31 
32 Serializer::Serializer(const DataType& dataType) {
33  if (dataType.isValid())
34  impl = dataType.createSerializer().impl;
35 }
36 
38  impl(src.impl) {
39 }
40 
42 }
43 
45 }
46 
48 }
49 
50 /*****************************************************************************/
51 /* Accessors */
52 /*****************************************************************************/
53 
54 size_t Serializer::getSerializedLength(const Variant& value) const {
55  if (impl)
56  return impl->getSerializedLength(value);
57  else
58  return 0;
59 }
60 
61 bool Serializer::isValid() const {
62  return impl != nullptr;
63 }
64 
65 /*****************************************************************************/
66 /* Methods */
67 /*****************************************************************************/
68 
70  impl.reset();
71 }
72 
74  value) {
75  if (impl)
76  impl->serialize(stream, value);
77  else
79 }
80 
82  value) {
83  if (impl)
84  impl->deserialize(stream, value);
85  else
87 }
88 
90  value) {
91  if (impl)
92  return impl->advance(stream, value);
93  else
95 }
96 
98  Variant& value) {
99  stream.advance(getSerializedLength(value));
100 }
101 
102 /*****************************************************************************/
103 /* Operators */
104 /*****************************************************************************/
105 
106 std::ostream& operator<<(std::ostream& stream, const Serializer& serializer) {
107  return stream;
108 }
109 
110 }
Header file providing the DataType class interface.
bool isValid() const
True, if this serializer is valid.
Definition: Serializer.cpp:61
Serializer createSerializer() const
Create a serializer for this data type.
Definition: DataType.cpp:161
Header file providing the Serializer class interface.
ImplPtr impl
The serializer&#39;s implementation.
Definition: Serializer.h:128
ROS_FORCE_INLINE uint8_t * advance(uint32_t len)
void serialize(ros::serialization::OStream &stream, const Variant &value)
Serialize a variant value to an output stream.
Definition: Serializer.cpp:73
Exception thrown in case of an invalid serializer.
Definition: Exceptions.h:201
bool isValid() const
True, if this data type is valid.
Definition: DataType.cpp:133
Header file defining exceptions for the variant topic tools.
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
void deserialize(ros::serialization::IStream &stream, Variant &value)
Deserialize a variant value from an input stream.
Definition: Serializer.cpp:81
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