diff options
| author | diogo464 <[email protected]> | 2026-02-12 16:30:05 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2026-02-12 16:30:05 +0000 |
| commit | f6f4cd8fcb5dd85e62cf7b10624784f8d4bdd71a (patch) | |
| tree | caff3877282abaa3e5ab6adcb26568bb65483cee | |
| parent | f319d7ab5278a3cfb43d38875d81c28cc2dce1e1 (diff) | |
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/internal.rs | 2 | ||||
| -rw-r--r-- | src/protocol.rs | 7 | ||||
| -rw-r--r-- | urpc-macro/src/lib.rs | 12 |
4 files changed, 10 insertions, 13 deletions
| @@ -15,12 +15,12 @@ members = ["urpc-macro"] | |||
| 15 | [dependencies] | 15 | [dependencies] |
| 16 | urpc-macro = { path = "urpc-macro" } | 16 | urpc-macro = { path = "urpc-macro" } |
| 17 | 17 | ||
| 18 | bincode = { version = "2.0.1", features = ["serde"] } | ||
| 19 | bytes = { version = "1.10.1", features = ["serde"] } | 18 | bytes = { version = "1.10.1", features = ["serde"] } |
| 20 | futures = "0.3.31" | 19 | futures = "0.3.31" |
| 21 | serde = { version = "1.0.219", features = ["derive"] } | 20 | serde = { version = "1.0.219", features = ["derive"] } |
| 22 | tokio = { version = "1.44.1", features = ["full"] } | 21 | tokio = { version = "1.44.1", features = ["full"] } |
| 23 | tokio-util = { version = "0.7.14", features = ["codec"] } | 22 | tokio-util = { version = "0.7.14", features = ["codec"] } |
| 23 | postcard = { version = "1.1.3", features = ["use-std"] } | ||
| 24 | 24 | ||
| 25 | [dev-dependencies] | 25 | [dev-dependencies] |
| 26 | tokio-test = "0.4" | 26 | tokio-test = "0.4" |
diff --git a/src/internal.rs b/src/internal.rs index a3c203a..7085d84 100644 --- a/src/internal.rs +++ b/src/internal.rs | |||
| @@ -1,2 +1,2 @@ | |||
| 1 | pub use bincode; | 1 | pub use postcard; |
| 2 | pub use bytes; | 2 | pub use bytes; |
diff --git a/src/protocol.rs b/src/protocol.rs index baf886b..d789939 100644 --- a/src/protocol.rs +++ b/src/protocol.rs | |||
| @@ -76,8 +76,7 @@ impl Encoder<RpcMessage> for RpcMessageCodec { | |||
| 76 | item: RpcMessage, | 76 | item: RpcMessage, |
| 77 | dst: &mut bytes::BytesMut, | 77 | dst: &mut bytes::BytesMut, |
| 78 | ) -> std::result::Result<(), Self::Error> { | 78 | ) -> std::result::Result<(), Self::Error> { |
| 79 | let encoded = bincode::serde::encode_to_vec(&item, bincode::config::standard()) | 79 | let encoded = postcard::to_stdvec(&item).map_err(std::io::Error::other)?; |
| 80 | .map_err(std::io::Error::other)?; | ||
| 81 | let encoded = Bytes::from(encoded); | 80 | let encoded = Bytes::from(encoded); |
| 82 | self.0.encode(encoded, dst).map_err(std::io::Error::other)?; | 81 | self.0.encode(encoded, dst).map_err(std::io::Error::other)?; |
| 83 | Ok(()) | 82 | Ok(()) |
| @@ -95,9 +94,7 @@ impl Decoder for RpcMessageCodec { | |||
| 95 | ) -> std::result::Result<Option<Self::Item>, Self::Error> { | 94 | ) -> std::result::Result<Option<Self::Item>, Self::Error> { |
| 96 | match self.0.decode(src) { | 95 | match self.0.decode(src) { |
| 97 | Ok(Some(frame)) => { | 96 | Ok(Some(frame)) => { |
| 98 | let (message, _) = | 97 | let message = postcard::from_bytes(&frame).map_err(std::io::Error::other)?; |
| 99 | bincode::serde::decode_from_slice(&frame, bincode::config::standard()) | ||
| 100 | .map_err(std::io::Error::other)?; | ||
| 101 | Ok(Some(message)) | 98 | Ok(Some(message)) |
| 102 | } | 99 | } |
| 103 | Ok(None) => Ok(None), | 100 | Ok(None) => Ok(None), |
diff --git a/urpc-macro/src/lib.rs b/urpc-macro/src/lib.rs index 4facc60..9d5ce0e 100644 --- a/urpc-macro/src/lib.rs +++ b/urpc-macro/src/lib.rs | |||
| @@ -130,11 +130,11 @@ fn generate_service_into_service_match_arm(service: &Service, method: &Method) - | |||
| 130 | 130 | ||
| 131 | quote::quote! { | 131 | quote::quote! { |
| 132 | #method_name => { | 132 | #method_name => { |
| 133 | let ((#(#arg_idents),*), _) = | 133 | let (#(#arg_idents),*) = |
| 134 | urpc::internal::bincode::serde::decode_from_slice(&arguments, urpc::internal::bincode::config::standard()).map_err(std::io::Error::other)?; | 134 | urpc::internal::postcard::from_bytes(&arguments).map_err(std::io::Error::other)?; |
| 135 | let ctx = Default::default(); | 135 | let ctx = Default::default(); |
| 136 | let ret = <T as #server_trait>::#method_ident(&self.0, ctx, #(#arg_idents),*).await; | 136 | let ret = <T as #server_trait>::#method_ident(&self.0, ctx, #(#arg_idents),*).await; |
| 137 | let value = urpc::internal::bincode::serde::encode_to_vec(&ret, urpc::internal::bincode::config::standard()).map_err(std::io::Error::other)?; | 137 | let value = urpc::internal::postcard::to_stdvec(&ret).map_err(std::io::Error::other)?; |
| 138 | Ok(From::from(value)) | 138 | Ok(From::from(value)) |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| @@ -229,7 +229,7 @@ fn generate_service_client_method(service: &Service, method: &Method) -> TokenSt | |||
| 229 | let service = String::from(#service_name); | 229 | let service = String::from(#service_name); |
| 230 | let method = String::from(#method_string); | 230 | let method = String::from(#method_string); |
| 231 | let arguments = (#(#method_arg_idents),*); | 231 | let arguments = (#(#method_arg_idents),*); |
| 232 | let arguments = match urpc::internal::bincode::serde::encode_to_vec(&arguments, urpc::internal::bincode::config::standard()) { | 232 | let arguments = match urpc::internal::postcard::to_stdvec(&arguments) { |
| 233 | Ok(arguments) => From::from(arguments), | 233 | Ok(arguments) => From::from(arguments), |
| 234 | Err(err) => return Err(urpc::protocol::RpcError::Transport(std::io::Error::other(err))), | 234 | Err(err) => return Err(urpc::protocol::RpcError::Transport(std::io::Error::other(err))), |
| 235 | }; | 235 | }; |
| @@ -237,8 +237,8 @@ fn generate_service_client_method(service: &Service, method: &Method) -> TokenSt | |||
| 237 | Ok(response) => response, | 237 | Ok(response) => response, |
| 238 | Err(err) => return Err(urpc::protocol::RpcError::Transport(err)), | 238 | Err(err) => return Err(urpc::protocol::RpcError::Transport(err)), |
| 239 | }; | 239 | }; |
| 240 | match urpc::internal::bincode::serde::decode_from_slice::<std::result::Result<#method_return_type, #service_error>, _>(&response, urpc::internal::bincode::config::standard()) { | 240 | match urpc::internal::postcard::from_bytes::<std::result::Result<#method_return_type, #service_error>>(&response) { |
| 241 | Ok((result, _)) => result.map_err(urpc::protocol::RpcError::Remote), | 241 | Ok(result) => result.map_err(urpc::protocol::RpcError::Remote), |
| 242 | Err(err) => Err(urpc::protocol::RpcError::Transport(std::io::Error::other(err))), | 242 | Err(err) => Err(urpc::protocol::RpcError::Transport(std::io::Error::other(err))), |
| 243 | } | 243 | } |
| 244 | } | 244 | } |
