Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: replace hidden field with From impl #2099

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions perf/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ fn throughput_bytes_per_second(duration_in_micros: u64, size: u64) -> f64 {
mod json {
use crate::stats;
use crate::stats::{Stats, StreamIntervalStats};
use quinn::StreamId;
use serde::{self, ser::SerializeStruct, Serialize, Serializer};
use std::io::Write;
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -339,7 +340,8 @@ mod json {

#[derive(Serialize)]
struct Stream {
id: u64,
#[serde(serialize_with = "serialize_stream_id")]
id: StreamId,
start: f64,
end: f64,
seconds: f64,
Expand All @@ -356,7 +358,7 @@ mod json {
let bits_per_second = stats.bytes as f64 * 8.0 / period.seconds;

Self {
id: stats.id.0,
id: stats.id,
start: period.start,
end: period.end,
seconds: period.seconds,
Expand All @@ -367,6 +369,10 @@ mod json {
}
}

fn serialize_stream_id<S: Serializer>(id: &StreamId, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_u64(u64::from(*id))
}

#[derive(Serialize)]
struct Sum {
start: f64,
Expand Down
8 changes: 7 additions & 1 deletion quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl fmt::Display for Dir {
/// Identifier for a stream within a particular connection
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct StreamId(#[doc(hidden)] pub u64);
pub struct StreamId(u64);

impl fmt::Display for StreamId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -279,6 +279,12 @@ impl From<VarInt> for StreamId {
}
}

impl From<StreamId> for u64 {
fn from(x: StreamId) -> Self {
x.0
}
}

impl coding::Codec for StreamId {
fn decode<B: bytes::Buf>(buf: &mut B) -> coding::Result<Self> {
VarInt::decode(buf).map(|x| Self(x.into_inner()))
Expand Down
Loading