Skip to content

Commit 9a680dc

Browse files
authored
chore: rustfmt (#53)
1 parent 4d1c56b commit 9a680dc

39 files changed

+419
-341
lines changed

examples/read_sbf.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use libsbf::{Messages, reader::SbfReader};
1+
use libsbf::{reader::SbfReader, Messages};
22

33
use clap::Parser;
44
use std::collections::HashMap;
@@ -12,7 +12,7 @@ use tracing_subscriber::EnvFilter;
1212
#[command(author, version, about, long_about = None)]
1313
struct Args {
1414
/// Input source: file path or TCP address (host:port)
15-
///
15+
///
1616
/// Examples:
1717
/// - /path/to/file.sbf (read from file)
1818
/// - 192.168.1.100:5555 (connect to TCP)
@@ -30,9 +30,9 @@ fn main() -> anyhow::Result<()> {
3030
.with_env_filter(EnvFilter::from_default_env())
3131
.with_writer(std::io::stderr)
3232
.init();
33-
33+
3434
let args = Args::parse();
35-
35+
3636
// Check if argument looks like a file path or TCP address
3737
let reader: Box<dyn Read> = if args.input.contains(':') {
3838
eprintln!("Connecting to TCP: {}", args.input);
@@ -41,7 +41,7 @@ fn main() -> anyhow::Result<()> {
4141
eprintln!("Reading from file: {}", args.input);
4242
Box::new(File::open(args.input)?)
4343
};
44-
44+
4545
let sbf_reader = SbfReader::new(reader);
4646
let mut stats: HashMap<&str, usize> = HashMap::new();
4747
let mut unsupported_blocks: HashMap<u16, usize> = HashMap::new();
@@ -87,19 +87,31 @@ fn main() -> anyhow::Result<()> {
8787
}
8888
Messages::Meas3Ranges(msg) => {
8989
if args.verbose {
90-
println!("Meas3Ranges: TOW={:?}, raw_bytes={}", msg.tow, msg.raw_data.len());
90+
println!(
91+
"Meas3Ranges: TOW={:?}, raw_bytes={}",
92+
msg.tow,
93+
msg.raw_data.len()
94+
);
9195
}
9296
*stats.entry("Meas3Ranges").or_insert(0) += 1;
9397
}
9498
Messages::Meas3Doppler(msg) => {
9599
if args.verbose {
96-
println!("Meas3Doppler: TOW={:?}, raw_bytes={}", msg.tow, msg.raw_data.len());
100+
println!(
101+
"Meas3Doppler: TOW={:?}, raw_bytes={}",
102+
msg.tow,
103+
msg.raw_data.len()
104+
);
97105
}
98106
*stats.entry("Meas3Doppler").or_insert(0) += 1;
99107
}
100108
Messages::INSSupport(msg) => {
101109
if args.verbose {
102-
println!("INSSupport: TOW={:?}, raw_bytes={}", msg.tow, msg.raw_data.len());
110+
println!(
111+
"INSSupport: TOW={:?}, raw_bytes={}",
112+
msg.tow,
113+
msg.raw_data.len()
114+
);
103115
}
104116
*stats.entry("INSSupport").or_insert(0) += 1;
105117
}
@@ -242,15 +254,15 @@ fn main() -> anyhow::Result<()> {
242254
}
243255
}
244256
}
245-
257+
246258
// Print statistics
247259
eprintln!("\n=== Message Statistics ===");
248260
let total: usize = stats.values().sum();
249261
for (msg_type, count) in stats.iter() {
250262
eprintln!("{}: {}", msg_type, count);
251263
}
252264
eprintln!("Total messages: {}", total);
253-
265+
254266
// Print unsupported blocks
255267
if !unsupported_blocks.is_empty() {
256268
eprintln!("\n=== Unsupported Block IDs ===");
@@ -260,14 +272,14 @@ fn main() -> anyhow::Result<()> {
260272
eprintln!(" 0x{:04X} ({}): {} occurrences", block_id, block_id, count);
261273
}
262274
}
263-
275+
264276
// Print AttCovEuler error distribution
265277
if !att_cov_errors.is_empty() {
266278
eprintln!("\n=== AttCovEuler Error Distribution ===");
267279
for (error_code, count) in att_cov_errors.iter() {
268280
eprintln!(" Error {}: {} occurrences", error_code, count);
269281
}
270282
}
271-
283+
272284
Ok(())
273285
}

sbf-parser-fuzz/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use afl::*;
33
use libsbf::parser::SbfParser;
44

55
fn main() {
6-
fuzz!(|data: &[u8]|{
6+
fuzz!(|data: &[u8]| {
77
let mut parser = SbfParser::new();
88

99
match parser.consume(data) {
@@ -17,4 +17,3 @@ fn main() {
1717
}
1818
})
1919
}
20-

sbf-parser-fuzz/src/reader-fuzz.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
fuzz!(|data: &[u8]| {
88
// Test with the original fuzz data
99
test_sbf_reader(data);
10-
10+
1111
// Also test with larger data to catch buffer-related bugs
1212
if (0..20000).contains(&data.len()) {
1313
// Create a larger test case by repeating the data
@@ -24,16 +24,16 @@ fn test_sbf_reader(data: &[u8]) {
2424
// Create a simple reader from the fuzz data
2525
let mut reader = FuzzReader::new(data);
2626
let total_bytes = reader.len();
27-
27+
2828
// Skip empty data
2929
if total_bytes == 0 {
3030
return;
3131
}
32-
32+
3333
// Process all messages from the SbfReader
3434
let sbf_reader = SbfReader::new(&mut reader);
3535
let mut message_count = 0;
36-
36+
3737
for result in sbf_reader {
3838
match result {
3939
Ok(_msg) => {
@@ -44,12 +44,14 @@ fn test_sbf_reader(data: &[u8]) {
4444
}
4545
}
4646
}
47-
47+
4848
// The reader should have consumed all the data
4949
let bytes_consumed = reader.bytes_read();
50-
assert_eq!(bytes_consumed, total_bytes,
51-
"SbfReader did not consume all {} bytes of fuzz data, only consumed {}",
52-
total_bytes, bytes_consumed);
50+
assert_eq!(
51+
bytes_consumed, total_bytes,
52+
"SbfReader did not consume all {} bytes of fuzz data, only consumed {}",
53+
total_bytes, bytes_consumed
54+
);
5355
}
5456

5557
// A simple reader that provides all fuzz data at once
@@ -65,11 +67,11 @@ impl FuzzReader {
6567
position: 0,
6668
}
6769
}
68-
70+
6971
fn len(&self) -> usize {
7072
self.data.len()
7173
}
72-
74+
7375
fn bytes_read(&self) -> usize {
7476
self.position
7577
}
@@ -79,12 +81,12 @@ impl Read for FuzzReader {
7981
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
8082
let remaining = self.data.len() - self.position;
8183
let to_read = buf.len().min(remaining);
82-
84+
8385
if to_read > 0 {
8486
buf[..to_read].copy_from_slice(&self.data[self.position..self.position + to_read]);
8587
self.position += to_read;
8688
}
87-
89+
8890
Ok(to_read)
8991
}
9092
}

src/lib.rs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use binrw::binrw;
1212

1313
extern crate alloc;
1414

15-
pub mod parser;
1615
pub mod messages;
16+
pub mod parser;
1717

1818
#[cfg(feature = "std")]
1919
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
@@ -24,46 +24,23 @@ mod mega_test;
2424

2525
// Constants for DO_NOT_USE values
2626
const DO_NOT_USE_I2: i16 = -32768;
27-
const DO_NOT_USE_U1: u8 = 255;
27+
const DO_NOT_USE_U1: u8 = 255;
2828
const DO_NOT_USE_U2: u16 = 65535;
2929
const DO_NOT_USE_U4: u32 = 4294967295;
3030
const DO_NOT_USE_F4: f32 = -2e10;
3131
const DO_NOT_USE_F8: f64 = -2e10;
3232

3333
// Re-export all message types at crate level
3434
pub use messages::{
35-
MeasEpoch, MeasEpochChannelType1, MeasEpochChannelType2,
36-
MeasExtra, MeasExtraChannelSub,
37-
Meas3Ranges, Meas3Doppler,
38-
DiffCorrIn,
39-
INSSupport,
40-
INSNavGeod, INSNavGeodPosStdDev, INSNavGeodAtt, INSNavGeodAttStdDev,
41-
INSNavGeodVel, INSNavGeodVelStdDev, INSNavGeodPosCov, INSNavGeodVelCov,
42-
INSNavGeodAttCov,
43-
AttEuler, AttCovEuler,
44-
ExtSensorMeas, ExtSensorMeasSet, ExtSensorMeasAcceleration,
45-
ExtSensorMeasAngularRate, ExtSensorMeasVelocity, ExtSensorMeasInfo,
46-
ExtSensorMeasZeroVelocityFlag, ExtSensorMeasSetType,
47-
QualityInd,
48-
ImuSetup,
49-
ReceiverSetup,
50-
GEORawL1, GEONav,
51-
PosCovGeodetic,
52-
PVTGeodetic,
53-
ReceiverStatus, AGCState,
54-
ExtSensorStatus,
55-
GALIon,
56-
GALUtc,
57-
GPSIon,
58-
GPSUtc,
59-
VelSensorSetup,
60-
ExtSensorInfo,
61-
GALNav,
62-
GALGstGps,
63-
GPSNav,
64-
Commands,
65-
BDSIon,
66-
GPSCNav,
35+
AGCState, AttCovEuler, AttEuler, BDSIon, Commands, DiffCorrIn, ExtSensorInfo, ExtSensorMeas,
36+
ExtSensorMeasAcceleration, ExtSensorMeasAngularRate, ExtSensorMeasInfo, ExtSensorMeasSet,
37+
ExtSensorMeasSetType, ExtSensorMeasVelocity, ExtSensorMeasZeroVelocityFlag, ExtSensorStatus,
38+
GALGstGps, GALIon, GALNav, GALUtc, GEONav, GEORawL1, GPSCNav, GPSIon, GPSNav, GPSUtc,
39+
INSNavGeod, INSNavGeodAtt, INSNavGeodAttCov, INSNavGeodAttStdDev, INSNavGeodPosCov,
40+
INSNavGeodPosStdDev, INSNavGeodVel, INSNavGeodVelCov, INSNavGeodVelStdDev, INSSupport,
41+
ImuSetup, Meas3Doppler, Meas3Ranges, MeasEpoch, MeasEpochChannelType1, MeasEpochChannelType2,
42+
MeasExtra, MeasExtraChannelSub, PVTGeodetic, PosCovGeodetic, QualityInd, ReceiverSetup,
43+
ReceiverStatus, VelSensorSetup,
6744
};
6845

6946
#[binrw]
@@ -162,4 +139,4 @@ define_messages!(
162139

163140
pub fn is_sync(bytes: &[u8; 2]) -> bool {
164141
bytes == b"$@"
165-
}
142+
}

0 commit comments

Comments
 (0)