diff --git a/examples/rpc_lite_server/rpc_lite_server.ino b/examples/rpc_lite_server/rpc_lite_server.ino index 81da0e1..3bd2f79 100644 --- a/examples/rpc_lite_server/rpc_lite_server.ino +++ b/examples/rpc_lite_server/rpc_lite_server.ino @@ -15,6 +15,16 @@ MsgPack::str_t loopback(MsgPack::str_t message){ return message; } +class multiplier { +public: + + multiplier(){} + static int mult(int a, int b){ + return a*b; + } +}; + + void setup() { Serial1.begin(115200); transport.begin(); @@ -24,6 +34,8 @@ void setup() { server.bind("add", add); server.bind("greet", greet); + server.bind("another_greeting", [] {return MsgPack::str_t ("This is a lambda greeting");}); + server.bind("object_multi", &multiplier::mult); } diff --git a/src/decoder.h b/src/decoder.h index 51ea45f..97052bc 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -4,6 +4,7 @@ #include "MsgPack.h" #include "transport.h" #include "dispatcher.h" +#include "rpclite_utils.h" #define NO_MSG -1 @@ -293,91 +294,6 @@ class RpcDecoder { return 0; } - bool unpackObject(MsgPack::Unpacker& unpacker){ - - if (unpacker.isNil()){ - static MsgPack::object::nil_t nil; - return unpacker.deserialize(nil); - } - if (unpacker.isBool()){ - static bool b; - return unpacker.deserialize(b); - } - if (unpacker.isUInt() || unpacker.isInt()){ - static int integer; - return unpacker.deserialize(integer); - } - if (unpacker.isFloat32()){ - static float num32; - return unpacker.deserialize(num32); - } - if (unpacker.isFloat64()){ - static double num64; - return unpacker.deserialize(num64); - } - if (unpacker.isStr()){ - static MsgPack::str_t string; - return unpacker.deserialize(string); - } - if (unpacker.isBin()){ - static MsgPack::bin_t bytes; - return unpacker.deserialize(bytes); - } - if (unpacker.isArray()){ - static size_t arr_sz; - return unpackArray(unpacker, arr_sz); - } - if (unpacker.isMap()){ - static size_t map_sz; - return unpackMap(unpacker, map_sz); - } - if (unpacker.isFixExt() || unpacker.isExt()){ - static MsgPack::object::ext e; - return unpacker.deserialize(e); - } - if (unpacker.isTimestamp()){ - static MsgPack::object::timespec t; - return unpacker.deserialize(t); - } - - return false; - } - - bool unpackArray(MsgPack::Unpacker& unpacker, size_t& size) { - - static MsgPack::arr_size_t sz; - unpacker.deserialize(sz); - - size = 0; - for (size_t i=0; i -#include +#include namespace RpcUtils { namespace detail { + +/////////////////////////////////////// +/// --- deserialization helpers --- /// +/////////////////////////////////////// + +bool unpackObject(MsgPack::Unpacker& unpacker); + +bool unpackArray(MsgPack::Unpacker& unpacker, size_t& size) { + + static MsgPack::arr_size_t sz; + unpacker.deserialize(sz); + + size = 0; + for (size_t i=0; i bytes; + return unpacker.deserialize(bytes); + } + if (unpacker.isArray()){ + static size_t arr_sz; + return unpackArray(unpacker, arr_sz); + } + if (unpacker.isMap()){ + static size_t map_sz; + return unpackMap(unpacker, map_sz); + } + if (unpacker.isFixExt() || unpacker.isExt()){ + static MsgPack::object::ext e; + return unpacker.deserialize(e); + } + if (unpacker.isTimestamp()){ + static MsgPack::object::timespec t; + return unpacker.deserialize(t); + } + + return false; +} + template bool deserialize_single(MsgPack::Unpacker& unpacker, T& value) { if (!unpacker.unpackable(value)) return false; @@ -15,6 +107,11 @@ bool deserialize_single(MsgPack::Unpacker& unpacker, T& value) { return true; } + +///////////////////////////// +/// --- tuple helpers --- /// +///////////////////////////// + template typename std::enable_if::type deserialize_tuple(MsgPack::Unpacker&, std::tuple&) {