Skip to content

Commit 9850130

Browse files
committed
Add API for reading message slices from a source.
This change will support: - Generic statistics (esrlabs#31) - Reading messages from streams (esrlabs#34) Additionally it provides a cleanup of the crate's feature names and removes the dependecy to the legacy buf_redux create.
1 parent 25706ea commit 9850130

File tree

11 files changed

+399
-155
lines changed

11 files changed

+399
-155
lines changed

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.20.0] - 2025-02-25
11+
12+
### Added
13+
14+
- Support generic statistics from reading messages
15+
- Support parsing of DLT messages from streams
16+
17+
### Changed
18+
19+
- Cleanup feature names
20+
1021
## [0.19.2] - 2025-02-06
1122

1223
### Changed
@@ -36,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3647

3748
### Changed
3849

39-
- Add feature "serde-support", which adds to crate's types Serialize/Deserialize
50+
- Add feature "serialization", which adds to crate's types Serialize/Deserialize
4051

4152
## [0.17.0] - 2024-10-04
4253

Cargo.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dlt-core"
3-
version = "0.19.2"
3+
version = "0.20.0"
44
authors = ["esrlabs.com"]
55
edition = "2021"
66
description = """
@@ -21,13 +21,15 @@ rustc-hash = { version = "2.1", optional = true }
2121
serde = { version = "1.0", features = ["derive"], optional = true }
2222
serde_json = { version = "1.0", optional = true }
2323
thiserror = "1.0"
24+
futures = "0.3"
2425

2526
[features]
2627
default = []
2728
statistics = ["buf_redux", "rustc-hash"]
28-
fibex_parser = ["quick-xml"]
29-
debug_parser = []
30-
serde-support = ["serde", "serde_json"]
29+
fibex = ["quick-xml"]
30+
debug = []
31+
serialization = ["serde", "serde_json"]
32+
stream = []
3133

3234
[lints.rust]
3335
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }
@@ -40,6 +42,9 @@ env_logger = "0.10"
4042
pretty_assertions = "1.3"
4143
proptest = "1.6"
4244
proptest-derive = "0.5"
45+
tokio = { version = "1", features = ["full"] }
46+
tokio-stream = "0.1"
47+
tokio-util = "0.7"
4348

4449
[[bench]]
4550
name = "dlt_benchmarks"

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,13 @@ Below is the revised and improved English version of the documentation:
150150

151151
* **`statistics`**: Enables the `statistics` module, which scans the source data and provides a summary of its contents. This gives you an overview of the number of messages and their content.
152152

153-
* **`fibex_parser`**: Enables the `fibex` module, which allows to parse configurations for non-verbose messages from a fibex model.
153+
* **`fibex`**: Enables the `fibex` module, which allows to parse configurations for non-verbose messages from a fibex model.
154154

155-
* **`debug_parser`**: Adds additional log output for debugging purposes.
155+
* **`debug`**: Adds additional log output for debugging purposes.
156156

157-
* **`serde-support`**: Adds `Serialize` and `Deserialize` implementations (via `serde`) to all public types. This feature is useful if you need to encode or decode these types for transmission or storage.
157+
* **`serialization`**: Adds `Serialize` and `Deserialize` implementations (via `serde`) to all public types. This feature is useful if you need to encode or decode these types for transmission or storage.
158+
159+
* **`stream`**: Provides API for parsing DLT messages from streams.
158160

159161
## Example users
160162

src/dlt.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum Error {
4242

4343
/// Used to express the byte order of DLT data type fields
4444
#[cfg_attr(
45-
feature = "serde-support",
45+
feature = "serialization",
4646
derive(serde::Serialize, serde::Deserialize)
4747
)]
4848
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, PartialOrd, Ord)]
@@ -56,7 +56,7 @@ pub enum Endianness {
5656

5757
/// represents a DLT message including all headers
5858
#[cfg_attr(
59-
feature = "serde-support",
59+
feature = "serialization",
6060
derive(serde::Serialize, serde::Deserialize)
6161
)]
6262
#[derive(Debug, Clone, PartialEq)]
@@ -69,7 +69,7 @@ pub struct Message {
6969

7070
/// Storage header is used in case of dlt entries stored in file
7171
#[cfg_attr(
72-
feature = "serde-support",
72+
feature = "serialization",
7373
derive(serde::Serialize, serde::Deserialize)
7474
)]
7575
#[derive(Debug, Clone, PartialEq)]
@@ -82,7 +82,7 @@ pub struct StorageHeader {
8282

8383
/// The Standard Header shall be in big endian format
8484
#[cfg_attr(
85-
feature = "serde-support",
85+
feature = "serialization",
8686
derive(serde::Serialize, serde::Deserialize)
8787
)]
8888
#[derive(Debug, Clone, PartialEq)]
@@ -107,7 +107,7 @@ pub struct StandardHeader {
107107
///
108108
/// The Extended Header shall be in big endian format
109109
#[cfg_attr(
110-
feature = "serde-support",
110+
feature = "serialization",
111111
derive(serde::Serialize, serde::Deserialize)
112112
)]
113113
#[derive(Debug, Clone, PartialEq)]
@@ -144,7 +144,7 @@ pub struct ExtendedHeader {
144144
/// and payload. The payload contains of the Service ID and the contained parameters.
145145
///
146146
#[cfg_attr(
147-
feature = "serde-support",
147+
feature = "serialization",
148148
derive(serde::Serialize, serde::Deserialize)
149149
)]
150150
#[derive(Debug, Clone, PartialEq)]
@@ -177,7 +177,7 @@ pub enum PayloadContent {
177177
}
178178

179179
#[cfg_attr(
180-
feature = "serde-support",
180+
feature = "serialization",
181181
derive(serde::Serialize, serde::Deserialize)
182182
)]
183183
#[derive(Debug, Clone, PartialEq)]
@@ -343,7 +343,7 @@ impl StandardHeader {
343343

344344
/// Representation of log levels used in DLT log messages
345345
#[cfg_attr(
346-
feature = "serde-support",
346+
feature = "serialization",
347347
derive(serde::Serialize, serde::Deserialize)
348348
)]
349349
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
@@ -378,7 +378,7 @@ impl AsRef<str> for LogLevel {
378378
/// In case the dlt message contains tracing information, the Trace-Type
379379
/// indicates different kinds of trace message types
380380
#[cfg_attr(
381-
feature = "serde-support",
381+
feature = "serialization",
382382
derive(serde::Serialize, serde::Deserialize)
383383
)]
384384
#[derive(Debug, PartialEq, Clone)]
@@ -414,7 +414,7 @@ impl AsRef<str> for ApplicationTraceType {
414414
/// In case the dlt message contains networking information,
415415
/// the Trace-Type indicates different kinds of network message types
416416
#[cfg_attr(
417-
feature = "serde-support",
417+
feature = "serialization",
418418
derive(serde::Serialize, serde::Deserialize)
419419
)]
420420
#[derive(Debug, PartialEq, Clone)]
@@ -457,7 +457,7 @@ const CTRL_TYPE_RESPONSE: u8 = 0x2;
457457
/// In case the dlt message contains control information,
458458
/// the Trace-Type indicates different kinds of control message types
459459
#[cfg_attr(
460-
feature = "serde-support",
460+
feature = "serialization",
461461
derive(serde::Serialize, serde::Deserialize)
462462
)]
463463
#[derive(Debug, PartialEq, Clone)]
@@ -498,7 +498,7 @@ impl ControlType {
498498

499499
/// Part of the extended header, distinguishes log, trace and controll messages
500500
#[cfg_attr(
501-
feature = "serde-support",
501+
feature = "serialization",
502502
derive(serde::Serialize, serde::Deserialize)
503503
)]
504504
#[derive(Debug, PartialEq, Clone)]
@@ -559,7 +559,7 @@ impl ExtendedHeader {
559559
/// Fixed-Point representation. only supports 32 bit and 64 bit values
560560
/// according to the spec 128 bit are possible but we don't support it
561561
#[cfg_attr(
562-
feature = "serde-support",
562+
feature = "serialization",
563563
derive(serde::Serialize, serde::Deserialize)
564564
)]
565565
#[derive(Debug, PartialEq, Clone)]
@@ -578,7 +578,7 @@ pub(crate) fn fixed_point_value_width(v: &FixedPointValue) -> usize {
578578

579579
/// Represents the value of an DLT argument
580580
#[cfg_attr(
581-
feature = "serde-support",
581+
feature = "serialization",
582582
derive(serde::Serialize, serde::Deserialize)
583583
)]
584584
#[derive(Debug, PartialEq, Clone)]
@@ -603,7 +603,7 @@ pub enum Value {
603603
/// Defines what string type is used, `ASCII` or `UTF8`
604604
#[allow(clippy::upper_case_acronyms)]
605605
#[cfg_attr(
606-
feature = "serde-support",
606+
feature = "serialization",
607607
derive(serde::Serialize, serde::Deserialize)
608608
)]
609609
#[derive(Debug, Clone, PartialEq)]
@@ -620,7 +620,7 @@ pub enum StringCoding {
620620

621621
/// Represents the bit width of a floatingpoint value type
622622
#[cfg_attr(
623-
feature = "serde-support",
623+
feature = "serialization",
624624
derive(serde::Serialize, serde::Deserialize)
625625
)]
626626
#[derive(Debug, Clone, PartialEq, Copy)]
@@ -639,7 +639,7 @@ pub(crate) fn float_width_to_type_length(width: FloatWidth) -> TypeLength {
639639

640640
/// Represents the bit width of a value type
641641
#[cfg_attr(
642-
feature = "serde-support",
642+
feature = "serialization",
643643
derive(serde::Serialize, serde::Deserialize)
644644
)]
645645
#[derive(Debug, Clone, PartialEq, Copy)]
@@ -677,7 +677,7 @@ impl TypeLength {
677677
///
678678
/// the Array type is not yet supported and honestly I never saw anyone using it
679679
#[cfg_attr(
680-
feature = "serde-support",
680+
feature = "serialization",
681681
derive(serde::Serialize, serde::Deserialize)
682682
)]
683683
#[derive(Debug, Clone, PartialEq)]
@@ -724,7 +724,7 @@ pub enum TypeInfoKind {
724724
/// number of characters of the associated name or unit filed. The unit
725725
/// information is to add only in some data types.
726726
#[cfg_attr(
727-
feature = "serde-support",
727+
feature = "serialization",
728728
derive(serde::Serialize, serde::Deserialize)
729729
)]
730730
#[derive(Debug, Clone, PartialEq)]
@@ -910,7 +910,7 @@ impl TryFrom<u32> for TypeInfo {
910910
/// * i64 bit if Type Length (TYLE) equals 4
911911
/// * i128 bit if Type Length (TYLE) equals 5 (unsupported)
912912
#[cfg_attr(
913-
feature = "serde-support",
913+
feature = "serialization",
914914
derive(serde::Serialize, serde::Deserialize)
915915
)]
916916
#[derive(Debug, Clone, PartialEq)]
@@ -927,7 +927,7 @@ pub struct FixedPoint {
927927
/// itself, it is needed to provide information like size and type
928928
/// of the variable. This information is contained in the `type_info` field.
929929
#[cfg_attr(
930-
feature = "serde-support",
930+
feature = "serialization",
931931
derive(serde::Serialize, serde::Deserialize)
932932
)]
933933
#[derive(Debug, Clone, PartialEq)]
@@ -1528,7 +1528,7 @@ fn payload_content_len(content: &PayloadContent) -> usize {
15281528

15291529
/// Configuration options for the extended header
15301530
#[cfg_attr(
1531-
feature = "serde-support",
1531+
feature = "serialization",
15321532
derive(serde::Serialize, serde::Deserialize)
15331533
)]
15341534
#[derive(Debug, Clone, PartialEq)]
@@ -1540,7 +1540,7 @@ pub struct ExtendedHeaderConfig {
15401540

15411541
/// Configuration options for a DLT message, used when constructing a message
15421542
#[cfg_attr(
1543-
feature = "serde-support",
1543+
feature = "serialization",
15441544
derive(serde::Serialize, serde::Deserialize)
15451545
)]
15461546
#[derive(Debug, Clone, PartialEq)]
@@ -1557,7 +1557,7 @@ pub struct MessageConfig {
15571557

15581558
#[inline]
15591559
fn dbg_bytes_with_info(_name: &str, _bytes: &[u8], _info: Option<&str>) {
1560-
#[cfg(feature = "debug_parser")]
1560+
#[cfg(feature = "debug")]
15611561
{
15621562
trace!(
15631563
"writing {}: {} {:02X?} {}",

src/fibex/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub enum Error {
5555

5656
/// Contains all the paths of fibex files that should be combined into the model
5757
#[cfg_attr(
58-
feature = "serde-support",
58+
feature = "serialization",
5959
derive(serde::Serialize, serde::Deserialize)
6060
)]
6161
#[derive(Debug)]

src/filtering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{collections::HashSet, iter::FromIterator};
2525
/// only this is possible:
2626
/// - `app-id is_one_of ["abc","foo"] AND log-level <= DEBUG`
2727
#[cfg_attr(
28-
feature = "serde-support",
28+
feature = "serialization",
2929
derive(serde::Serialize, serde::Deserialize)
3030
)]
3131
#[derive(Debug, Clone)]
@@ -96,8 +96,8 @@ impl From<&DltFilterConfig> for ProcessedDltFilterConfig {
9696
}
9797
}
9898

99-
/// Read filter config from a json file. Available only with feature "serde-support"
100-
#[cfg(feature = "serde-support")]
99+
/// Read filter config from a json file. Available only with feature "serialization"
100+
#[cfg(feature = "serialization")]
101101
pub fn read_filter_options(f: &mut std::fs::File) -> Option<DltFilterConfig> {
102102
use std::io::Read;
103103

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
extern crate log;
2121

2222
pub mod dlt;
23-
#[cfg(feature = "fibex_parser")]
23+
#[cfg(feature = "fibex")]
2424
pub mod fibex;
2525
pub mod filtering;
2626
pub mod parse;
27+
pub mod read;
2728

2829
#[cfg(not(tarpaulin_include))]
2930
pub mod service_id;

src/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ fn dlt_payload<T: NomByteOrder>(
747747

748748
#[inline]
749749
fn dbg_parsed<T: std::fmt::Debug>(_name: &str, _before: &[u8], _after: &[u8], _value: &T) {
750-
// #[cfg(feature = "debug_parser")]
750+
// #[cfg(feature = "debug")]
751751
{
752752
let input_len = _before.len();
753753
let now_len = _after.len();

0 commit comments

Comments
 (0)