gameServer2/src/protocol/mod.rs
author unc0rr
Sun, 08 Jan 2017 23:57:45 +0300
changeset 12133 81df2e1f9ae9
parent 12132 1525923cd7e3
child 12136 e25a82ce2374
permissions -rw-r--r--
Some parsing using 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;
12133
81df2e1f9ae9 Some parsing using nom
unc0rr
parents: 12132
diff changeset
     6
mod parser;
12129
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     7
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     8
pub struct FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     9
    buf: netbuf::Buf,
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    10
}
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    11
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    12
impl FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    13
    pub fn new() -> FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    14
        FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    15
            buf: netbuf::Buf::new()
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
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    19
    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    20
        self.buf.read_from(stream)
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    21
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    22
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    23
    pub fn extract_messages(&mut self) -> &[u8] {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    24
        &self.buf[..]
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    25
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    26
}