File tree 1 file changed +16
-9
lines changed
1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -68,20 +68,27 @@ impl Connection {
68
68
let mut bytes = BytesMut :: new ( ) ;
69
69
let mut chunk_size = 0 ;
70
70
while chunk_size == 0 {
71
- let mut data = [ 0 , 0 ] ;
72
- self . stream . read_exact ( & mut data) . await ?;
73
- chunk_size = u16:: from_be_bytes ( data) ;
71
+ chunk_size = self . read_u16 ( ) . await ?;
74
72
}
75
73
76
74
while chunk_size > 0 {
77
- let mut buf = vec ! [ 0 ; chunk_size as usize ] ;
78
- self . stream . read_exact ( & mut buf) . await ?;
79
- bytes. put_slice ( & buf) ;
80
- let mut data = [ 0 , 0 ] ;
81
- self . stream . read_exact ( & mut data) . await ?;
82
- chunk_size = u16:: from_be_bytes ( data) ;
75
+ let chunk = self . read ( chunk_size) . await ?;
76
+ bytes. put_slice ( & chunk) ;
77
+ chunk_size = self . read_u16 ( ) . await ?;
83
78
}
84
79
85
80
Ok ( BoltResponse :: parse ( self . version , bytes. freeze ( ) ) ?)
86
81
}
82
+
83
+ async fn read ( & mut self , size : u16 ) -> Result < Vec < u8 > > {
84
+ let mut buf = vec ! [ 0 ; size as usize ] ;
85
+ self . stream . read_exact ( & mut buf) . await ?;
86
+ Ok ( buf)
87
+ }
88
+
89
+ async fn read_u16 ( & mut self ) -> Result < u16 > {
90
+ let mut data = [ 0 , 0 ] ;
91
+ self . stream . read_exact ( & mut data) . await ?;
92
+ Ok ( u16:: from_be_bytes ( data) )
93
+ }
87
94
}
You can’t perform that action at this time.
0 commit comments