Don't raise error if there is more data

next
Sayan Nandan 3 years ago
parent c9b2abfc96
commit 4265820fbd

@ -268,20 +268,15 @@ pub fn parse(buf: &[u8]) -> ParseResult {
} }
} }
} }
if buf.get(pos).is_none() {
// Either more data was sent or some data was missing
if items.len() == action_size { if items.len() == action_size {
if items.len() == 1 { if items.len() == 1 {
ParseResult::Query(Query::Simple(items.remove(0)), buf.len()) ParseResult::Query(Query::Simple(items.remove(0)), pos)
} else { } else {
ParseResult::Query(Query::Pipelined(items), buf.len()) ParseResult::Query(Query::Pipelined(items), pos)
} }
} else { } else {
ParseResult::Incomplete ParseResult::Incomplete
} }
} else {
ParseResult::BadPacket(buf.len())
}
} }
/// Read a size line and return the following line /// Read a size line and return the following line
/// ///
@ -386,7 +381,7 @@ fn test_parser() {
input.len(), input.len(),
); );
assert_eq!(res, res_should_be); assert_eq!(res, res_should_be);
let input = "#2\n*2\n#2\n&3\n#3\nGET\n#1\nx\n#2\nex\n#2\n&3\n#3\nSET\n#1\nx\n#4\ntrue" let input = "#2\n*2\n#2\n&3\n#3\nGET\n#1\nx\n#2\nex\n#2\n&3\n#3\nSET\n#1\nx\n#4\ntrue\n"
.as_bytes() .as_bytes()
.to_owned(); .to_owned();
let res = parse(&input); let res = parse(&input);

Loading…
Cancel
Save