gameServer2/src/protocol/mod.rs
author unc0rr
Thu, 05 Jan 2017 19:07:01 +0300
changeset 12130 6273f89ab13d
parent 12129 gameServer2/src/protocol.rs@07972a8c2433
child 12131 a4d22f197bd2
permissions -rw-r--r--
Start on messages parser
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;
6273f89ab13d Start on messages parser
unc0rr
parents: 12129
diff changeset
     6
mod hwprotocol;
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
}