Skip to content

Commit 5fe4bcb

Browse files
mullerchbrocaar
authored andcommitted
Skip serialization of RXPK fields that are None. (#33)
1 parent d054fd2 commit 5fe4bcb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/structs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub struct RxPk {
192192
#[serde(with = "compact_time_format")]
193193
pub time: DateTime<Utc>,
194194
/// GPS time of pkt RX, number of milliseconds since 06.Jan.1980
195+
#[serde(skip_serializing_if = "Option::is_none")]
195196
pub tmms: Option<u64>,
196197
/// Internal timestamp of "RX finished" event (32b unsigned)
197198
pub tmst: u32,
@@ -208,10 +209,12 @@ pub struct RxPk {
208209
/// LoRa datarate identifier (eg. SF12BW500)}
209210
pub datr: DataRate,
210211
/// LoRa coding rate.
212+
#[serde(skip_serializing_if = "Option::is_none")]
211213
pub codr: Option<CodeRate>,
212214
/// RSSI in dBm (signed integer, 1 dB precision).
213215
pub rssi: i32,
214216
/// Lora SNR ratio in dB (signed float, 0.1 dB precision).
217+
#[serde(skip_serializing_if = "Option::is_none")]
215218
pub lsnr: Option<f32>,
216219
/// RF packet payload size in bytes (unsigned integer).
217220
pub size: u8,
@@ -806,7 +809,7 @@ mod tests {
806809

807810
assert_eq!(
808811
str::from_utf8(&b[12..]).unwrap(),
809-
r#"{"rxpk":[{"time":"1970-01-01T00:00:00+00:00","tmms":1000,"tmst":16909060,"freq":868.3,"chan":1,"rfch":2,"stat":1,"modu":"FSK","datr":50000,"codr":null,"rssi":-160,"lsnr":null,"size":3,"data":"AQID"}]}"#
812+
r#"{"rxpk":[{"time":"1970-01-01T00:00:00+00:00","tmms":1000,"tmst":16909060,"freq":868.3,"chan":1,"rfch":2,"stat":1,"modu":"FSK","datr":50000,"rssi":-160,"size":3,"data":"AQID"}]}"#
810813
);
811814
}
812815

0 commit comments

Comments
 (0)