@@ -57,6 +57,14 @@ pub(super) struct Parser<'a> {
5757 buffer : & ' a [ u8 ] ,
5858}
5959
60+ #[ derive( Debug , PartialEq ) ]
61+ pub enum FlatElement {
62+ String ( String ) ,
63+ Binstr ( Vec < u8 > ) ,
64+ RespCode ( RespCode ) ,
65+ UnsignedInt ( u64 ) ,
66+ }
67+
6068#[ derive( Debug , PartialEq ) ]
6169#[ non_exhaustive]
6270/// # Data Types
@@ -71,8 +79,8 @@ pub enum Element {
7179 Binstr ( Vec < u8 > ) ,
7280 /// An unsigned integer value; `<tsymbol>` is `:`
7381 UnsignedInt ( u64 ) ,
74- /// A non-recursive String array; tsymbol: `_`
75- FlatArray ( Vec < Vec < u8 > > ) ,
82+ /// A non-recursive array; tsymbol: `_`
83+ FlatArray ( Vec < FlatElement > ) ,
7684 /// A response code
7785 RespCode ( RespCode ) ,
7886 /// An array of unicode strings
@@ -441,7 +449,7 @@ impl<'a> Parser<'a> {
441449 }
442450 }
443451 /// The cursor should have passed the tsymbol
444- fn parse_next_flat_array ( & mut self ) -> ParseResult < Vec < Vec < u8 > > > {
452+ fn parse_next_flat_array ( & mut self ) -> ParseResult < Vec < FlatElement > > {
445453 let ( start, stop) = self . read_line ( ) ;
446454 if let Some ( our_size_chunk) = self . buffer . get ( start..stop) {
447455 let array_size = Self :: parse_into_usize ( our_size_chunk) ?;
@@ -451,7 +459,10 @@ impl<'a> Parser<'a> {
451459 // good, there is a tsymbol; move the cursor ahead
452460 self . incr_cursor ( ) ;
453461 let ret = match * tsymbol {
454- b'+' => self . parse_next_binstr ( ) ?,
462+ b'+' => FlatElement :: String ( self . parse_next_string ( ) ?) ,
463+ b'?' => FlatElement :: Binstr ( self . parse_next_binstr ( ) ?) ,
464+ b'!' => FlatElement :: RespCode ( self . parse_next_respcode ( ) ?) ,
465+ b':' => FlatElement :: UnsignedInt ( self . parse_next_u64 ( ) ?) ,
455466 _ => return Err ( ParseError :: UnknownDatatype ) ,
456467 } ;
457468 array. push ( ret) ;
0 commit comments