gameServer2/src/protocol/mod.rs
author unc0rr
Sat, 07 Jan 2017 21:34:00 +0300
changeset 12132 1525923cd7e3
parent 12131 a4d22f197bd2
child 12133 81df2e1f9ae9
permissions -rw-r--r--
Give up on lalrpop, let's try nom
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12129
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     1
use netbuf;
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     2
use std::io::Read;
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     3
use std::io::Result;
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     4
12130
6273f89ab13d Start on messages parser
unc0rr
parents: 12129
diff changeset
     5
mod messages;
12129
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     6
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     7
pub struct FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     8
    buf: netbuf::Buf,
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     9
}
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    10
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    11
impl FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    12
    pub fn new() -> FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    13
        FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    14
            buf: netbuf::Buf::new()
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    15
        }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    16
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    17
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    18
    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    19
        self.buf.read_from(stream)
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    20
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    21
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    22
    pub fn extract_messages(&mut self) -> &[u8] {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    23
        &self.buf[..]
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    24
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    25
}