@@ -15,6 +15,13 @@ use crate::record::{self, Record, StaticRecord};
15
15
#[ derive( Clone , Debug , Default ) ]
16
16
pub struct MarshalledRequest ( pub Vec < u8 > ) ;
17
17
18
+ #[ derive( Clone , Copy , Debug ) ]
19
+ pub enum OpStat < ' a > {
20
+ None ,
21
+ Path ( & ' a str ) ,
22
+ Watch { path : & ' a str , mode : WatchMode } ,
23
+ }
24
+
18
25
impl MarshalledRequest {
19
26
pub fn new ( code : OpCode , body : & dyn Record ) -> MarshalledRequest {
20
27
let header = RequestHeader :: with_code ( code) ;
@@ -45,42 +52,64 @@ impl MarshalledRequest {
45
52
xid_buf. put_i32 ( xid) ;
46
53
}
47
54
48
- pub fn get_operation_info ( & self ) -> ( OpCode , Option < ( & str , WatchMode ) > ) {
55
+ fn get_body ( & self ) -> & [ u8 ] {
56
+ let offset = 4 + RequestHeader :: record_len ( ) ;
57
+ & self . 0 [ offset..]
58
+ }
59
+
60
+ pub fn get_operation_info ( & self ) -> ( OpCode , OpStat < ' _ > ) {
49
61
let op_code = self . get_code ( ) ;
50
- let watcher_info = match op_code {
62
+ let stat = match op_code {
63
+ OpCode :: Create
64
+ | OpCode :: Create2
65
+ | OpCode :: CreateTtl
66
+ | OpCode :: CreateContainer
67
+ | OpCode :: SetData
68
+ | OpCode :: Delete
69
+ | OpCode :: DeleteContainer
70
+ | OpCode :: GetACL
71
+ | OpCode :: SetACL
72
+ | OpCode :: Sync
73
+ | OpCode :: Check
74
+ | OpCode :: CheckWatches
75
+ | OpCode :: GetEphemerals
76
+ | OpCode :: GetAllChildrenNumber => {
77
+ let mut body = self . get_body ( ) ;
78
+ let server_path = record:: deserialize :: < & str > ( & mut body) . unwrap ( ) ;
79
+ OpStat :: Path ( server_path)
80
+ } ,
51
81
OpCode :: GetData
52
82
| OpCode :: Exists
53
83
| OpCode :: GetChildren
54
84
| OpCode :: GetChildren2
55
85
| OpCode :: AddWatch
56
86
| OpCode :: RemoveWatches => {
57
- let offset = 4 + RequestHeader :: record_len ( ) ;
58
- let mut body = & self . 0 [ offset..] ;
87
+ let mut body = self . get_body ( ) ;
59
88
let server_path = record:: deserialize :: < & str > ( & mut body) . unwrap ( ) ;
60
89
if op_code == OpCode :: AddWatch || op_code == OpCode :: RemoveWatches {
61
90
body. advance ( 3 ) ;
62
91
}
63
92
let watch = body. get_u8 ( ) ;
64
93
if op_code == OpCode :: AddWatch {
65
94
let add_mode = AddWatchMode :: try_from ( watch as i32 ) . unwrap ( ) ;
66
- Some ( ( server_path, WatchMode :: from ( add_mode) ) )
95
+ OpStat :: Watch { path : server_path, mode : WatchMode :: from ( add_mode) }
67
96
} else if op_code == OpCode :: RemoveWatches {
68
- Some ( ( server_path, WatchMode :: try_from ( watch as i32 ) . unwrap ( ) ) )
97
+ OpStat :: Watch { path : server_path, mode : WatchMode :: try_from ( watch as i32 ) . unwrap ( ) }
69
98
} else if watch == 1 {
70
99
let mode = if op_code == OpCode :: GetData || op_code == OpCode :: Exists {
71
100
WatchMode :: Data
72
101
} else {
73
102
WatchMode :: Child
74
103
} ;
75
- Some ( ( server_path, mode) )
104
+ OpStat :: Watch { path : server_path, mode }
76
105
} else {
77
106
assert ! ( watch == 0 ) ;
78
- None
107
+ OpStat :: Path ( server_path )
79
108
}
80
109
} ,
81
- _ => None ,
110
+ _ => OpStat :: None ,
82
111
} ;
83
- ( op_code, watcher_info )
112
+ ( op_code, stat )
84
113
}
85
114
86
115
pub fn is_empty ( & self ) -> bool {
0 commit comments