aboutsummaryrefslogtreecommitdiff
path: root/src/data_type.rs
blob: f9c97cba00e717960d9ffcdbacb09416c35efb86 (plain) (blame)
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
use std::net::{Ipv4Addr, Ipv6Addr};

pub trait DataType {
    const TYPE: u32;
    const LEN: u32;

    fn data(&self) -> Vec<u8>;
}

impl DataType for Ipv4Addr {
    const TYPE: u32 = 7;
    const LEN: u32 = 4;

    fn data(&self) -> Vec<u8> {
        self.octets().to_vec()
    }
}

impl DataType for Ipv6Addr {
    const TYPE: u32 = 8;
    const LEN: u32 = 16;

    fn data(&self) -> Vec<u8> {
        self.octets().to_vec()
    }
}

impl<const N: usize> DataType for [u8; N] {
    const TYPE: u32 = 5;
    const LEN: u32 = N as u32;

    fn data(&self) -> Vec<u8> {
        self.to_vec()
    }
}