1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use bitbuffer::{BitReadBuffer, BitReadStream, LittleEndian};

pub mod data;
pub mod gameevent_gen;
pub mod gamevent;
pub mod header;
pub mod lzss;
pub mod message;
pub mod packet;
pub mod parser;
pub mod sendprop;
mod sendprop_gen;
pub mod vector;

pub type Buffer<'a> = BitReadBuffer<'a, LittleEndian>;
pub type Stream<'a> = BitReadStream<'a, LittleEndian>;

pub struct Demo<'a> {
    stream: Stream<'a>,
}

impl<'a> Demo<'a> {
    pub fn new(bytes: &'a [u8]) -> Self {
        let data = Buffer::new(bytes, LittleEndian);
        let stream = Stream::new(data);
        Demo { stream }
    }

    /// Get a new stream with the data of the demo
    pub fn get_stream(&self) -> Stream<'a> {
        self.stream.clone()
    }
}

impl Demo<'static> {
    pub fn owned(bytes: Vec<u8>) -> Self {
        let data = Buffer::new_owned(bytes, LittleEndian);
        let stream = Stream::new(data);
        Demo { stream }
    }
}