ArraySerializer.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 
21 
22 namespace variant_topic_tools {
23 
24 /*****************************************************************************/
25 /* Constructors and Destructor */
26 /*****************************************************************************/
27 
29 }
30 
31 ArraySerializer::ArraySerializer(const Serializer& memberSerializer, size_t
32  numMembers) {
33  impl.reset(new ImplV(memberSerializer, numMembers));
34 }
35 
37  Serializer(src) {
38 }
39 
41  Serializer(src) {
42  if (impl)
43  BOOST_ASSERT(boost::dynamic_pointer_cast<Impl>(impl));
44 }
45 
47 }
48 
50 }
51 
53 }
54 
55 ArraySerializer::ImplV::ImplV(const Serializer& memberSerializer, size_t
56  numMembers) :
57  memberSerializer(memberSerializer),
58  numMembers(numMembers) {
59 }
60 
62 }
63 
64 /*****************************************************************************/
65 /* Accessors */
66 /*****************************************************************************/
67 
69  const {
70  ArrayVariant arrayValue = value;
71  size_t length = 0;
72 
73  if (!numMembers)
74  length += sizeof(uint32_t);
75 
76  for (size_t i = 0; i < arrayValue.getNumMembers(); ++i)
77  length += memberSerializer.getSerializedLength(arrayValue[i]);
78 
79  return length;
80 }
81 
82 /*****************************************************************************/
83 /* Methods */
84 /*****************************************************************************/
85 
87  const Variant& value) {
88  ArrayVariant arrayValue = value;
89 
90  if (!numMembers)
91  stream.next((uint32_t)arrayValue.getNumMembers());
92 
93  for (size_t i = 0; i < arrayValue.getNumMembers(); ++i)
94  memberSerializer.serialize(stream, arrayValue[i]);
95 }
96 
98  Variant& value) {
99  ArrayVariant arrayValue = value;
100 
101  if (!numMembers) {
102  uint32_t numMembers = 0;
103  stream.next(numMembers);
104 
105  arrayValue.resize(numMembers);
106  }
107 
108  for (size_t i = 0; i < arrayValue.getNumMembers(); ++i) {
109  Variant member = arrayValue[i];
110  memberSerializer.deserialize(stream, member);
111  }
112 }
113 
114 }
Header file providing the ArraySerializer class interface.
size_t numMembers
The number of array members.
void resize(size_t numMembers)
Resize the array.
ImplPtr impl
The serializer&#39;s implementation.
Definition: Serializer.h:128
ROS_FORCE_INLINE void next(T &t)
void serialize(ros::serialization::OStream &stream, const Variant &value)
Serialize a variant value to an output stream.
Definition: Serializer.cpp:73
ArraySerializer()
Default constructor.
size_t getSerializedLength(const Variant &value) const
Retrieve the serialized length of a variant value.
Definition: Serializer.cpp:54
Header file providing the ArrayVariant class interface.
size_t getSerializedLength(const Variant &value) const
Retrieve the serialized length of a variant value (implementation)
void deserialize(ros::serialization::IStream &stream, Variant &value)
Deserialize a variant value from an input stream.
Definition: Serializer.cpp:81
Array serializer implementation (variant-typed version)
size_t getNumMembers() const
Retrieve the number of members of the collection.
Serializer memberSerializer
The array member serializer.
void serialize(ros::serialization::OStream &stream, const Variant &value)
Serialize a variant value (implementation)
ROS_FORCE_INLINE void next(const T &t)
void deserialize(ros::serialization::IStream &stream, Variant &value)
Deserialize a variant value (implementation)
ImplV(const Serializer &memberSerializer=Serializer(), size_t numMembers=0)
Default constructor.


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