rust/hedgewars-server/src/protocol/parser.rs
changeset 15127 4f31954a0b81
parent 15124 901751d3cd80
child 15129 824472aa4d97
equal deleted inserted replaced
15126:1a43b570cbe4 15127:4f31954a0b81
    11     bytes::complete::{tag, tag_no_case, take_until, take_while},
    11     bytes::complete::{tag, tag_no_case, take_until, take_while},
    12     character::complete::{newline, not_line_ending},
    12     character::complete::{newline, not_line_ending},
    13     combinator::{map, peek},
    13     combinator::{map, peek},
    14     error::{ErrorKind, ParseError},
    14     error::{ErrorKind, ParseError},
    15     multi::separated_list,
    15     multi::separated_list,
    16     sequence::{pair, preceded, terminated},
    16     sequence::{delimited, pair, preceded, terminated},
    17     Err, IResult,
    17     Err, IResult,
    18 };
    18 };
    19 
    19 
    20 use std::{
    20 use std::{
    21     num::ParseIntError,
    21     num::ParseIntError,
   456 pub fn malformed_message(input: &[u8]) -> HwResult<()> {
   456 pub fn malformed_message(input: &[u8]) -> HwResult<()> {
   457     map(terminated(take_until(&b"\n\n"[..]), end_of_message), |_| ())(input)
   457     map(terminated(take_until(&b"\n\n"[..]), end_of_message), |_| ())(input)
   458 }
   458 }
   459 
   459 
   460 pub fn message(input: &[u8]) -> HwResult<HwProtocolMessage> {
   460 pub fn message(input: &[u8]) -> HwResult<HwProtocolMessage> {
   461     preceded(
   461     delimited(
   462         take_while(|c| c == b'\n'),
   462         take_while(|c| c == b'\n'),
   463         terminated(
   463         alt((
   464             alt((
   464             no_arg_message,
   465                 no_arg_message,
   465             single_arg_message,
   466                 single_arg_message,
   466             cmd_message,
   467                 cmd_message,
   467             config_message,
   468                 config_message,
   468             server_var_message,
   469                 server_var_message,
   469             complex_message,
   470                 complex_message,
   470         )),
   471             )),
   471         end_of_message,
   472             end_of_message,
       
   473         ),
       
   474     )(input)
   472     )(input)
   475 }
   473 }
   476 
   474 
   477 #[cfg(test)]
   475 #[cfg(test)]
   478 mod test {
   476 mod test {