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

use netbuf;
use std::io::Read;
use std::io::Result;

mod messages;
mod parser;

pub struct FrameDecoder {
    buf: netbuf::Buf,
}

impl FrameDecoder {
    pub fn new() -> FrameDecoder {
        FrameDecoder {
            buf: netbuf::Buf::new()
        }
    }

    pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
        self.buf.read_from(stream)
    }

    pub fn extract_messages(&mut self) -> &[u8] {
        &self.buf[..]
    }
}