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 1
1
use crate :: ebml:: vint:: VInt ;
2
2
use crate :: error:: Result ;
3
- use crate :: macros:: decode_err;
3
+ use crate :: macros:: { decode_err, try_vec } ;
4
4
5
5
use std:: io:: Read ;
6
6
@@ -342,8 +342,21 @@ where
342
342
} )
343
343
}
344
344
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)
347
360
}
348
361
349
362
pub ( crate ) fn read_utf8 ( & mut self ) -> Result < String > {
Original file line number Diff line number Diff line change @@ -119,7 +119,9 @@ where
119
119
ElementIdent :: EBMLReadVersion => {
120
120
properties. header . read_version = element_reader. read_unsigned_int ( size) ?
121
121
} ,
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
+ } ,
123
125
ElementIdent :: DocTypeVersion => {
124
126
properties. header . doc_type_version = element_reader. read_unsigned_int ( size) ?
125
127
} ,
You can’t perform that action at this time.
0 commit comments