@@ -192,6 +192,17 @@ pub struct ElementReader<R> {
192192 ctx : ElementReaderContext ,
193193}
194194
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+
195206impl < R > ElementReader < R >
196207where
197208 R : Read ,
@@ -262,11 +273,7 @@ where
262273 return self . next_master ( ) ;
263274 }
264275
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 ) ?;
270277
271278 let Some ( ( _, child) ) = current_master
272279 . children
@@ -295,7 +302,7 @@ where
295302 }
296303
297304 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 ( ) ) ?;
299306 Ok ( ( ) )
300307 }
301308
@@ -307,8 +314,7 @@ where
307314 }
308315
309316 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 ..] ) ?;
312318 let value = u64:: from_be_bytes ( buf) ;
313319
314320 // Signed Integers are stored with two's complement notation with the leftmost bit being the sign bit.
@@ -325,8 +331,7 @@ where
325331 }
326332
327333 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 ..] ) ?;
330335 Ok ( u64:: from_be_bytes ( buf) )
331336 }
332337
@@ -336,8 +341,8 @@ where
336341 // four octets (32 bit), or eight octets (64 bit)
337342 Ok ( match element_length {
338343 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 > ( ) ?,
341346 _ => decode_err ! ( @BAIL Ebml , "Invalid size for float element" ) ,
342347 } )
343348 }
@@ -346,7 +351,7 @@ where
346351 // https://www.rfc-editor.org/rfc/rfc8794.html#section-7.4
347352 // A String Element MUST declare a length in octets from zero to VINTMAX
348353 let mut content = try_vec ! [ 0 ; element_length as usize ] ;
349- self . reader . read_exact ( & mut content) ?;
354+ self . read_exact ( & mut content) ?;
350355
351356 // https://www.rfc-editor.org/rfc/rfc8794.html#section-13
352357 // Null Octets, which are octets with all bits set to zero,
0 commit comments