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
use crate::Context;
use std::io::Cursor;

#[derive(Debug)]
pub struct DataView {
    pub(crate) buffer: Cursor<Vec<u8>>,
    pub(crate) context: Context,
}

impl DataView {
    pub fn new(buf: &[u8], context: Context) -> Result<Self, String> {
        Ok(Self {
            buffer: Cursor::new(buf.to_vec()),
            context,
        })
    }

    pub fn get_buffer(&self) -> Vec<u8> {
        self.buffer.clone().into_inner()
    }

    pub fn context(&mut self) -> &mut Context {
        &mut self.context
    }
}