@@ -22,6 +22,33 @@ impl<R: Read + Unpin> ChunkedEncoder<R> {
22
22
}
23
23
}
24
24
25
+ impl < R : Read + Unpin > Read for ChunkedEncoder < R > {
26
+ fn poll_read (
27
+ mut self : Pin < & mut Self > ,
28
+ cx : & mut Context < ' _ > ,
29
+ buf : & mut [ u8 ] ,
30
+ ) -> Poll < io:: Result < usize > > {
31
+ if self . done {
32
+ return Poll :: Ready ( Ok ( 0 ) ) ;
33
+ }
34
+ let reader = & mut self . reader ;
35
+
36
+ let max_bytes_to_read = max_bytes_to_read ( buf. len ( ) ) ;
37
+
38
+ let bytes = ready ! ( Pin :: new( reader) . poll_read( cx, & mut buf[ ..max_bytes_to_read] ) ) ?;
39
+ if bytes == 0 {
40
+ self . done = true ;
41
+ }
42
+ let start = format ! ( "{:X}\r \n " , bytes) ;
43
+ let start_length = start. as_bytes ( ) . len ( ) ;
44
+ let total = bytes + start_length + 2 ;
45
+ buf. copy_within ( ..bytes, start_length) ;
46
+ buf[ ..start_length] . copy_from_slice ( start. as_bytes ( ) ) ;
47
+ buf[ total - 2 ..total] . copy_from_slice ( b"\r \n " ) ;
48
+ Poll :: Ready ( Ok ( total) )
49
+ }
50
+ }
51
+
25
52
fn max_bytes_to_read ( buf_len : usize ) -> usize {
26
53
if buf_len < 6 {
27
54
// the minimum read size is of 6 represents one byte of
@@ -89,30 +116,3 @@ mod test_bytes_to_read {
89
116
}
90
117
}
91
118
}
92
-
93
- impl < R : Read + Unpin > Read for ChunkedEncoder < R > {
94
- fn poll_read (
95
- mut self : Pin < & mut Self > ,
96
- cx : & mut Context < ' _ > ,
97
- buf : & mut [ u8 ] ,
98
- ) -> Poll < io:: Result < usize > > {
99
- if self . done {
100
- return Poll :: Ready ( Ok ( 0 ) ) ;
101
- }
102
- let reader = & mut self . reader ;
103
-
104
- let max_bytes_to_read = max_bytes_to_read ( buf. len ( ) ) ;
105
-
106
- let bytes = ready ! ( Pin :: new( reader) . poll_read( cx, & mut buf[ ..max_bytes_to_read] ) ) ?;
107
- if bytes == 0 {
108
- self . done = true ;
109
- }
110
- let start = format ! ( "{:X}\r \n " , bytes) ;
111
- let start_length = start. as_bytes ( ) . len ( ) ;
112
- let total = bytes + start_length + 2 ;
113
- buf. copy_within ( ..bytes, start_length) ;
114
- buf[ ..start_length] . copy_from_slice ( start. as_bytes ( ) ) ;
115
- buf[ total - 2 ..total] . copy_from_slice ( b"\r \n " ) ;
116
- Poll :: Ready ( Ok ( total) )
117
- }
118
- }
0 commit comments