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

Update RpcClient::invoke_method() to return a UMessage in support of symmetry / flexibility #27

Closed
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/rpc/rpcmapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
********************************************************************************/

use protobuf::well_known_types::any::Any;
use protobuf::MessageFull;
use protobuf::MessageField;
use protobuf::MessageFull;
use std::default::Default;
use std::fmt;

Expand Down Expand Up @@ -85,7 +85,9 @@ impl RpcMapper {
{
let message = response?; // Directly returns in case of error
let MessageField(Some(payload)) = message.payload else {
return Err(RpcMapperError::InvalidPayload("Payload is empty".to_string()));
return Err(RpcMapperError::InvalidPayload(
PLeVasseur marked this conversation as resolved.
Show resolved Hide resolved
"Payload is empty".to_string(),
));
};
Any::try_from(*payload)
.map_err(|_e| {
Expand Down Expand Up @@ -128,12 +130,16 @@ impl RpcMapper {
pub fn map_response_to_result(response: RpcClientResult) -> RpcPayloadResult {
let message = response?; // Directly returns in case of error
let MessageField(Some(payload)) = message.payload else {
return Err(RpcMapperError::InvalidPayload("Payload is empty".to_string()));
return Err(RpcMapperError::InvalidPayload(
"Payload is empty".to_string(),
));
};
let payload = *payload;
Any::try_from(payload)
.map_err(|e| {
RpcMapperError::UnknownType(format!("Couldn't decode payload into Any: {:?}", e).to_string())
RpcMapperError::UnknownType(
format!("Couldn't decode payload into Any: {:?}", e).to_string(),
)
})
.and_then(|any| {
match Self::unpack_any::<UStatus>(&any) {
Expand Down
Loading