moq_lite/lite/
version.rs

1use crate::coding;
2
3/// The ALPN string for the Lite protocol.
4///
5/// NOTE: The version is still negotiated via the setup message.
6/// In the future we'll use ALPN instead.
7pub const ALPN: &str = "moql";
8
9#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
10#[repr(u64)]
11pub enum Version {
12	Draft01 = 0xff0dad01,
13	Draft02 = 0xff0dad02,
14}
15
16impl TryFrom<coding::Version> for Version {
17	type Error = ();
18
19	fn try_from(value: coding::Version) -> Result<Self, Self::Error> {
20		if value == Self::Draft01.coding() {
21			Ok(Self::Draft01)
22		} else if value == Self::Draft02.coding() {
23			Ok(Self::Draft02)
24		} else {
25			Err(())
26		}
27	}
28}
29
30impl From<Version> for coding::Version {
31	fn from(value: Version) -> Self {
32		value.coding()
33	}
34}
35
36impl Version {
37	pub const fn coding(self) -> coding::Version {
38		coding::Version(self as u64)
39	}
40}