packetize/
lib.rs

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
#![feature(min_specialization)]
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

pub use packetize_derive::*;

pub trait Packet<T> {
    fn get_id(&self, state: &T) -> Option<u32>;
    fn is_changing_state(&self) -> Option<T>;
}

pub trait EncodePacket<T> {
    fn encode_packet<E: serialization::Encoder>(
        &self,
        encoder: E,
        state: &mut T,
    ) -> Result<(), E::Error>;

    fn encode_packet2<P, E: serialization::Encoder>(
        packet: P,
        encoder: E,
        state: &mut T,
    ) -> Result<(), E::Error>
    where
        P: Packet<T>,
    {
        Ok(())
    }
}

pub trait DecodePacket<T>: Sized {
    fn decode_packet<D: serialization::Decoder>(
        decoder: D,
        state: &mut T,
    ) -> Result<Self, D::Error>;
}