mirror of
https://github.com/qicosmos/rest_rpc.git
synced 2026-08-29 16:40:48 +08:00
simplify user interface
This commit is contained in:
+11
-2
@@ -30,7 +30,16 @@ namespace rest_rpc {
|
||||
template<typename T>
|
||||
inline T get_result(string_view result) {
|
||||
rpc_service::msgpack_codec codec;
|
||||
auto err_tp = codec.unpack<std::tuple<int, T>>(result.data(), result.size());
|
||||
return std::get<1>(err_tp);
|
||||
auto tp = codec.unpack<std::tuple<int, T>>(result.data(), result.size());
|
||||
return std::get<1>(tp);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T as(string_view result) {
|
||||
if (has_error(result)) {
|
||||
throw std::logic_error("rpc error");
|
||||
}
|
||||
|
||||
return get_result<T>(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user