rust/hedgewars-engine-messages/src/parser.rs
changeset 14275 9f4d75fa4a2c
parent 14235 77b95406631e
child 14276 a239e4243cf9
equal deleted inserted replaced
14274:084af6d2685f 14275:9f4d75fa4a2c
    68 ));
    68 ));
    69 
    69 
    70 named!(unordered_message<&[u8], UnorderedEngineMessage>, alt!(
    70 named!(unordered_message<&[u8], UnorderedEngineMessage>, alt!(
    71       do_parse!(tag!("?") >> ( Ping ))
    71       do_parse!(tag!("?") >> ( Ping ))
    72     | do_parse!(tag!("!") >> ( Ping ))
    72     | do_parse!(tag!("!") >> ( Ping ))
       
    73     | do_parse!(tag!("E") >> s: string_tail >> ( Error(s)) )
       
    74     | do_parse!(tag!("W") >> s: string_tail >> ( Warning(s)) )
    73     | do_parse!(tag!("s") >> s: string_tail >> ( ChatMessage(s)) )
    75     | do_parse!(tag!("s") >> s: string_tail >> ( ChatMessage(s)) )
    74     | do_parse!(tag!("b") >> s: string_tail >> ( TeamMessage(s)) ) // TODO: wtf is the format
    76     | do_parse!(tag!("b") >> s: string_tail >> ( TeamMessage(s)) ) // TODO: wtf is the format
    75     | do_parse!(tag!("M") >> s: string_tail >> ( GameSetupChecksum(s)) )
    77     | do_parse!(tag!("M") >> s: string_tail >> ( GameSetupChecksum(s)) )
    76     | do_parse!(tag!("o") >> ( StopSyncing ))
    78     | do_parse!(tag!("o") >> ( StopSyncing ))
    77     | do_parse!(tag!("I") >> ( PauseToggled ))
    79     | do_parse!(tag!("I") >> ( PauseToggled ))
   136     assert_eq!(
   138     assert_eq!(
   137         message(b"\x03L\x01\x02"),
   139         message(b"\x03L\x01\x02"),
   138         Ok((&b""[..], Synced(Left(Press), 258)))
   140         Ok((&b""[..], Synced(Left(Press), 258)))
   139     );
   141     );
   140     assert_eq!(message(b"\x01#"), Ok((&b""[..], Synced(TimeWrap, 65535))));
   142     assert_eq!(message(b"\x01#"), Ok((&b""[..], Synced(TimeWrap, 65535))));
       
   143 
       
   144     assert_eq!(message(&vec![9, b'p', 255, 133, 151, 1, 0, 2, 0, 0]), Ok((&b""[..], Synced(Put(-31337, 65538), 0))));
   141 }
   145 }
   142 
   146 
   143 #[test]
   147 #[test]
   144 fn parse_unsynced_messages() {
   148 fn parse_unsynced_messages() {
   145     assert_eq!(
   149     assert_eq!(