diff --git a/src/dlt_typed_payload.rs b/src/dlt_typed_payload.rs index c7eea2b..5bb8e94 100644 --- a/src/dlt_typed_payload.rs +++ b/src/dlt_typed_payload.rs @@ -1,6 +1,4 @@ -use crate::{ - verbose::VerboseIter, DltControlMessageType, DltLogLevel, DltNetworkType, DltTraceType, -}; +use crate::{*, verbose::VerboseIter}; /// Typed payload of a DLT log message based on the message info in the DLT /// extended header. @@ -48,47 +46,6 @@ pub enum DltTypedPayload<'a> { ControlV(ControlVPayload<'a>), } -/// A non verbose message of unknown type. -/// -/// This type is used if the DLT message did not contain an extended -/// header and the type of message can only be determined via the -/// message id. In this the type of th message can only be determined -/// based on the message id and an additional information source describing -/// how to decode the message payloads and what type of message it is -/// (e.g. a Fibex file). -#[derive(Debug, Clone, Eq, PartialEq, Hash)] -pub struct NvPayload<'a> { - pub msg_id: u32, - pub payload: &'a [u8], -} - -impl<'a> From> for NvPayload<'a> { - fn from(value: LogNvPayload<'a>) -> Self { - NvPayload { - msg_id: value.msg_id, - payload: value.payload, - } - } -} - -impl<'a> From> for NvPayload<'a> { - fn from(value: TraceNvPayload<'a>) -> Self { - NvPayload { - msg_id: value.msg_id, - payload: value.payload, - } - } -} - -impl<'a> From> for NvPayload<'a> { - fn from(value: NetworkNvPayload<'a>) -> Self { - NvPayload { - msg_id: value.msg_id, - payload: value.payload, - } - } -} - /// Non verbose log message (does not contain a description of it's contents). /// /// Non verbose log messages cannot be decoded without additional diff --git a/src/lib.rs b/src/lib.rs index b669a74..1edcf96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,6 +218,9 @@ pub use dlt_packet_slice::*; mod dlt_slice_iterator; pub use dlt_slice_iterator::*; +mod nv_payload; +pub use nv_payload::*; + /// Control message related types & functions. pub mod control; diff --git a/src/nv_payload.rs b/src/nv_payload.rs new file mode 100644 index 0000000..ece183a --- /dev/null +++ b/src/nv_payload.rs @@ -0,0 +1,72 @@ +use crate::*; + +/// A non verbose message of unknown type. +/// +/// This type is used if the DLT message did not contain an extended +/// header and the type of message can only be determined via the +/// message id. In this the type of th message can only be determined +/// based on the message id and an additional information source describing +/// how to decode the message payloads and what type of message it is +/// (e.g. a Fibex file). +#[derive(Debug, Clone, Eq, PartialEq, Hash)] +pub struct NvPayload<'a> { + pub msg_id: u32, + pub payload: &'a [u8], +} + +impl<'a> From> for NvPayload<'a> { + fn from(value: LogNvPayload<'a>) -> Self { + NvPayload { + msg_id: value.msg_id, + payload: value.payload, + } + } +} + +impl<'a> From> for NvPayload<'a> { + fn from(value: TraceNvPayload<'a>) -> Self { + NvPayload { + msg_id: value.msg_id, + payload: value.payload, + } + } +} + +impl<'a> From> for NvPayload<'a> { + fn from(value: NetworkNvPayload<'a>) -> Self { + NvPayload { + msg_id: value.msg_id, + payload: value.payload, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn from() { + let data = [5,6,7,8]; + let msg_id = 1234_5678u32; + let payload = &data; + + // LogNvPayload + assert_eq!( + NvPayload::from(LogNvPayload{ msg_id, payload, log_level: DltLogLevel::Info }), + NvPayload{ msg_id, payload } + ); + + // TraceNvPayload + assert_eq!( + NvPayload::from(TraceNvPayload{ msg_id, payload, trace_type: DltTraceType::State }), + NvPayload{ msg_id, payload } + ); + + // TraceNvPayload + assert_eq!( + NvPayload::from(NetworkNvPayload{msg_id,payload, net_type: DltNetworkType::Flexray }), + NvPayload{ msg_id, payload } + ); + } +} \ No newline at end of file