From 773c82ac837538da2395cc22a46eb6e07a6e9637 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Mon, 10 May 2021 10:16:49 +0530 Subject: [PATCH] Add actiongroup size parsing --- server/src/protocol/parserv2.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/src/protocol/parserv2.rs b/server/src/protocol/parserv2.rs index 01cadb31..c61f6d56 100644 --- a/server/src/protocol/parserv2.rs +++ b/server/src/protocol/parserv2.rs @@ -131,6 +131,24 @@ impl<'a> Parser<'a> { Err(ParseError::UnexpectedByte) } } + /// This will return the number of items in a datagroup + fn parse_actiongroup_size(&mut self) -> ParseResult { + // This will give us `#

\n` + let dataframe_sizeline = self.read_sizeline()?; + // Now we want to read `&\n` + let our_chunk = self.read_until(dataframe_sizeline)?; + if our_chunk[0] == b'&' { + // Good, so this is indeed a datagroup! + // Let us attempt to read the usize from this point onwards + // excluding the '&' char (so 1..) + // also push the cursor ahead + let ret = Self::parse_into_usize(&our_chunk[1..])?; + self.incr_cursor(); + Ok(ret) + } else { + Err(ParseError::UnexpectedByte) + } + } } #[test] @@ -148,3 +166,11 @@ fn test_metaframe_parse() { assert_eq!(2, parser.parse_metaframe().unwrap()); assert_eq!(parser.cursor, metaframe.len()); } + +#[test] +fn test_actiongroup_size_parse() { + let dataframe_layout = "#6\n&12345\n".as_bytes(); + let mut parser = Parser::new(&dataframe_layout); + assert_eq!(12345, parser.parse_actiongroup_size().unwrap()); + assert_eq!(parser.cursor, dataframe_layout.len()); +}