Skip to content

Commit

Permalink
moq-transport: Add payload length to datagrams
Browse files Browse the repository at this point in the history
draft-06 change:

Object Payload Length ([PR 487](moq-wg/moq-transport#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.
  • Loading branch information
englishm committed Nov 2, 2024
1 parent 11c8e8b commit b51f49a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moq-transport/src/coding/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
9 changes: 9 additions & 0 deletions moq-transport/src/data/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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));

Check failure on line 41 in moq-transport/src/data/datagram.rs

View workflow job for this annotation

GitHub Actions / build

casting to the same type is unnecessary (`usize` -> `usize`)
}
let payload = r.copy_to_bytes(r.remaining());

Ok(Self {
Expand All @@ -42,6 +49,7 @@ impl Decode for Datagram {
object_id,
publisher_priority,
object_status,
payload_len,
payload,
})
}
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions moq-transport/src/session/subscribed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit b51f49a

Please sign in to comment.