moq_transfork/message/
setup.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use super::{Extensions, Version, Versions};
use crate::coding::*;

/// Sent by the client to setup the session.
#[derive(Debug, Clone)]
pub struct ClientSetup {
	/// The list of supported versions in preferred order.
	pub versions: Versions,

	/// Extensions.
	pub extensions: Extensions,
}

impl Decode for ClientSetup {
	/// Decode a client setup message.
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let versions = Versions::decode(r)?;
		let extensions = Extensions::decode(r)?;

		Ok(Self { versions, extensions })
	}
}

impl Encode for ClientSetup {
	/// Encode a server setup message.
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		self.versions.encode(w);
		self.extensions.encode(w);
	}
}

/// Sent by the server in response to a client setup.
#[derive(Debug, Clone)]
pub struct ServerSetup {
	/// The list of supported versions in preferred order.
	pub version: Version,

	/// Supported extenisions.
	pub extensions: Extensions,
}

impl Decode for ServerSetup {
	/// Decode the server setup.
	fn decode<R: bytes::Buf>(r: &mut R) -> Result<Self, DecodeError> {
		let version = Version::decode(r)?;
		let extensions = Extensions::decode(r)?;

		Ok(Self { version, extensions })
	}
}

impl Encode for ServerSetup {
	fn encode<W: bytes::BufMut>(&self, w: &mut W) {
		self.version.encode(w);
		self.extensions.encode(w);
	}
}