MessageSerializer.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 
32  memberSerializers) {
33  impl.reset(new ImplV(memberSerializers));
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 
56  memberSerializers) :
57  memberSerializers(memberSerializers) {
58 }
59 
61 }
62 
63 /*****************************************************************************/
64 /* Accessors */
65 /*****************************************************************************/
66 
68  const {
69  MessageVariant messageValue = value;
70  size_t length = 0;
71 
72  for (size_t i = 0; i < messageValue.getNumMembers(); ++i)
73  length += memberSerializers[i].getValue().getSerializedLength(
74  messageValue[i]);
75 
76  return length;
77 }
78 
79 /*****************************************************************************/
80 /* Methods */
81 /*****************************************************************************/
82 
84  const Variant& value) {
85  MessageVariant messageValue = value;
86 
87  for (size_t i = 0; i < messageValue.getNumMembers(); ++i)
88  memberSerializers[i].getValue().serialize(stream, messageValue[i]);
89 }
90 
92  Variant& value) {
93  MessageVariant messageValue = value;
94 
95  for (size_t i = 0; i < messageValue.getNumMembers(); ++i) {
96  Variant member = messageValue[i];
97  memberSerializers[i].getValue().deserialize(stream, member);
98  }
99 }
100 
101 }
ImplPtr impl
The serializer&#39;s implementation.
Definition: Serializer.h:128
Header file providing the MessageSerializer class interface.
Header file providing the MessageVariant class interface.
Message serializer implementation (variant-typed version)
MessageFieldCollection< Serializer > memberSerializers
The message member serializers.
void deserialize(ros::serialization::IStream &stream, Variant &value)
Deserialize a variant value (implementation)
size_t getNumMembers() const
Retrieve the number of members of the collection.
void serialize(ros::serialization::OStream &stream, const Variant &value)
Serialize a variant value (implementation)
ImplV(const MessageFieldCollection< Serializer > &memberSerializers=MessageFieldCollection< Serializer >())
Constructor.
size_t getSerializedLength(const Variant &value) const
Retrieve the serialized length of a variant value (implementation)
Forward declaration of the message field collection.
Definition: Forwards.h:64


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