gameServer2/src/protocol.rs
author unc0rr
Tue, 03 Jan 2017 00:19:47 +0300
changeset 12129 07972a8c2433
permissions -rw-r--r--
- Start protocol parser implementation - Small fixes
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
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     5
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     6
pub struct FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     7
    buf: netbuf::Buf,
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     8
}
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
     9
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    10
impl FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    11
    pub fn new() -> FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    12
        FrameDecoder {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    13
            buf: netbuf::Buf::new()
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    14
        }
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
    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    18
        self.buf.read_from(stream)
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    19
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    20
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    21
    pub fn extract_messages(&mut self) -> &[u8] {
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    22
        &self.buf[..]
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    23
    }
07972a8c2433 - Start protocol parser implementation
unc0rr
parents:
diff changeset
    24
}