-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
303 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//! Low-level message sent over the wire, as defined in the specification. | ||
//! | ||
//! TODO Update this | ||
//! All of these messages are sent over a bidirectional QUIC stream. | ||
//! This introduces some head-of-line blocking but preserves ordering. | ||
//! The only exception are OBJECT "messages", which are sent over dedicated QUIC streams. | ||
//! | ||
//! Messages sent by the publisher: | ||
//! - [Announce] | ||
//! - [Unannounce] | ||
//! - [SubscribeOk] | ||
//! - [SubscribeError] | ||
//! - [SubscribeReset] | ||
//! - [Object] | ||
//! | ||
//! Messages sent by the subscriber: | ||
//! - [Subscribe] | ||
//! - [Unsubscribe] | ||
//! - [AnnounceOk] | ||
//! - [AnnounceError] | ||
//! | ||
//! Example flow: | ||
//! ```test | ||
//! -> ANNOUNCE namespace="foo" | ||
//! <- ANNOUNCE_OK namespace="foo" | ||
//! <- SUBSCRIBE id=0 namespace="foo" name="bar" | ||
//! -> SUBSCRIBE_OK id=0 | ||
//! -> OBJECT id=0 sequence=69 priority=4 expires=30 | ||
//! -> OBJECT id=0 sequence=70 priority=4 expires=30 | ||
//! -> OBJECT id=0 sequence=70 priority=4 expires=30 | ||
//! <- SUBSCRIBE_STOP id=0 | ||
//! -> SUBSCRIBE_RESET id=0 code=206 reason="closed by peer" | ||
//! ``` | ||
mod announce; | ||
mod announce_error; | ||
mod announce_ok; | ||
mod go_away; | ||
mod message; | ||
mod subscribe; | ||
mod subscribe_done; | ||
mod subscribe_error; | ||
mod subscribe_ok; | ||
mod unannounce; | ||
mod unsubscribe; | ||
|
||
pub use announce::*; | ||
pub use announce_error::*; | ||
pub use announce_ok::*; | ||
pub use go_away::*; | ||
pub use message::*; | ||
pub use subscribe::*; | ||
pub use subscribe_done::*; | ||
pub use subscribe_error::*; | ||
pub use subscribe_ok::*; | ||
pub use unannounce::*; | ||
pub use unsubscribe::*; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | ||
|
||
use crate::coding::{AsyncRead, AsyncWrite}; | ||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt}; | ||
|
||
/// Sent by the publisher to cleanly terminate a Subscribe. | ||
#[derive(Clone, Debug)] | ||
pub struct SubscribeDone { | ||
/// The ID for this subscription. | ||
pub id: VarInt, | ||
|
||
/// The error code | ||
pub code: VarInt, | ||
|
||
/// An optional error reason | ||
pub reason: String, | ||
|
||
/// The final group/object sent on this subscription. | ||
pub last: Option<(VarInt, VarInt)>, | ||
} | ||
|
||
impl SubscribeDone { | ||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> { | ||
let id = VarInt::decode(r).await?; | ||
let code = VarInt::decode(r).await?; | ||
let reason = String::decode(r).await?; | ||
let last = match r.read_u8().await? { | ||
0 => None, | ||
1 => Some((VarInt::decode(r).await?, VarInt::decode(r).await?)), | ||
_ => return Err(DecodeError::InvalidValue), | ||
}; | ||
|
||
Ok(Self { id, code, reason, last }) | ||
} | ||
|
||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> { | ||
self.id.encode(w).await?; | ||
self.code.encode(w).await?; | ||
self.reason.encode(w).await?; | ||
|
||
if let Some((group, object)) = self.last { | ||
w.write_u8(1).await?; | ||
group.encode(w).await?; | ||
object.encode(w).await?; | ||
} else { | ||
w.write_u8(0).await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::coding::{AsyncRead, AsyncWrite}; | ||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Datagram { | ||
// The subscribe ID. | ||
pub subscribe_id: VarInt, | ||
|
||
// The track alias. | ||
pub track_alias: VarInt, | ||
|
||
// The sequence number within the track. | ||
pub group_id: VarInt, | ||
|
||
// The object ID within the group. | ||
pub object_id: VarInt, | ||
|
||
// The priority, where **smaller** values are sent first. | ||
pub send_order: VarInt, | ||
} | ||
|
||
impl Datagram { | ||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> { | ||
Ok(Self { | ||
subscribe_id: VarInt::decode(r).await?, | ||
track_alias: VarInt::decode(r).await?, | ||
group_id: VarInt::decode(r).await?, | ||
object_id: VarInt::decode(r).await?, | ||
send_order: VarInt::decode(r).await?, | ||
}) | ||
} | ||
|
||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> { | ||
self.subscribe_id.encode(w).await?; | ||
self.track_alias.encode(w).await?; | ||
self.group_id.encode(w).await?; | ||
self.object_id.encode(w).await?; | ||
self.send_order.encode(w).await?; | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.