rust/hedgewars-network-protocol/src/parser.rs
changeset 15830 ea459da15b30
parent 15811 a855f32ab3ca
child 15982 cf580d9ff7ef
equal deleted inserted replaced
15829:d5e6c8c92d87 15830:ea459da15b30
    21     num::ParseIntError,
    21     num::ParseIntError,
    22     str,
    22     str,
    23     str::{FromStr, Utf8Error},
    23     str::{FromStr, Utf8Error},
    24 };
    24 };
    25 
    25 
    26 use crate::messages::{HwProtocolMessage, HwProtocolMessage::*, HwServerMessage};
    26 use crate::{
    27 use crate::types::{GameCfg, HedgehogInfo, ServerVar, TeamInfo, VoteType};
    27     messages::{HwProtocolMessage, HwProtocolMessage::*, HwServerMessage},
       
    28     types::{GameCfg, HedgehogInfo, ServerVar, TeamInfo, VoteType},
       
    29 };
    28 
    30 
    29 #[derive(Debug, PartialEq)]
    31 #[derive(Debug, PartialEq)]
    30 pub struct HwProtocolError {}
    32 pub struct HwProtocolError {}
    31 
    33 
    32 impl HwProtocolError {
    34 impl HwProtocolError {
   491                     map(peek(end_of_message), |_| None),
   493                     map(peek(end_of_message), |_| None),
   492                     map(preceded(newline, separated_list0(newline, a_line)), Some),
   494                     map(preceded(newline, separated_list0(newline, a_line)), Some),
   493                 )),
   495                 )),
   494             ),
   496             ),
   495             |values| CheckedOk(values.unwrap_or_default()),
   497             |values| CheckedOk(values.unwrap_or_default()),
   496         )
   498         ),
   497 ))(input)
   499     ))(input)
   498 }
   500 }
   499 
   501 
   500 pub fn malformed_message(input: &[u8]) -> HwResult<()> {
   502 pub fn malformed_message(input: &[u8]) -> HwResult<()> {
   501     map(terminated(take_until(&b"\n\n"[..]), end_of_message), |_| ())(input)
   503     map(terminated(take_until(&b"\n\n"[..]), end_of_message), |_| ())(input)
   502 }
   504 }