# HG changeset patch # User alfadur # Date 1711314253 -10800 # Node ID 7c8697fa019ffe5823e00011adf0dbfca906f6c2 # Parent 19927b70588cebf3b381c74f2252545015454cfc fix protocol recovery diff -r 19927b70588c -r 7c8697fa019f rust/hedgewars-network-protocol/src/parser.rs --- a/rust/hedgewars-network-protocol/src/parser.rs Sun Mar 24 14:34:27 2024 -0400 +++ b/rust/hedgewars-network-protocol/src/parser.rs Mon Mar 25 00:04:13 2024 +0300 @@ -8,13 +8,13 @@ */ use nom::{ branch::alt, - bytes::complete::{tag, tag_no_case, take_until, take_while}, - character::complete::{newline, not_line_ending}, + bytes::streaming::{tag, tag_no_case, take_until, take_while}, + character::streaming::{newline, not_line_ending}, combinator::{map, peek}, error::{ErrorKind, ParseError}, multi::separated_list0, sequence::{delimited, pair, preceded, terminated, tuple}, - Err, IResult, Parser + Err, IResult, Parser, }; use std::{ @@ -214,7 +214,7 @@ ) -> impl FnMut(&'a [u8]) -> HwResult + '_ where F: Parser<&'a [u8], T, HwProtocolError> + 'a, - G: FnMut(T) -> HwProtocolMessage + 'a + G: FnMut(T) -> HwProtocolMessage + 'a, { map(preceded(tag(name), parser), constructor) } diff -r 19927b70588c -r 7c8697fa019f rust/hedgewars-network-protocol/src/tests/parser.rs --- a/rust/hedgewars-network-protocol/src/tests/parser.rs Sun Mar 24 14:34:27 2024 -0400 +++ b/rust/hedgewars-network-protocol/src/tests/parser.rs Mon Mar 25 00:04:13 2024 +0300 @@ -1,12 +1,22 @@ use crate::{ parser::HwProtocolError, - parser::{message, server_message}, + parser::{malformed_message, message, server_message}, types::GameCfg, }; #[test] fn parse_test() { use crate::messages::HwProtocolMessage::*; + use nom::Err::Incomplete; + + assert!(matches!( + dbg!(message(b"CHAT\nWhat the")), + Err(Incomplete(_)) + )); + assert!(matches!( + dbg!(malformed_message(b"CHAT\nWhat the \xF0\x9F\xA6\x94\n\nBYE")), + Ok((b"BYE", _)) + )); assert_eq!(message(b"PING\n\n"), Ok((&b""[..], Ping))); assert_eq!(message(b"START_GAME\n\n"), Ok((&b""[..], StartGame)));