Skip to content

Commit cb9bef9

Browse files
committed
mod: reverted rpclite_utils
1 parent 060ab54 commit cb9bef9

File tree

3 files changed

+123
-145
lines changed

3 files changed

+123
-145
lines changed

src/decoder.h

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "MsgPack.h"
55
#include "transport.h"
66
#include "dispatcher.h"
7-
#include "rpclite_utils.h"
87

98

109
#define NO_MSG -1
@@ -294,6 +293,91 @@ class RpcDecoder {
294293
return 0;
295294
}
296295

296+
bool unpackArray(MsgPack::Unpacker& unpacker, size_t& size) {
297+
MsgPack::arr_size_t sz;
298+
unpacker.deserialize(sz);
299+
300+
size = 0;
301+
for (size_t i=0; i<sz.size(); i++){
302+
if (unpackObject(unpacker)){
303+
size++;
304+
} else {
305+
return false;
306+
}
307+
}
308+
309+
return true;
310+
311+
}
312+
313+
bool unpackMap(MsgPack::Unpacker& unpacker, size_t& size) {
314+
MsgPack::map_size_t sz;
315+
unpacker.deserialize(sz);
316+
317+
size = 0;
318+
for (size_t i=0; i<sz.size(); i++){
319+
if (unpackObject(unpacker) && unpackObject(unpacker)){ // must unpack key&value
320+
size++;
321+
} else {
322+
return false;
323+
}
324+
}
325+
326+
return true;
327+
328+
}
329+
330+
bool unpackObject(MsgPack::Unpacker& unpacker){
331+
332+
if (unpacker.isNil()){
333+
static MsgPack::object::nil_t nil;
334+
return unpacker.deserialize(nil);
335+
}
336+
if (unpacker.isBool()){
337+
static bool b;
338+
return unpacker.deserialize(b);
339+
}
340+
if (unpacker.isUInt() || unpacker.isInt()){
341+
static int integer;
342+
return unpacker.deserialize(integer);
343+
}
344+
if (unpacker.isFloat32()){
345+
static float num32;
346+
return unpacker.deserialize(num32);
347+
}
348+
if (unpacker.isFloat64()){
349+
static double num64;
350+
return unpacker.deserialize(num64);
351+
}
352+
if (unpacker.isStr()){
353+
static MsgPack::str_t string;
354+
return unpacker.deserialize(string);
355+
}
356+
if (unpacker.isBin()){
357+
static MsgPack::bin_t<uint8_t> bytes;
358+
return unpacker.deserialize(bytes);
359+
}
360+
if (unpacker.isArray()){
361+
static size_t arr_sz;
362+
return unpackArray(unpacker, arr_sz);
363+
}
364+
if (unpacker.isMap()){
365+
static size_t map_sz;
366+
return unpackMap(unpacker, map_sz);
367+
}
368+
if (unpacker.isFixExt() || unpacker.isExt()){
369+
static MsgPack::object::ext e;
370+
return unpacker.deserialize(e);
371+
}
372+
if (unpacker.isTimestamp()){
373+
static MsgPack::object::timespec t;
374+
return unpacker.deserialize(t);
375+
}
376+
377+
return false;
378+
}
379+
380+
297381
};
298382

299383
#endif

src/rpclite_utils.h

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/wrapper.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,50 @@
22
#define RPCLITE_WRAPPER_H
33

44
#include "error.h"
5-
#include "rpclite_utils.h"
65

7-
using namespace RpcUtils::detail;
86

97
#ifdef HANDLE_RPC_ERRORS
108
#include <stdexcept>
119
#endif
1210

11+
template<typename T>
12+
bool deserialize_single(MsgPack::Unpacker& unpacker, T& value) {
13+
if (!unpacker.unpackable(value)) return false;
14+
unpacker.deserialize(value);
15+
return true;
16+
}
17+
18+
19+
/////////////////////////////
20+
/// --- tuple helpers --- ///
21+
/////////////////////////////
22+
23+
template<std::size_t I = 0, typename... Ts>
24+
typename std::enable_if<I == sizeof...(Ts), bool>::type
25+
deserialize_tuple(MsgPack::Unpacker&, std::tuple<Ts...>&) {
26+
return true;
27+
}
28+
29+
template<std::size_t I = 0, typename... Ts>
30+
typename std::enable_if<I < sizeof...(Ts), bool>::type
31+
deserialize_tuple(MsgPack::Unpacker& unpacker, std::tuple<Ts...>& out) {
32+
if (!deserialize_single(unpacker, std::get<I>(out))) return false;
33+
return deserialize_tuple<I + 1>(unpacker, out);
34+
}
35+
36+
template<typename... Ts>
37+
bool deserialize_all(MsgPack::Unpacker& unpacker, std::tuple<Ts...>& values) {
38+
return deserialize_tuple(unpacker, values);
39+
}
40+
41+
// Helper to invoke a function with a tuple of arguments
42+
template<typename F, typename Tuple, std::size_t... I>
43+
auto invoke_with_tuple(F&& f, Tuple&& t, arx::stdx::index_sequence<I...>)
44+
-> decltype(f(std::get<I>(std::forward<Tuple>(t))...)) {
45+
return f(std::get<I>(std::forward<Tuple>(t))...);
46+
}
47+
48+
1349
template<typename F>
1450
class RpcFunctionWrapper;
1551

0 commit comments

Comments
 (0)