From b51f49a666db402626de9fa045fd6a5b7a8ea66e Mon Sep 17 00:00:00 2001 From: Mike English Date: Sat, 2 Nov 2024 02:33:37 -0400 Subject: [PATCH] moq-transport: Add payload length to datagrams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit draft-06 change: Object Payload Length ([PR 487](https://github.com/moq-wg/moq-transport/pull/487), [§7.2](https://www.ietf.org/archive/id/draft-ietf-moq-transport-06.html#section-7.2), [§7.3](https://www.ietf.org/archive/id/draft-ietf-moq-transport-06.html#section-7.3), [§1.3](https://www.ietf.org/archive/id/draft-ietf-moq-transport-06.html#section-1.3-5.2.1)) Object stream was removed by the addition of Peeps/SubGroups, but we still have datagrams so add this length field there. --- moq-transport/src/coding/decode.rs | 3 +++ moq-transport/src/data/datagram.rs | 9 +++++++++ moq-transport/src/session/subscribed.rs | 1 + 3 files changed, 13 insertions(+) diff --git a/moq-transport/src/coding/decode.rs b/moq-transport/src/coding/decode.rs index 189f39f..2f908c0 100644 --- a/moq-transport/src/coding/decode.rs +++ b/moq-transport/src/coding/decode.rs @@ -22,6 +22,9 @@ pub enum DecodeError { #[error("fill buffer")] More(usize), + #[error("invalid payload length {0} got {1}")] + InvalidLength(usize, usize), + #[error("invalid string")] InvalidString(#[from] FromUtf8Error), diff --git a/moq-transport/src/data/datagram.rs b/moq-transport/src/data/datagram.rs index 7495254..5b74977 100644 --- a/moq-transport/src/data/datagram.rs +++ b/moq-transport/src/data/datagram.rs @@ -21,6 +21,9 @@ pub struct Datagram { // Object status pub object_status: ObjectStatus, + // The payload length. + pub payload_len: u64, + // The payload. pub payload: bytes::Bytes, } @@ -33,6 +36,10 @@ impl Decode for Datagram { let object_id = u64::decode(r)?; let publisher_priority = u8::decode(r)?; let object_status = ObjectStatus::decode(r)?; + let payload_len = u64::decode(r)?; + if payload_len != r.remaining() as u64 { + return Err(DecodeError::InvalidLength(payload_len as usize, r.remaining() as usize)); + } let payload = r.copy_to_bytes(r.remaining()); Ok(Self { @@ -42,6 +49,7 @@ impl Decode for Datagram { object_id, publisher_priority, object_status, + payload_len, payload, }) } @@ -55,6 +63,7 @@ impl Encode for Datagram { self.object_id.encode(w)?; self.publisher_priority.encode(w)?; self.object_status.encode(w)?; + self.payload_len.encode(w)?; Self::encode_remaining(w, self.payload.len())?; w.put_slice(&self.payload); diff --git a/moq-transport/src/session/subscribed.rs b/moq-transport/src/session/subscribed.rs index fcdeb59..7ae42e8 100644 --- a/moq-transport/src/session/subscribed.rs +++ b/moq-transport/src/session/subscribed.rs @@ -297,6 +297,7 @@ impl Subscribed { object_id: datagram.object_id, publisher_priority: datagram.priority, object_status: datagram.status, + payload_len: datagram.payload.len() as u64, payload: datagram.payload, };