Skip to content

Commit 969ece9

Browse files
flubdivagant-martian
authored andcommitted
Encode/decode PathId as VarInt
1 parent 02a2854 commit 969ece9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

quinn-proto/src/connection/paths.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use super::{
99
};
1010
use crate::{
1111
coding, congestion, frame::ObservedAddr, packet::SpaceId, Duration, Instant, TransportConfig,
12-
TIMER_GRANULARITY,
12+
VarInt, TIMER_GRANULARITY,
1313
};
1414

1515
/// Id representing different paths when using multipath extension
@@ -19,13 +19,15 @@ pub struct PathId(pub(crate) u32);
1919

2020
impl coding::Codec for PathId {
2121
fn decode<B: bytes::Buf>(r: &mut B) -> coding::Result<Self> {
22-
// TODO(@divma): unclear if the encoding is similar to the varint or plain u32, in any case
23-
// the change needs to be done just here
24-
Ok(Self(u32::decode(r)?))
22+
let v = VarInt::decode(r)?;
23+
// TODO(@flub): Mapping this error is not nice, maybe the error type should have 2
24+
// variants.
25+
let v = u32::try_from(v.0).map_err(|_| coding::UnexpectedEnd)?;
26+
Ok(Self(v as u32))
2527
}
2628

2729
fn encode<B: bytes::BufMut>(&self, w: &mut B) {
28-
self.0.encode(w)
30+
VarInt(self.0 as u64).encode(w)
2931
}
3032
}
3133

0 commit comments

Comments
 (0)