@@ -65,8 +65,10 @@ pub(super) struct Parser<'a> {
6565pub enum Element {
6666 /// Arrays can be nested! Their `<tsymbol>` is `&`
6767 Array ( Vec < Element > ) ,
68- /// A binary/unicode string value; `<tsymbol>` is `+`
69- String ( Vec < u8 > ) ,
68+ /// An unicode string value; `<tsymbol>` is `+`
69+ Str ( String ) ,
70+ /// A binary string (`?`)
71+ Binstr ( Vec < u8 > ) ,
7072 /// An unsigned integer value; `<tsymbol>` is `:`
7173 UnsignedInt ( u64 ) ,
7274 /// A non-recursive String array; tsymbol: `_`
@@ -279,20 +281,23 @@ impl<'a> Parser<'a> {
279281 Err ( ParseError :: NotEnough )
280282 }
281283 }
282- /// The cursor should have passed the `+` tsymbol
283- fn parse_next_string ( & mut self ) -> ParseResult < Vec < u8 > > {
284- let our_string_chunk = self . __get_next_element ( ) ?;
285- let our_string = Vec :: from ( our_string_chunk) ;
284+ /// The cursor should have passed the `?` tsymbol
285+ fn parse_next_binstr ( & mut self ) -> ParseResult < Vec < u8 > > {
286+ let our_string_chunk = self . __get_next_element ( ) ?. to_owned ( ) ;
286287 if self . will_cursor_give_linefeed ( ) ? {
287- // there is a lf after the end of the string; great!
288+ // there is a lf after the end of the binary string; great!
288289 // let's skip that now
289290 self . incr_cursor ( ) ;
290291 // let's return our string
291- Ok ( our_string )
292+ Ok ( our_string_chunk )
292293 } else {
293294 Err ( ParseError :: UnexpectedByte )
294295 }
295296 }
297+ /// The cursor should have passed the `+` tsymbol
298+ fn parse_next_string ( & mut self ) -> ParseResult < String > {
299+ Ok ( String :: from_utf8_lossy ( & self . parse_next_binstr ( ) ?) . to_string ( ) )
300+ }
296301 /// The cursor should have passed the `:` tsymbol
297302 fn parse_next_u64 ( & mut self ) -> ParseResult < u64 > {
298303 let our_u64_chunk = self . __get_next_element ( ) ?;
@@ -323,7 +328,8 @@ impl<'a> Parser<'a> {
323328 // but advance the cursor before doing that
324329 self . incr_cursor ( ) ;
325330 let ret = match * tsymbol {
326- b'+' => Element :: String ( self . parse_next_string ( ) ?) ,
331+ b'?' => Element :: Binstr ( self . parse_next_binstr ( ) ?) ,
332+ b'+' => Element :: Str ( self . parse_next_string ( ) ?) ,
327333 b':' => Element :: UnsignedInt ( self . parse_next_u64 ( ) ?) ,
328334 b'&' => Element :: Array ( self . parse_next_array ( ) ?) ,
329335 b'!' => Element :: RespCode ( self . parse_next_respcode ( ) ?) ,
@@ -347,7 +353,7 @@ impl<'a> Parser<'a> {
347353 // good, there is a tsymbol; move the cursor ahead
348354 self . incr_cursor ( ) ;
349355 let ret = match * tsymbol {
350- b'+' => self . parse_next_string ( ) ?,
356+ b'+' => self . parse_next_binstr ( ) ?,
351357 _ => return Err ( ParseError :: UnknownDatatype ) ,
352358 } ;
353359 array. push ( ret) ;
0 commit comments