mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-30 19:46:15 +00:00
transport: derive Serialize for EthernetStatsSnapshot
EthernetStatsSnapshot derived only Clone/Debug/Default, unlike every
other transport's *StatsSnapshot which also derives Serialize. That gap
forced a hand-rolled serde_json::json!{} arm in TransportHandle::
transport_stats() that re-listed all ten fields by hand. Add the
Serialize derive and collapse the arm to the same one-line
serde_json::to_value(...) form the other transports use. The emitted
JSON keys and values are unchanged.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
use portable_atomic::{AtomicU64, Ordering};
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
/// Statistics for an Ethernet transport instance.
|
||||
///
|
||||
/// Uses atomic counters for lock-free updates from the receive loop
|
||||
@@ -92,7 +94,7 @@ impl Default for EthernetStats {
|
||||
}
|
||||
|
||||
/// Point-in-time snapshot of Ethernet stats (non-atomic, copyable).
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct EthernetStatsSnapshot {
|
||||
pub frames_sent: u64,
|
||||
pub frames_recv: u64,
|
||||
|
||||
+1
-13
@@ -1022,19 +1022,7 @@ impl TransportHandle {
|
||||
}
|
||||
#[cfg(unix)]
|
||||
TransportHandle::Ethernet(t) => {
|
||||
let snap = t.stats().snapshot();
|
||||
serde_json::json!({
|
||||
"frames_sent": snap.frames_sent,
|
||||
"frames_recv": snap.frames_recv,
|
||||
"bytes_sent": snap.bytes_sent,
|
||||
"bytes_recv": snap.bytes_recv,
|
||||
"send_errors": snap.send_errors,
|
||||
"recv_errors": snap.recv_errors,
|
||||
"beacons_sent": snap.beacons_sent,
|
||||
"beacons_recv": snap.beacons_recv,
|
||||
"frames_too_short": snap.frames_too_short,
|
||||
"frames_too_long": snap.frames_too_long,
|
||||
})
|
||||
serde_json::to_value(t.stats().snapshot()).unwrap_or_default()
|
||||
}
|
||||
TransportHandle::Tcp(t) => {
|
||||
serde_json::to_value(t.stats().snapshot()).unwrap_or_default()
|
||||
|
||||
Reference in New Issue
Block a user