aboutsummaryrefslogtreecommitdiff
path: root/src/field/data.rs
blob: cd1341c310f48d0a8fbebc9eb5b979376fe54cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use super::Field;
use std::io::Result;

pub struct Data {
    value: Vec<u8>,
}

impl Field for Data {
    const ID: u16 = 101;

    fn size(&self) -> [u8; 2] {
        (self.value.len() as u16).to_be_bytes()
    }

    fn serialize_data(&self) -> &Vec<u8> {
        &self.value
    }

    fn deserialize(data: &[u8]) -> Result<Self> {
        Ok(Data {
            value: data.to_owned(),
        })
    }
}