Skip to content

Commit 5c0d053

Browse files
committed
feat(quinn): add serde support
Signed-off-by: loongtao.zhang <[email protected]>
1 parent eee334d commit 5c0d053

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quinn-proto/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ tracing-log = ["tracing/log"]
3535
rustls-log = ["rustls?/logging"]
3636
# Enable qlog support
3737
qlog = ["dep:qlog"]
38+
# Add serde support.
39+
serde = ["dep:serde"]
3840

3941
# Internal (PRIVATE!) features used to aid testing.
4042
# Don't rely on these whatsoever. They may disappear at any time.
@@ -57,6 +59,7 @@ slab = { workspace = true }
5759
thiserror = { workspace = true }
5860
tinyvec = { workspace = true, features = ["alloc"] }
5961
tracing = { workspace = true }
62+
serde = { workspace = true, optional = true }
6063

6164
# Feature flags & dependencies for wasm
6265
# wasm-bindgen is assumed for a wasm*-*-unknown target

quinn-proto/src/connection/stats.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
//! Connection statistics
22
33
use crate::{Dir, Duration, frame::Frame};
4+
#[cfg(feature = "serde")]
5+
use serde::Serialize;
46

57
/// Statistics about UDP datagrams transmitted or received on a connection
68
///
79
/// All QUIC packets are carried by UDP datagrams. Hence, these statistics cover all traffic on a connection.
810
#[derive(Default, Debug, Copy, Clone)]
11+
#[cfg_attr(feature = "serde", derive(Serialize))]
912
#[non_exhaustive]
1013
pub struct UdpStats {
1114
/// The amount of UDP datagrams observed
@@ -28,6 +31,7 @@ impl UdpStats {
2831

2932
/// Number of frames transmitted or received of each frame type
3033
#[derive(Default, Copy, Clone)]
34+
#[cfg_attr(feature = "serde", derive(Serialize))]
3135
#[non_exhaustive]
3236
#[allow(missing_docs)]
3337
pub struct FrameStats {
@@ -132,6 +136,7 @@ impl std::fmt::Debug for FrameStats {
132136

133137
/// Statistics related to a transmission path
134138
#[derive(Debug, Default, Copy, Clone)]
139+
#[cfg_attr(feature = "serde", derive(Serialize))]
135140
#[non_exhaustive]
136141
pub struct PathStats {
137142
/// Current best estimate of this connection's latency (round-trip-time)
@@ -159,6 +164,7 @@ pub struct PathStats {
159164

160165
/// Connection statistics
161166
#[derive(Debug, Default, Copy, Clone)]
167+
#[cfg_attr(feature = "serde", derive(Serialize))]
162168
#[non_exhaustive]
163169
pub struct ConnectionStats {
164170
/// Statistics about UDP datagrams transmitted on a connection

quinn/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ tracing-log = ["tracing/log", "proto/tracing-log", "udp/tracing-log"]
4444
rustls-log = ["rustls?/logging"]
4545
# Enable qlog support
4646
qlog = ["proto/qlog"]
47+
# Add serde support.
48+
serde = ["dep:serde"]
4749

4850
# Internal (PRIVATE!) features used to aid testing.
4951
# Don't rely on these whatsoever. They may disappear at any time.
@@ -64,6 +66,7 @@ thiserror = { workspace = true }
6466
tracing = { workspace = true }
6567
tokio = { workspace = true }
6668
udp = { package = "quinn-udp", path = "../quinn-udp", version = "0.6", default-features = false, features = ["tracing"] }
69+
serde = { workspace = true, optional = true }
6770

6871
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
6972
socket2 = { workspace = true }

quinn/src/endpoint.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use proto::{
2525
EndpointEvent, ServerConfig,
2626
};
2727
use rustc_hash::FxHashMap;
28+
#[cfg(feature = "serde")]
29+
use serde::Serialize;
2830
#[cfg(all(not(wasm_browser), any(feature = "aws-lc-rs", feature = "ring"),))]
2931
use socket2::{Domain, Protocol, Socket, Type};
3032
use tokio::sync::{Notify, futures::Notified, mpsc};
@@ -334,6 +336,7 @@ impl Endpoint {
334336
/// Statistics on [Endpoint] activity
335337
#[non_exhaustive]
336338
#[derive(Debug, Default, Copy, Clone)]
339+
#[cfg_attr(feature = "serde", derive(Serialize))]
337340
pub struct EndpointStats {
338341
/// Cummulative number of Quic handshakes accepted by this [Endpoint]
339342
pub accepted_handshakes: u64,

0 commit comments

Comments
 (0)