1212#ifndef RPCLITE_WRAPPER_H
1313#define RPCLITE_WRAPPER_H
1414
15+ #include < string>
16+
1517#include " error.h"
1618#include " rpclite_utils.h"
1719
@@ -69,7 +71,20 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
6971 return false ;
7072 }
7173
72- return handle_call (unpacker, packer);
74+ const int res = handle_call (unpacker, packer);
75+ if (res<0 ) {
76+ MsgPack::str_t err_msg = " Wrong type parameter in position: " ;
77+ #ifdef ARDUINO
78+ err_msg += String (TYPE_ERROR-res);
79+ #else
80+ err_msg += std::to_string (TYPE_ERROR-res);
81+ #endif
82+ RpcError error (MALFORMED_CALL_ERR, err_msg);
83+ packer.serialize (error, nil);
84+ return false ;
85+ }
86+
87+ return true ;
7388
7489#ifdef HANDLE_RPC_ERRORS
7590 } catch (const std::exception& e) {
@@ -86,27 +101,29 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
86101 std::function<R (Args...)> _func;
87102
88103 template <typename Dummy = R>
89- typename std::enable_if<std::is_void<Dummy>::value, bool >::type
104+ typename std::enable_if<std::is_void<Dummy>::value, int >::type
90105 handle_call (MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) {
91106 // unpacker not ready if deserialization fails at this point
92107 std::tuple<Args...> args;
93- if (!deserialize_tuple (unpacker, args)) return false ;
108+ const int res = deserialize_tuple (unpacker, args);
109+ if (res<0 ) return res;
94110 MsgPack::object::nil_t nil;
95111 invoke_with_tuple (_func, args, arx::stdx::make_index_sequence<sizeof ...(Args)>{});
96112 packer.serialize (nil, nil);
97- return true ;
113+ return 0 ;
98114 }
99115
100116 template <typename Dummy = R>
101- typename std::enable_if<!std::is_void<Dummy>::value, bool >::type
117+ typename std::enable_if<!std::is_void<Dummy>::value, int >::type
102118 handle_call (MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) {
103119 // unpacker not ready if deserialization fails at this point
104120 std::tuple<Args...> args;
105- if (!deserialize_tuple (unpacker, args)) return false ;
121+ const int res = deserialize_tuple (unpacker, args);
122+ if (res<0 ) return res;
106123 MsgPack::object::nil_t nil;
107124 R out = invoke_with_tuple (_func, args, arx::stdx::make_index_sequence<sizeof ...(Args)>{});
108125 packer.serialize (nil, out);
109- return true ;
126+ return 0 ;
110127 }
111128};
112129
0 commit comments