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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use std::marker::PhantomData;
use euclid::default::Vector3D;

pub type Angle = euclid::Angle<f32>;
pub type BlockPosition = Vector3D<i32>;

pub struct ProtocolJson<T> {
    pub value: T,
}

pub struct ProtocolNbt<T> {
    pub value: T,
}

pub struct RemainingBytesArray<T> {
    pub value: Vec<T>,
}

impl<T> RemainingBytesArray<T> {
    pub fn new(value: Vec<T>) -> Self {
        Self { value }
    }

    pub fn get(&self) -> &Vec<T> {
        &self.value
    }
}

impl<T> From<Vec<T>> for RemainingBytesArray<T> {
    fn from(value: Vec<T>) -> Self {
        RemainingBytesArray::new(value)
    }
}

impl<T> From<RemainingBytesArray<T>> for Vec<T> {
    fn from(array: RemainingBytesArray<T>) -> Self {
        array.value
    }
}

pub struct LengthProvidedArray<T, S> {
    pub value: Vec<T>,
    size: PhantomData<S>,
}

impl<T, S> LengthProvidedArray<T, S> {
    pub fn new(value: Vec<T>) -> Self {
        Self { value, size: PhantomData }
    }

    pub fn get(&self) -> &Vec<T> {
        &self.value
    }
}

impl<T, S> From<Vec<T>> for LengthProvidedArray<T, S> {
    fn from(value: Vec<T>) -> Self {
        LengthProvidedArray::new(value)
    }
}

impl<T, S> From<LengthProvidedArray<T, S>> for Vec<T> {
    fn from(array: LengthProvidedArray<T, S>) -> Self {
        array.value
    }
}

impl<T> ProtocolJson<T> {
    pub fn new(value: T) -> Self {
        Self { value }
    }

    pub fn get(&self) -> &T {
        &self.value
    }

    pub fn into(self) -> T {
        self.value
    }
}

impl<T> From<T> for ProtocolJson<T> {
    fn from(val: T) -> Self {
        ProtocolJson::new(val)
    }
}

impl<T> ProtocolNbt<T> {
    pub fn new(value: T) -> Self {
        Self { value }
    }

    pub fn get(&self) -> &T {
        &self.value
    }

    pub fn int(self) -> T {
        self.value
    }
}

macro_rules! container_type {
    ($name: ident, $contained: ty) => {
        #[derive(Debug, Copy, Clone)]
        pub struct $name(pub $contained);

        impl From<$name> for $contained {
            fn from(value: $name) -> Self {
                value.0
            }
        }

        impl From<$contained> for $name {
            fn from(value: $contained) -> Self {
                $name(value)
            }
        }
    }
}

container_type!(VarInt, i32);
container_type!(VarLong, i64);