Skip to content

Commit

Permalink
Fix RPC argument order
Browse files Browse the repository at this point in the history
  • Loading branch information
LubosD authored and faaxm committed Jul 15, 2019
1 parent c9674ec commit 7ba1955
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/src/Utils/AnyRpcUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ std::vector<std::string> unpackAnyRpcParam(anyrpc::Value& value)
return result;
}

/**
* Converts a value in an anyrpc::Value array at the given index
* to the requested type and increases the index.
**/
template <typename T>
T unpackAnyRpcParamArray(anyrpc::Value& params, int& index)
{
auto value = unpackAnyRpcParam<T>(params[index]);
++index;
return value;
}

/**
* Functions that call a std::function and assign its returned
* value to the given anyrpc::Value. If the return type
Expand Down Expand Up @@ -105,6 +93,12 @@ void callAndAssignAnyRpcResult(std::function<void(Args...)> func, anyrpc::Value&
func(std::forward<Args>(args)...);
}

template<typename...Args, std::size_t... Is, typename F>
void callAndAssignAnyRpcResult(F func, anyrpc::Value& result, std::index_sequence<Is...>, anyrpc::Value& params)
{
callAndAssignAnyRpcResult(func, result, unpackAnyRpcParam<Args>(params[Is])...);
}

/**
* The AnyRpcFunction object that takes a std::function that is
* to be called. The parameters received from AnyRPC are automatically
Expand Down Expand Up @@ -133,8 +127,7 @@ class AnyRpcFunction<R(Args...)> : public anyrpc::Method {
anyrpc::AnyRpcErrorInvalidParams, "Invalid parameters. Number of parameters incorrect.");
}

int paramIndex = 0;
callAndAssignAnyRpcResult(m_func, result, unpackAnyRpcParamArray<Args>(params, paramIndex)...);
callAndAssignAnyRpcResult<Args...>(m_func, result, std::make_index_sequence<sizeof...(Args)>(), params);
}

private:
Expand Down

0 comments on commit 7ba1955

Please sign in to comment.