From 5011ff1f9f73247ec125b9d9f15fc5b92a2f9eda Mon Sep 17 00:00:00 2001 From: Mike English Date: Sat, 2 Nov 2024 03:17:43 -0400 Subject: [PATCH] moq-transport: Add lengths to control messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit draft-06 change See: [PR 520](https://github.com/moq-wg/moq-transport/pull/520), [§6](https://www.ietf.org/archive/id/draft-ietf-moq-transport-06.html#section-6), [§1.3](https://www.ietf.org/archive/id/draft-ietf-moq-transport-06.html#section-1.3-5.2.1) --- moq-transport/src/message/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/moq-transport/src/message/mod.rs b/moq-transport/src/message/mod.rs index 405ba21..13524a5 100644 --- a/moq-transport/src/message/mod.rs +++ b/moq-transport/src/message/mod.rs @@ -86,6 +86,9 @@ macro_rules! message_types { impl Decode for Message { fn decode(r: &mut R) -> Result { let t = u64::decode(r)?; + let _len = u64::decode(r)?; + + // TODO: Check the length of the message. match t { $($val => { @@ -102,7 +105,18 @@ macro_rules! message_types { match self { $(Self::$name(ref m) => { self.id().encode(w)?; - m.encode(w) + + // Find out the length of the message + // by encoding it into a buffer and then encoding the length. + // This is a bit wasteful, but it's the only way to know the length. + let mut buf = Vec::new(); + m.encode(&mut buf).unwrap(); + (buf.len() as u64).encode(w)?; + + // At least don't encode the message twice. + // Instead, write the buffer directly to the writer. + w.put_slice(&buf); + Ok(()) },)* } }