Skip to content

Commit

Permalink
Implemented review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Schoppe committed Apr 22, 2024
1 parent e885e94 commit 5a3a75e
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 230 deletions.
48 changes: 21 additions & 27 deletions examples/print_dlt_file.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
fs::File,
io::{BufReader, Write},
path::PathBuf,
};
use std::{fs::File, io::BufReader, path::PathBuf};

use dlt_parse::{
error::ReadError, storage::DltStorageReader, ControlNvPayload, LogNvPayload, LogVPayload,
Expand Down Expand Up @@ -42,47 +38,45 @@ fn main() -> Result<(), ReadError> {
if let Some(typed_payload) = msg.packet.typed_payload() {
use dlt_parse::DltTypedPayload::*;
match typed_payload {
LogV(LogVPayload { info, iter }) => {
LogV(LogVPayload { iter, log_level }) => {
println!(
"verbose message of type {:?} with values:",
info.into_message_type()
"verbose log message with log level {:?} and values:",
log_level
);
for value in iter {
println!(" {:?}", value);
}
}
LogNv(LogNvPayload {
info,
log_level,
msg_id,
payload,
}) => {
println!(
"non verbose message 0x{:x} of type {:?} and {} bytes of payload without control message.",
"non verbose log message 0x{:x} with log level {:?} and {} bytes of payload.",
msg_id,
info.map(|v| v.into_message_type()),
log_level,
payload.len(),
);
}
ControlNv(ControlNvPayload {
info,
msg_id,
msg_type,
service_id,
payload,
control_message,
}) => {
if let Some(mut control_message) = control_message {
println!(
"non verbose message 0x{:x} of type {:?} and {} bytes of payload.",
msg_id,
info.map(|v| v.into_message_type()),
payload.len(),
);
print!("With control message: ");
if let Err(err) = control_message.write(b"") {
println!("The following error occured while trying to write the control message content: {:?}" , err);
}
}
println!(
"non verbose control message {:?} with service id: {} and {} bytes of payload.",
msg_type,
service_id,
payload.len(),
);
}
_ => {}
GenericNv(_) => println!("generic non verbose message received"),
TraceV(_) => println!("verbose trace message received"),
TraceNv(_) => println!("non verbose trace message received"),
NetworkV(_) => println!("verbose network message received"),
NetworkNv(_) => println!("non verbose network message received"),
ControlV(_) => println!("verbose control message received"),
}
} else {
println!("non verbose message with incomplete message id");
Expand Down
44 changes: 21 additions & 23 deletions examples/print_pcap_dlt_msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use etherparse;
use rpcap::read::PcapReader;

use std::fs::File;
use std::io::{BufReader, Write};
use std::io::BufReader;

use dlt_parse::*;

Expand Down Expand Up @@ -94,47 +94,45 @@ fn read(arguments: CommandLineArguments) -> Result<(), Error> {
if let Some(typed_payload) = dlt_slice.typed_payload() {
use dlt_parse::DltTypedPayload::*;
match typed_payload {
LogV(LogVPayload { info, iter }) => {
LogV(LogVPayload { iter, log_level }) => {
println!(
"verbose message of type {:?} with values:",
info.into_message_type()
"verbose log message with log level {:?} and values:",
log_level
);
for value in iter {
println!(" {:?}", value);
}
}
LogNv(LogNvPayload {
info,
log_level,
msg_id,
payload,
}) => {
println!(
"non verbose message 0x{:x} of type {:?} and {} bytes of payload without control message.",
"non verbose log message 0x{:x} with log level {:?} and {} bytes of payload.",
msg_id,
info.map(|v| v.into_message_type()),
log_level,
payload.len(),
);
}
ControlNv(ControlNvPayload {
info,
msg_id,
msg_type,
service_id,
payload,
control_message,
}) => {
if let Some(mut control_message) = control_message {
println!(
"non verbose message 0x{:x} of type {:?} and {} bytes of payload.",
msg_id,
info.map(|v| v.into_message_type()),
payload.len(),
);
print!("With control message: ");
if let Err(err) = control_message.write(b"") {
println!("The following error occured while trying to write the control message content: {:?}" , err);
}
}
println!(
"non verbose control message {:?} with service id: {} and {} bytes of payload.",
msg_type,
service_id,
payload.len(),
);
}
_ => {}
GenericNv(_) => println!("generic non verbose message received"),
TraceV(_) => println!("verbose trace message received"),
TraceNv(_) => println!("non verbose trace message received"),
NetworkV(_) => println!("verbose network message received"),
NetworkNv(_) => println!("non verbose network message received"),
ControlV(_) => println!("verbose control message received"),
}
} else {
println!("non verbose message with incomplete message id");
Expand Down
16 changes: 10 additions & 6 deletions examples/print_verbose_manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ fn main() -> Result<(), ReadError> {
if let Some(typed_payload) = msg.packet.typed_payload() {
use dlt_parse::DltTypedPayload::*;
match typed_payload {
LogV(LogVPayload { info, iter }) => {
println!(
"verbose message of type {:?} with values:",
info.into_message_type()
);
LogV(LogVPayload { log_level, iter }) => {
println!("verbose message of type {:?} with values:", log_level);
let field_print_result = print_fields(iter, 1);
if let Err(err) = field_print_result {
println!(" ERROR decoding value: {}", err);
}
}
_ => {}
GenericNv(_) => println!("generic non verbose message received"),
TraceV(_) => println!("verbose trace message received"),
TraceNv(_) => println!("non verbose trace message received"),
NetworkV(_) => println!("verbose network message received"),
NetworkNv(_) => println!("non verbose network message received"),
ControlV(_) => println!("verbose control message received"),
LogNv(_) => println!("non verbose log message received"),
ControlNv(_) => println!("non verbose control message received"),
}
} else {
println!("non verbose message with incomplete message id");
Expand Down
Loading

0 comments on commit 5a3a75e

Please sign in to comment.