File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 11use crate :: ebml:: vint:: VInt ;
22use crate :: error:: Result ;
3- use crate :: macros:: decode_err;
3+ use crate :: macros:: { decode_err, try_vec } ;
44
55use std:: io:: Read ;
66
@@ -342,8 +342,21 @@ where
342342 } )
343343 }
344344
345- pub ( crate ) fn read_string ( & mut self ) -> Result < String > {
346- todo ! ( )
345+ pub ( crate ) fn read_string ( & mut self , element_length : u64 ) -> Result < String > {
346+ // https://www.rfc-editor.org/rfc/rfc8794.html#section-7.4
347+ // A String Element MUST declare a length in octets from zero to VINTMAX
348+ let mut content = try_vec ! [ 0 ; element_length as usize ] ;
349+ self . reader . read_exact ( & mut content) ?;
350+
351+ // https://www.rfc-editor.org/rfc/rfc8794.html#section-13
352+ // Null Octets, which are octets with all bits set to zero,
353+ // MAY follow the value of a String Element or UTF-8 Element to serve as a terminator.
354+ if let Some ( i) = content. iter ( ) . rposition ( |x| * x != 0 ) {
355+ let new_len = i + 1 ;
356+ content. truncate ( new_len) ;
357+ }
358+
359+ String :: from_utf8 ( content) . map_err ( Into :: into)
347360 }
348361
349362 pub ( crate ) fn read_utf8 ( & mut self ) -> Result < String > {
Original file line number Diff line number Diff line change @@ -119,7 +119,9 @@ where
119119 ElementIdent :: EBMLReadVersion => {
120120 properties. header . read_version = element_reader. read_unsigned_int ( size) ?
121121 } ,
122- ElementIdent :: DocType => properties. header . doc_type = element_reader. read_string ( ) ?,
122+ ElementIdent :: DocType => {
123+ properties. header . doc_type = element_reader. read_string ( size) ?
124+ } ,
123125 ElementIdent :: DocTypeVersion => {
124126 properties. header . doc_type_version = element_reader. read_unsigned_int ( size) ?
125127 } ,
You can’t perform that action at this time.
0 commit comments