@@ -55,6 +55,17 @@ pub struct OpenResponse {
5555 pub connection_properties : HashMap < String , String > ,
5656}
5757
58+ impl OpenResponse {
59+ /// Get a reference to the generic response's code.
60+ pub fn code ( & self ) -> & ResponseCode {
61+ & self . code
62+ }
63+
64+ pub fn is_ok ( & self ) -> bool {
65+ self . code == ResponseCode :: Ok
66+ }
67+ }
68+
5869impl OpenResponse {
5970 /// Get a reference to the open response's connection properties.
6071 pub fn connection_properties ( & self ) -> & HashMap < String , String > {
@@ -75,7 +86,12 @@ impl Decoder for OpenResponse {
7586 fn decode ( input : & [ u8 ] ) -> Result < ( & [ u8 ] , Self ) , DecodeError > {
7687 let ( input, correlation_id) = u32:: decode ( input) ?;
7788 let ( input, response_code) = ResponseCode :: decode ( input) ?;
78- let ( input, connection_properties) = HashMap :: decode ( input) ?;
89+
90+ let ( input, connection_properties) = if response_code == ResponseCode :: Ok {
91+ HashMap :: decode ( input) ?
92+ } else {
93+ ( input, HashMap :: new ( ) )
94+ } ;
7995
8096 Ok ( (
8197 input,
@@ -106,10 +122,16 @@ impl Decoder for OpenCommand {
106122#[ cfg( test) ]
107123mod tests {
108124
125+ use fake:: { Fake , Faker } ;
126+
109127 use super :: OpenCommand ;
110128 use crate :: {
111129 codec:: Encoder ,
112- commands:: { open:: OpenResponse , tests:: command_encode_decode_test} ,
130+ commands:: {
131+ open:: OpenResponse ,
132+ tests:: { command_encode_decode_test, specific_command_encode_decode_test} ,
133+ } ,
134+ ResponseCode ,
113135 } ;
114136
115137 #[ test]
@@ -135,6 +157,8 @@ mod tests {
135157
136158 #[ test]
137159 fn open_response_test ( ) {
138- command_encode_decode_test :: < OpenResponse > ( ) ;
160+ let mut response: OpenResponse = Faker . fake ( ) ;
161+ response. code = ResponseCode :: Ok ;
162+ specific_command_encode_decode_test ( response) ;
139163 }
140164}
0 commit comments