@@ -35,7 +35,6 @@ Supported procedures:
35
35
///
36
36
/// Assumes that the request's parameters are always `String`s.
37
37
#[ derive( Debug ) ]
38
- #[ cfg_attr( feature = "msgpack" , derive( Deserialize ) ) ]
39
38
pub struct Rpc {
40
39
/// The type of msgpack request. Should always be notification.
41
40
#[ cfg( feature = "msgpack" ) ]
@@ -49,6 +48,33 @@ pub struct Rpc {
49
48
pub params : Vec < String > ,
50
49
}
51
50
51
+ #[ cfg( feature = "msgpack" ) ]
52
+ impl < ' de > Deserialize < ' de > for Rpc {
53
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
54
+ where
55
+ D : serde:: Deserializer < ' de > ,
56
+ {
57
+ use serde:: de:: { Error , Unexpected } ;
58
+
59
+ const NOTIFICATION_MESSAGE_TYPE : u64 = 2 ;
60
+
61
+ let ( msg_type, method, params) = <( u64 , String , Vec < String > ) >:: deserialize ( deserializer) ?;
62
+
63
+ if msg_type != NOTIFICATION_MESSAGE_TYPE {
64
+ return Err ( Error :: invalid_value (
65
+ Unexpected :: Unsigned ( msg_type) ,
66
+ & format ! ( "notification message type ({})" , NOTIFICATION_MESSAGE_TYPE ) . as_str ( ) ,
67
+ ) ) ;
68
+ }
69
+
70
+ Ok ( Rpc {
71
+ msg_type,
72
+ method,
73
+ params,
74
+ } )
75
+ }
76
+ }
77
+
52
78
#[ cfg( feature = "json-rpc" ) ]
53
79
impl < ' de > Deserialize < ' de > for Rpc {
54
80
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
0 commit comments