8 #ifndef INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_
9 #define INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_
12 using namespace org::infinispan::protostream;
14 template <
class T>
bool unwrapResults(QueryResponse resp, std::vector<T> &res)
16 if (resp.projectionsize()>0)
20 for (
int i=0; i<resp.results_size(); i++)
22 const WrappedMessage &wm =resp.results(i);
23 if ( wm.has_wrappedbytes() )
26 wmn.ParseFromString(wm.wrappedbytes());
27 if (wmn.has_wrappedmessagebytes()) {
28 sample_bank_account::User u1;
29 u1.ParseFromString(wmn.wrappedmessagebytes());
39 template <> std::string unwrapSingleValue<std::string>(
const WrappedMessage& wm)
41 if (wm.has_wrappedstring())
43 return wm.wrappedstring();
47 throw "std::string not found in response";
53 if (wm.has_wrappedint32())
55 return wm.wrappedint32();
57 else if (wm.has_wrappedint64())
59 return wm.wrappedint64();
63 throw "std::string not found in response";
69 return unwrapSingleValue<T>(qr.results(0));
73 #if !defined (_MSC_VER) || (_MSC_VER>=1800)
74 template <
typename H,
typename... Params> std::tuple<H, Params...>
popTuple(QueryResponse &resp,
int &k)
76 H s = unwrapSingleValue<H>(resp.results(k++));
77 std::tuple<Params...> p=
popTuple<Params... >(resp,k);
78 return std::tuple_cat(std::tie(s),p);
82 std::tuple<std::string> popTuple<std::string>(QueryResponse & resp,
int &k)
84 std::string s(unwrapSingleValue<std::string>(resp.results(k++)));
85 return std::make_tuple<std::string>(std::move(s));
92 return std::make_tuple<int>(std::move(s));
96 template<
typename... Params>
bool unwrapProjection(QueryResponse &resp, std::vector<std::tuple<Params...> > &prjRes)
98 if (resp.projectionsize() == 0) {
101 int numTuple = resp.results_size() / resp.projectionsize();
103 for (
int i = 0; i < numTuple; i++) {
104 std::tuple<Params...> tp=
popTuple<Params...>(resp, k) ;
105 prjRes.push_back(tp);
bool unwrapProjection(QueryResponse &resp, std::vector< std::tuple< Params...> > &prjRes)
Definition: QueryUtils.h:96
T unwrapSingleValue(const WrappedMessage &wm)
int unwrapSingleValue< int >(const WrappedMessage &wm)
Definition: QueryUtils.h:51
bool unwrapResults(QueryResponse resp, std::vector< T > &res)
Definition: QueryUtils.h:14
std::tuple< int > popTuple< int >(QueryResponse &resp, int &k)
Definition: QueryUtils.h:89
T unwrapSingleResult(const QueryResponse &qr)
Definition: QueryUtils.h:67
std::tuple< H, Params...> popTuple(QueryResponse &resp, int &k)
Definition: QueryUtils.h:74