@@ -192,6 +192,17 @@ pub struct ElementReader<R> {
192
192
ctx : ElementReaderContext ,
193
193
}
194
194
195
+ impl < R > Read for ElementReader < R >
196
+ where
197
+ R : Read ,
198
+ {
199
+ fn read ( & mut self , buf : & mut [ u8 ] ) -> std:: io:: Result < usize > {
200
+ let ret = self . reader . read ( buf) ?;
201
+ self . ctx . master_length = self . ctx . master_length . saturating_sub ( ret as u64 ) ;
202
+ Ok ( ret)
203
+ }
204
+ }
205
+
195
206
impl < R > ElementReader < R >
196
207
where
197
208
R : Read ,
@@ -262,11 +273,7 @@ where
262
273
return self . next_master ( ) ;
263
274
}
264
275
265
- let header = ElementHeader :: read (
266
- & mut self . reader ,
267
- self . ctx . max_id_length ,
268
- self . ctx . max_size_length ,
269
- ) ?;
276
+ let header = ElementHeader :: read ( self , self . ctx . max_id_length , self . ctx . max_size_length ) ?;
270
277
271
278
let Some ( ( _, child) ) = current_master
272
279
. children
@@ -295,7 +302,7 @@ where
295
302
}
296
303
297
304
pub ( crate ) fn skip ( & mut self , length : u64 ) -> Result < ( ) > {
298
- std:: io:: copy ( & mut self . reader . by_ref ( ) . take ( length) , & mut std:: io:: sink ( ) ) ?;
305
+ std:: io:: copy ( & mut self . by_ref ( ) . take ( length) , & mut std:: io:: sink ( ) ) ?;
299
306
Ok ( ( ) )
300
307
}
301
308
@@ -307,8 +314,7 @@ where
307
314
}
308
315
309
316
let mut buf = [ 0 ; 8 ] ;
310
- self . reader
311
- . read_exact ( & mut buf[ 8 - element_length as usize ..] ) ?;
317
+ self . read_exact ( & mut buf[ 8 - element_length as usize ..] ) ?;
312
318
let value = u64:: from_be_bytes ( buf) ;
313
319
314
320
// Signed Integers are stored with two's complement notation with the leftmost bit being the sign bit.
@@ -325,8 +331,7 @@ where
325
331
}
326
332
327
333
let mut buf = [ 0 ; 8 ] ;
328
- self . reader
329
- . read_exact ( & mut buf[ 8 - element_length as usize ..] ) ?;
334
+ self . read_exact ( & mut buf[ 8 - element_length as usize ..] ) ?;
330
335
Ok ( u64:: from_be_bytes ( buf) )
331
336
}
332
337
@@ -336,8 +341,8 @@ where
336
341
// four octets (32 bit), or eight octets (64 bit)
337
342
Ok ( match element_length {
338
343
0 => 0.0 ,
339
- 4 => f64:: from ( self . reader . read_f32 :: < BigEndian > ( ) ?) ,
340
- 8 => self . reader . read_f64 :: < BigEndian > ( ) ?,
344
+ 4 => f64:: from ( self . read_f32 :: < BigEndian > ( ) ?) ,
345
+ 8 => self . read_f64 :: < BigEndian > ( ) ?,
341
346
_ => decode_err ! ( @BAIL Ebml , "Invalid size for float element" ) ,
342
347
} )
343
348
}
@@ -346,7 +351,7 @@ where
346
351
// https://www.rfc-editor.org/rfc/rfc8794.html#section-7.4
347
352
// A String Element MUST declare a length in octets from zero to VINTMAX
348
353
let mut content = try_vec ! [ 0 ; element_length as usize ] ;
349
- self . reader . read_exact ( & mut content) ?;
354
+ self . read_exact ( & mut content) ?;
350
355
351
356
// https://www.rfc-editor.org/rfc/rfc8794.html#section-13
352
357
// Null Octets, which are octets with all bits set to zero,
0 commit comments