deserializer.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright 2016 Davide Faconti
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 ********************************************************************/
00034 
00035 #ifndef ROS_INTRO_DESERIALIZE_H
00036 #define ROS_INTRO_DESERIALIZE_H
00037 
00038 #include <array>
00039 #include <sstream>
00040 #include "ros_type_introspection/parser.hpp"
00041 #include "ros_type_introspection/stringtree.hpp"
00042 #include "ros_type_introspection/variant.hpp"
00043 
00044 
00045 namespace RosIntrospection{
00046 
00065 struct StringTreeLeaf{
00066 
00067   StringTreeLeaf();
00068 
00069   StringTreeNode* node_ptr;
00070 
00071   uint8_t array_size;
00072 
00073   std::array<uint16_t,7> index_array;
00074 
00076   bool toStr(SString &destination) const;
00077   bool toStr(std::string &destination) const;
00078   
00079   // return string length or -1 if failed
00080   int toStr(char* buffer) const;
00081   
00082   SString toSString() { SString out; toStr(out); return out; }
00083   
00084   std::string toStdString() { std::string out; toStr(out); return out; }
00085 };
00086 
00087 typedef struct{
00089   StringTree tree;
00090 
00093   std::vector< std::pair<StringTreeLeaf, VarNumber> > value;
00094 
00097   std::vector< std::pair<StringTreeLeaf, SString> > name;
00098 
00099   // Not used yet
00100   std::vector< std::pair<StringTreeLeaf, std::vector<uint8_t>>> blob;
00101 
00102 }ROSTypeFlat;
00103 
00104 
00130 void buildRosFlatType(const ROSTypeList& type_map,
00131                       ROSType type,
00132                       SString prefix,
00133                       uint8_t *buffer_ptr,
00134                       ROSTypeFlat* flat_container_output,
00135                       const uint32_t max_array_size );
00136 
00137 
00138 inline std::ostream& operator<<(std::ostream &os, const StringTreeLeaf& leaf )
00139 {
00140   SString dest;
00141   leaf.toStr(dest);
00142   os << dest;
00143   return os;
00144 }
00145 
00146 
00147 //-------------------- UTILITY function ------------------
00148 // much faster for numbers below 100
00149 inline int print_number(char* buffer, uint16_t value)
00150 {
00151     const char DIGITS[] =
00152             "00010203040506070809"
00153             "10111213141516171819"
00154             "20212223242526272829"
00155             "30313233343536373839"
00156             "40414243444546474849"
00157             "50515253545556575859"
00158             "60616263646566676869"
00159             "70717273747576777879"
00160             "80818283848586878889"
00161             "90919293949596979899";
00162     if (value < 10)
00163     {
00164         buffer[0] = static_cast<char>('0' + value);
00165         return 1;
00166     }
00167     else if (value < 100) {
00168         value *= 2;
00169         buffer[0] = DIGITS[ value+1 ];
00170         buffer[1] = DIGITS[ value ];
00171         return 2;
00172     }
00173     else{
00174         return sprintf( buffer,"%d", value );
00175     }
00176 }
00177 
00178 
00179 } //end namespace
00180 
00181 #endif // ROS_INTRO_DESERIALIZE_H


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Sun Oct 1 2017 02:54:53