Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion h3-datagram/src/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
let varint = VarInt::from(self.stream_id) / 4;
varint.encode(&mut buffer.as_mut_slice());
EncodedDatagram {
stream_id: [0; VarInt::MAX_SIZE],
stream_id: buffer,
len: varint.size(),
pos: 0,
payload: self.payload,
Expand All @@ -85,6 +85,25 @@ where
}
}

#[cfg(test)]
mod tests {
use super::Datagram;
use bytes::{Buf, Bytes};
use h3::quic::StreamId;

#[test]
fn encode_preserves_quarter_stream_id() {
let stream_id = StreamId::try_from(4).unwrap();
let payload = Bytes::from_static(b"payload");

let mut encoded = Datagram::new(stream_id, payload.clone()).encode();
let decoded = Datagram::decode(encoded.copy_to_bytes(encoded.remaining())).unwrap();

assert_eq!(decoded.stream_id(), stream_id);
assert_eq!(decoded.into_payload(), payload);
}
}

#[derive(Debug)]
pub struct EncodedDatagram<B: Buf> {
/// Encoded datagram stream ID as Varint
Expand Down