1
- use crate :: frame:: { self , Error , Head , Kind , Reason , StreamId } ;
1
+ use std:: fmt;
2
+
3
+ use bytes:: { BufMut , Bytes } ;
2
4
3
- use bytes :: BufMut ;
5
+ use crate :: frame :: { self , Error , Head , Kind , Reason , StreamId } ;
4
6
5
- #[ derive( Debug , Clone , Copy , Eq , PartialEq ) ]
7
+ #[ derive( Clone , Eq , PartialEq ) ]
6
8
pub struct GoAway {
7
9
last_stream_id : StreamId ,
8
10
error_code : Reason ,
11
+ #[ allow( unused) ]
12
+ debug_data : Bytes ,
9
13
}
10
14
11
15
impl GoAway {
12
16
pub fn new ( last_stream_id : StreamId , reason : Reason ) -> Self {
13
17
GoAway {
14
18
last_stream_id,
15
19
error_code : reason,
20
+ debug_data : Bytes :: new ( ) ,
16
21
}
17
22
}
18
23
@@ -24,17 +29,24 @@ impl GoAway {
24
29
self . error_code
25
30
}
26
31
32
+ #[ cfg( feature = "unstable" ) ]
33
+ pub fn debug_data ( & self ) -> & [ u8 ] {
34
+ & self . debug_data
35
+ }
36
+
27
37
pub fn load ( payload : & [ u8 ] ) -> Result < GoAway , Error > {
28
38
if payload. len ( ) < 8 {
29
39
return Err ( Error :: BadFrameSize ) ;
30
40
}
31
41
32
42
let ( last_stream_id, _) = StreamId :: parse ( & payload[ ..4 ] ) ;
33
43
let error_code = unpack_octets_4 ! ( payload, 4 , u32 ) ;
44
+ let debug_data = Bytes :: from ( & payload[ 8 ..] ) ;
34
45
35
46
Ok ( GoAway {
36
47
last_stream_id,
37
48
error_code : error_code. into ( ) ,
49
+ debug_data,
38
50
} )
39
51
}
40
52
@@ -52,3 +64,17 @@ impl<B> From<GoAway> for frame::Frame<B> {
52
64
frame:: Frame :: GoAway ( src)
53
65
}
54
66
}
67
+
68
+ impl fmt:: Debug for GoAway {
69
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
70
+ let mut builder = f. debug_struct ( "GoAway" ) ;
71
+ builder. field ( "error_code" , & self . error_code ) ;
72
+ builder. field ( "last_stream_id" , & self . last_stream_id ) ;
73
+
74
+ if !self . debug_data . is_empty ( ) {
75
+ builder. field ( "debug_data" , & self . debug_data ) ;
76
+ }
77
+
78
+ builder. finish ( )
79
+ }
80
+ }
0 commit comments