Skip to content

Commit bf9833d

Browse files
committed
Fix FlatArray impl
1 parent 87462db commit bf9833d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/actions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//!
3838
//! ```
3939
40+
use crate::deserializer::FlatElement;
4041
use crate::types::Array;
4142
use crate::types::SnapshotResult;
4243
use crate::types::Str;
@@ -187,7 +188,7 @@ implement_actions!(
187188
/// Returns a vector of keys
188189
///
189190
/// Do note that the order might be completely meaningless
190-
fn lskeys(count: usize) -> Vec<Vec<u8>> {
191+
fn lskeys(count: usize) -> Vec<FlatElement> {
191192
{ Query::from("lskeys").arg(count)}
192193
Response::Item(Element::FlatArray(arr)) => arr
193194
}

src/deserializer.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)