2023-07-08 16:13:29 +00:00
|
|
|
use super::{Role, Version};
|
2023-08-15 17:20:03 +00:00
|
|
|
use crate::coding::{DecodeError, EncodeError};
|
2023-07-08 16:13:29 +00:00
|
|
|
|
2023-08-15 17:20:03 +00:00
|
|
|
use webtransport_generic::{RecvStream, SendStream};
|
2023-07-08 16:13:29 +00:00
|
|
|
|
|
|
|
// Sent by the server in response to a client.
|
|
|
|
// NOTE: This is not a message type, but rather the control stream header.
|
|
|
|
// Proposal: https://github.com/moq-wg/moq-transport/issues/138
|
|
|
|
#[derive(Debug)]
|
2023-08-15 17:20:03 +00:00
|
|
|
pub struct Server {
|
2023-07-08 16:13:29 +00:00
|
|
|
// The list of supported versions in preferred order.
|
|
|
|
pub version: Version,
|
|
|
|
|
|
|
|
// param: 0x0: Indicate if the server is a publisher, a subscriber, or both.
|
|
|
|
// Proposal: moq-wg/moq-transport#151
|
|
|
|
pub role: Role,
|
|
|
|
}
|
|
|
|
|
2023-08-15 17:20:03 +00:00
|
|
|
impl Server {
|
|
|
|
pub async fn decode<R: RecvStream>(r: &mut R) -> Result<Self, DecodeError> {
|
|
|
|
let version = Version::decode(r).await?;
|
|
|
|
let role = Role::decode(r).await?;
|
2023-07-08 16:13:29 +00:00
|
|
|
|
|
|
|
Ok(Self { version, role })
|
|
|
|
}
|
|
|
|
|
2023-08-15 17:20:03 +00:00
|
|
|
pub async fn encode<W: SendStream>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
|
|
self.version.encode(w).await?;
|
|
|
|
self.role.encode(w).await?;
|
2023-07-08 16:13:29 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|