IceBlobToObject.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu)
20 * @date 2020
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <sstream>
27#include <string_view>
28
29#include <boost/iostreams/copy.hpp>
30#include <boost/iostreams/filter/gzip.hpp>
31#include <boost/iostreams/filtering_streambuf.hpp>
32
33#include <Ice/InputStream.h>
34
35//raw
36namespace armarx
37{
38 template <class T>
39 void
40 iceBlobToObject(T& result, const std::string_view& sv)
41 {
42 const auto first = reinterpret_cast<const Ice::Byte*>(sv.data());
43 const auto last = first + sv.size();
44 Ice::InputStream{std::make_pair(first, last)}.read(result);
45 }
46
47 template <class T>
48 T
49 iceBlobToObject(const std::string_view& sv)
50 {
51 T result;
52 iceBlobToObject(result, sv);
53 return result;
54 }
55
56 template <class T>
58 {
59 void
60 deserialize(T& result, const std::string_view& sv)
61 {
62 iceBlobToObject(result, sv);
63 }
64
65 T
66 deserialize(const std::string_view& sv)
67 {
68 return iceBlobToObject<T>(sv);
69 }
70 };
71} // namespace armarx
72
73//compressed
74namespace armarx
75{
76 template <class T>
77 void
78 compressedIceBlobToObject(T& result, const std::string_view& sv)
79 {
80 std::stringstream istr;
81 istr << sv;
82 boost::iostreams::filtering_istreambuf in;
83 in.push(boost::iostreams::gzip_decompressor());
84 in.push(istr);
85 std::stringstream ostr;
86 boost::iostreams::copy(in, ostr);
87
88 iceBlobToObject(result, ostr.str());
89 }
90
91 template <class T>
92 T
93 compressedIceBlobToObject(const std::string_view& sv)
94 {
95 T result;
96 compressedIceBlobToObject(result, sv);
97 return result;
98 }
99
100 template <class T>
102 {
103 void
104 deserialize(T& result, const std::string_view& sv)
105 {
106 compressedIceBlobToObject(result, sv);
107 }
108
109 T
110 deserialize(const std::string_view& sv)
111 {
113 }
114 };
115} // namespace armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
void compressedIceBlobToObject(T &result, const std::string_view &sv)
void iceBlobToObject(T &result, const std::string_view &sv)
void deserialize(T &result, const std::string_view &sv)
T deserialize(const std::string_view &sv)
void deserialize(T &result, const std::string_view &sv)