File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -68,20 +68,27 @@ impl Connection {
6868 let mut bytes = BytesMut :: new ( ) ;
6969 let mut chunk_size = 0 ;
7070 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 ?;
7472 }
7573
7674 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 ?;
8378 }
8479
8580 Ok ( BoltResponse :: parse ( self . version , bytes. freeze ( ) ) ?)
8681 }
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+ }
8794}
You can’t perform that action at this time.
0 commit comments