MessageSerializer.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2014 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include "variant_topic_tools/MessageSerializer.h"
00020 #include "variant_topic_tools/MessageVariant.h"
00021 
00022 namespace variant_topic_tools {
00023 
00024 /*****************************************************************************/
00025 /* Constructors and Destructor                                               */
00026 /*****************************************************************************/
00027 
00028 MessageSerializer::MessageSerializer() {
00029 }
00030 
00031 MessageSerializer::MessageSerializer(const MessageFieldCollection<Serializer>&
00032     memberSerializers) {
00033   impl.reset(new ImplV(memberSerializers));
00034 }
00035 
00036 MessageSerializer::MessageSerializer(const MessageSerializer& src) :
00037   Serializer(src) {
00038 }
00039 
00040 MessageSerializer::MessageSerializer(const Serializer& src) :
00041   Serializer(src) {
00042   if (impl)
00043     BOOST_ASSERT(boost::dynamic_pointer_cast<Impl>(impl));
00044 }
00045 
00046 MessageSerializer::~MessageSerializer() {
00047 }
00048 
00049 MessageSerializer::Impl::Impl() {
00050 }
00051 
00052 MessageSerializer::Impl::~Impl() {
00053 }
00054 
00055 MessageSerializer::ImplV::ImplV(const MessageFieldCollection<Serializer>&
00056     memberSerializers) :
00057   memberSerializers(memberSerializers) {
00058 }
00059 
00060 MessageSerializer::ImplV::~ImplV() {
00061 }
00062 
00063 /*****************************************************************************/
00064 /* Accessors                                                                 */
00065 /*****************************************************************************/
00066 
00067 size_t MessageSerializer::ImplV::getSerializedLength(const Variant& value)
00068     const {
00069   MessageVariant messageValue = value;
00070   size_t length = 0;
00071 
00072   for (size_t i = 0; i < messageValue.getNumMembers(); ++i)
00073     length += memberSerializers[i].getValue().getSerializedLength(
00074       messageValue[i]);
00075   
00076   return length;
00077 }
00078 
00079 /*****************************************************************************/
00080 /* Methods                                                                   */
00081 /*****************************************************************************/
00082 
00083 void MessageSerializer::ImplV::serialize(ros::serialization::OStream& stream,
00084     const Variant& value) {
00085   MessageVariant messageValue = value;
00086   
00087   for (size_t i = 0; i < messageValue.getNumMembers(); ++i)
00088     memberSerializers[i].getValue().serialize(stream, messageValue[i]);
00089 }
00090 
00091 void MessageSerializer::ImplV::deserialize(ros::serialization::IStream& stream,
00092     Variant& value) {
00093   MessageVariant messageValue = value;
00094 
00095   for (size_t i = 0; i < messageValue.getNumMembers(); ++i) {
00096     Variant member = messageValue[i];
00097     memberSerializers[i].getValue().deserialize(stream, member);
00098   }
00099 }
00100 
00101 }


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Tue Jul 9 2019 03:18:42