RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Uint64Converter.cpp
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
6  * 2011 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
7  *
8  * This file may be licensed under the terms of the
9  * GNU Lesser General Public License Version 3 (the ``LGPL''),
10  * or (at your option) any later version.
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the LGPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the LGPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * The development of this software was supported by:
23  * CoR-Lab, Research Institute for Cognition and Robotics
24  * Bielefeld University
25  *
26  * ============================================================ */
27 
28 #include "Uint64Converter.h"
29 
30 #include <sstream>
31 
32 #include <boost/cstdint.hpp>
33 #include <boost/lexical_cast.hpp>
34 
35 #include "SerializationException.h"
36 
37 using namespace std;
38 
39 using namespace boost;
40 
41 namespace rsb {
42 namespace converter {
43 
44 const string Uint64Converter::WIRE_SCHEMA = "uint64";
45 
46 Uint64Converter::Uint64Converter() :
47  Converter<string> (WIRE_SCHEMA, RSB_TYPE_TAG(uint64_t)) {
48 }
49 
51 }
52 
53 string Uint64Converter::serialize(const AnnotatedData& data, string& wire) {
54  assert(data.first == this->getDataType());
55 
56  boost::shared_ptr<uint64_t> number = boost::static_pointer_cast<uint64_t>(data.second);
57  wire.resize(8);
58  for (uint64_t i = 0; i < 8; ++i) {
59  wire[i] = (unsigned char) ((*number & (0xffull << (i * 8ull))) >> (i * 8ull));
60  }
61  return WIRE_SCHEMA;
62 }
63 
65  const string& wire) {
66  assert(wireSchema == WIRE_SCHEMA);
67  assert(wire.size() == 8);
68 
69  boost::shared_ptr<uint64_t> number(new uint64_t(0));
70  for (uint64_t i = 0; i < 8; ++i) {
71  *number |= ((uint64_t) ((unsigned char) wire[i]) << (i * 8ull));
72  }
73  return make_pair(getDataType(), number);
74 }
75 
76 }
77 }