Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RPC argument order #1

Merged
merged 1 commit into from
Jul 15, 2019
Merged
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
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