Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/rpc_lite_client/rpc_lite_client.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <Arduino_RPClite.h>

SerialTransport transport(&Serial0);
SerialTransport transport(&Serial1);
RPCClient client(transport);

void setup() {
Serial0.begin(115200);
Serial1.begin(115200);
transport.begin();
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Expand Down
4 changes: 2 additions & 2 deletions examples/rpc_lite_server/rpc_lite_server.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Arduino_RPClite.h>

SerialTransport transport(&Serial0);
SerialTransport transport(&Serial1);
RPCServer server(transport);

int add(int a, int b){
Expand All @@ -16,7 +16,7 @@ MsgPack::str_t loopback(MsgPack::str_t message){
}

void setup() {
Serial0.begin(115200);
Serial1.begin(115200);
transport.begin();
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Expand Down
1 change: 1 addition & 0 deletions src/DummyTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DummyTransport: public ITransport {

size_t write(const uint8_t* data, size_t size) override {
// Mock write
(void)data;
return size;
}

Expand Down
16 changes: 9 additions & 7 deletions src/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ class RpcFunctionWrapper<R(Args...)>: public IFunctionWrapper {
return false;
}

//unpacker not ready if deserialization fails at this point
std::tuple<Args...> args;
if (!deserialize_all<Args...>(unpacker, args)) return false;

return handle_call(args, packer);
return handle_call(unpacker, packer);

#ifdef HANDLE_RPC_ERRORS
} catch (const std::exception& e) {
Expand All @@ -116,7 +112,10 @@ class RpcFunctionWrapper<R(Args...)>: public IFunctionWrapper {

template<typename Dummy = R>
typename std::enable_if<std::is_void<Dummy>::value, bool>::type
handle_call(auto&& args, auto&& packer) {
handle_call(MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) {
//unpacker not ready if deserialization fails at this point
std::tuple<Args...> args;
if (!deserialize_all<Args...>(unpacker, args)) return false;
MsgPack::object::nil_t nil;
invoke_with_tuple(_func, args, arx::stdx::make_index_sequence<sizeof...(Args)>{});
packer.serialize(nil, nil);
Expand All @@ -125,7 +124,10 @@ class RpcFunctionWrapper<R(Args...)>: public IFunctionWrapper {

template<typename Dummy = R>
typename std::enable_if<!std::is_void<Dummy>::value, bool>::type
handle_call(auto&& args, auto&& packer) {
handle_call(MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) {
//unpacker not ready if deserialization fails at this point
std::tuple<Args...> args;
if (!deserialize_all<Args...>(unpacker, args)) return false;
MsgPack::object::nil_t nil;
R out = invoke_with_tuple(_func, args, arx::stdx::make_index_sequence<sizeof...(Args)>{});
packer.serialize(nil, out);
Expand Down