moq_lite/lite/
stream.rs

1use crate::coding::*;
2
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4
5#[derive(Debug, PartialEq, Clone, Copy, IntoPrimitive, TryFromPrimitive)]
6#[repr(u64)]
7pub enum ControlType {
8	Session = 0,
9	Announce = 1,
10	Subscribe = 2,
11}
12
13impl<V> Decode<V> for ControlType {
14	fn decode<R: bytes::Buf>(r: &mut R, version: V) -> Result<Self, DecodeError> {
15		let t = u64::decode(r, version)?;
16		t.try_into().map_err(|_| DecodeError::InvalidValue)
17	}
18}
19
20impl<V> Encode<V> for ControlType {
21	fn encode<W: bytes::BufMut>(&self, w: &mut W, version: V) {
22		let v: u64 = (*self).into();
23		v.encode(w, version)
24	}
25}
26
27#[derive(Debug, PartialEq, Clone, Copy, IntoPrimitive, TryFromPrimitive)]
28#[repr(u64)]
29pub enum DataType {
30	Group = 0,
31}
32
33impl<V> Decode<V> for DataType {
34	fn decode<R: bytes::Buf>(r: &mut R, version: V) -> Result<Self, DecodeError> {
35		let t = u64::decode(r, version)?;
36		t.try_into().map_err(|_| DecodeError::InvalidValue)
37	}
38}
39
40impl<V> Encode<V> for DataType {
41	fn encode<W: bytes::BufMut>(&self, w: &mut W, version: V) {
42		let v: u64 = (*self).into();
43		v.encode(w, version)
44	}
45}