diff --git a/crates/core/tedge_api/src/lib.rs b/crates/core/tedge_api/src/lib.rs index 658d7ca445b..cdfa0a1119f 100644 --- a/crates/core/tedge_api/src/lib.rs +++ b/crates/core/tedge_api/src/lib.rs @@ -1,20 +1,14 @@ pub mod alarm; -pub mod builder; -pub mod data; pub mod entity_store; pub mod error; pub mod event; -pub mod group; pub mod health; pub mod measurement; pub mod messages; pub mod mqtt_topics; -pub mod parser; pub mod path; -pub mod serialize; mod software; mod store; -pub mod utils; pub mod workflow; pub use download::*; diff --git a/crates/core/tedge_api/src/builder.rs b/crates/core/tedge_api/src/measurement/builder.rs similarity index 98% rename from crates/core/tedge_api/src/builder.rs rename to crates/core/tedge_api/src/measurement/builder.rs index 2a742978d73..f424ecab7a4 100644 --- a/crates/core/tedge_api/src/builder.rs +++ b/crates/core/tedge_api/src/measurement/builder.rs @@ -1,6 +1,6 @@ use time::OffsetDateTime; -use crate::data::*; +use crate::measurement::data::*; use crate::measurement::*; /// A `MeasurementVisitor` that builds up `ThinEdgeJson`. diff --git a/crates/core/tedge_api/src/data.rs b/crates/core/tedge_api/src/measurement/data.rs similarity index 100% rename from crates/core/tedge_api/src/data.rs rename to crates/core/tedge_api/src/measurement/data.rs diff --git a/crates/core/tedge_api/src/group.rs b/crates/core/tedge_api/src/measurement/group.rs similarity index 100% rename from crates/core/tedge_api/src/group.rs rename to crates/core/tedge_api/src/measurement/group.rs diff --git a/crates/core/tedge_api/src/measurement/mod.rs b/crates/core/tedge_api/src/measurement/mod.rs index 94d5c87bd04..34317929618 100644 --- a/crates/core/tedge_api/src/measurement/mod.rs +++ b/crates/core/tedge_api/src/measurement/mod.rs @@ -1,5 +1,18 @@ use time::OffsetDateTime; +#[cfg(test)] +pub mod builder; +#[cfg(test)] +mod data; +mod group; +mod parser; +mod serialize; +pub(crate) mod utils; + +pub use group::*; +pub use parser::*; +pub use serialize::*; + /// The `MeasurementVisitor` trait represents the capability to visit a series of measurements, possibly grouped. /// /// Here is an implementation of the `MeasurementVisitor` trait that prints the measurements: diff --git a/crates/core/tedge_api/src/parser.rs b/crates/core/tedge_api/src/measurement/parser.rs similarity index 95% rename from crates/core/tedge_api/src/parser.rs rename to crates/core/tedge_api/src/measurement/parser.rs index cc6320083f1..cf140837567 100644 --- a/crates/core/tedge_api/src/parser.rs +++ b/crates/core/tedge_api/src/measurement/parser.rs @@ -276,7 +276,7 @@ fn invalid_empty_measurement(key: &str) -> String { fn map_error(error: serde_json::Error, input: &str) -> ThinEdgeJsonParserError { const MAX_INPUT_EXCERPT: usize = 80; let input_excerpt = - crate::utils::excerpt(input, error.line(), error.column(), MAX_INPUT_EXCERPT); + crate::measurement::utils::excerpt(input, error.line(), error.column(), MAX_INPUT_EXCERPT); ThinEdgeJsonParserError { error, input_excerpt, @@ -287,11 +287,11 @@ mod tests { use time::macros::datetime; use time::OffsetDateTime; - use crate::parser::parse_str; + use super::parse_str; #[test] fn it_deserializes_thin_edge_json() -> anyhow::Result<()> { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = r#"{ "time" : "2021-04-30T17:03:14.123+02:00", "pressure": 123.4, @@ -333,7 +333,7 @@ mod tests { #[test] fn it_shows_input_excerpt_on_error() { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = "{\n\"time\" : null\n}"; @@ -349,7 +349,7 @@ mod tests { #[test] fn it_accepts_unix_timestamps_in_place_of_iso_8601() { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = "{\n\"time\" : 1701949168,\n\"test\": 1023}"; let expected_timestamp = OffsetDateTime::parse( @@ -367,7 +367,7 @@ mod tests { #[test] fn it_accepts_decimals_as_unix_timestamps() { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = "{\n\"time\" : 1701949168.001,\n\"test\": 1023}"; let expected_timestamp = OffsetDateTime::parse( @@ -385,7 +385,7 @@ mod tests { #[test] fn it_produces_a_clear_error_message_when_unix_timestamp_is_out_of_range() { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = "{\n\"time\" : -377705116801,\n\"test\": 1023}"; let mut builder = ThinEdgeJsonBuilder::default(); @@ -400,7 +400,7 @@ mod tests { #[test] fn parse_type_as_measurement() { - use crate::builder::ThinEdgeJsonBuilder; + use crate::measurement::builder::ThinEdgeJsonBuilder; let input = r#"{ "time" : "2021-04-30T17:03:14.123+02:00", diff --git a/crates/core/tedge_api/src/serialize.rs b/crates/core/tedge_api/src/measurement/serialize.rs similarity index 100% rename from crates/core/tedge_api/src/serialize.rs rename to crates/core/tedge_api/src/measurement/serialize.rs diff --git a/crates/core/tedge_api/src/utils.rs b/crates/core/tedge_api/src/measurement/utils.rs similarity index 100% rename from crates/core/tedge_api/src/utils.rs rename to crates/core/tedge_api/src/measurement/utils.rs diff --git a/crates/core/tedge_api/tests/test_suite.rs b/crates/core/tedge_api/tests/test_suite.rs index 0168d2b57a7..b3f2c9e9135 100644 --- a/crates/core/tedge_api/tests/test_suite.rs +++ b/crates/core/tedge_api/tests/test_suite.rs @@ -11,10 +11,10 @@ fn it_rejects_invalid_thin_edge_json() -> anyhow::Result<()> { println!("Fixture: {:?}", fixture.path()); let res: anyhow::Result<_> = { - let mut builder = tedge_api::builder::ThinEdgeJsonBuilder::default(); - tedge_api::parser::parse_str(&input, &mut builder) + let mut builder = tedge_api::measurement::ThinEdgeJsonSerializer::new(); + tedge_api::measurement::parse_str(&input, &mut builder) .map_err(Into::into) - .and_then(|_| builder.done().map_err(Into::into)) + .and_then(|_| builder.into_string().map_err(Into::into)) }; let err_msg = res.unwrap_err().to_string(); @@ -43,8 +43,8 @@ fn it_transforms_valid_thin_edge_json() -> anyhow::Result<()> { let input = std::fs::read_to_string(fixture.path())?; let output = { - let mut builder = tedge_api::serialize::ThinEdgeJsonSerializer::new(); - let res = tedge_api::parser::parse_str(&input, &mut builder); + let mut builder = tedge_api::measurement::ThinEdgeJsonSerializer::new(); + let res = tedge_api::measurement::parse_str(&input, &mut builder); assert!(res.is_ok()); builder.into_string()? }; diff --git a/crates/extensions/aws_mapper_ext/src/error.rs b/crates/extensions/aws_mapper_ext/src/error.rs index ff6f66721f4..ffeccf64b1e 100644 --- a/crates/extensions/aws_mapper_ext/src/error.rs +++ b/crates/extensions/aws_mapper_ext/src/error.rs @@ -1,4 +1,4 @@ -use tedge_api::serialize::ThinEdgeJsonSerializationError; +use tedge_api::measurement::ThinEdgeJsonSerializationError; use tedge_mqtt_ext::MqttError; #[derive(Debug, thiserror::Error)] @@ -7,7 +7,7 @@ pub enum ConversionError { FromThinEdgeJsonSerialization(#[from] ThinEdgeJsonSerializationError), #[error(transparent)] - FromThinEdgeJsonParser(#[from] tedge_api::parser::ThinEdgeJsonParserError), + FromThinEdgeJsonParser(#[from] tedge_api::measurement::ThinEdgeJsonParserError), #[error("The size of the message received on {topic} is {actual_size} which is greater than the threshold size of {threshold}.")] SizeThresholdExceeded { diff --git a/crates/extensions/c8y_mapper_ext/src/error.rs b/crates/extensions/c8y_mapper_ext/src/error.rs index 562fc115d94..896773e1807 100644 --- a/crates/extensions/c8y_mapper_ext/src/error.rs +++ b/crates/extensions/c8y_mapper_ext/src/error.rs @@ -6,7 +6,7 @@ use c8y_http_proxy::messages::C8YRestError; use plugin_sm::operation_logs::OperationLogsError; use std::path::PathBuf; use tedge_api::entity_store::InvalidExternalIdError; -use tedge_api::serialize::ThinEdgeJsonSerializationError; +use tedge_api::measurement::ThinEdgeJsonSerializationError; use tedge_config::TEdgeConfigError; use tedge_mqtt_ext::MqttError; use tedge_utils::file::FileError; @@ -59,7 +59,7 @@ pub enum ConversionError { ), #[error(transparent)] - FromThinEdgeJsonParser(#[from] tedge_api::parser::ThinEdgeJsonParserError), + FromThinEdgeJsonParser(#[from] tedge_api::measurement::ThinEdgeJsonParserError), #[error(transparent)] SizeThresholdExceeded(#[from] SizeThresholdExceededError), diff --git a/crates/extensions/c8y_mapper_ext/src/json.rs b/crates/extensions/c8y_mapper_ext/src/json.rs index 56b3386c16f..aa6cd58c7a8 100644 --- a/crates/extensions/c8y_mapper_ext/src/json.rs +++ b/crates/extensions/c8y_mapper_ext/src/json.rs @@ -19,7 +19,7 @@ use crate::serializer; use clock::Clock; use clock::WallClock; use tedge_api::entity_store::EntityMetadata; -use tedge_api::parser::*; +use tedge_api::measurement::*; use time::OffsetDateTime; use time::{self}; diff --git a/crates/extensions/collectd_ext/src/batcher.rs b/crates/extensions/collectd_ext/src/batcher.rs index 1f108c9f5d6..094af4bc487 100644 --- a/crates/extensions/collectd_ext/src/batcher.rs +++ b/crates/extensions/collectd_ext/src/batcher.rs @@ -1,9 +1,9 @@ use clock::Timestamp; -use tedge_api::group::MeasurementGroup; -use tedge_api::group::MeasurementGrouper; -use tedge_api::group::MeasurementGrouperError; +use tedge_api::measurement::MeasurementGroup; +use tedge_api::measurement::MeasurementGrouper; +use tedge_api::measurement::MeasurementGrouperError; use tedge_api::measurement::MeasurementVisitor; -use tedge_api::serialize::ThinEdgeJsonSerializer; +use tedge_api::measurement::ThinEdgeJsonSerializer; use tedge_mqtt_ext::MqttMessage; use tedge_mqtt_ext::Topic; diff --git a/crates/extensions/collectd_ext/src/error.rs b/crates/extensions/collectd_ext/src/error.rs index cfffc9f670c..df4133b50ab 100644 --- a/crates/extensions/collectd_ext/src/error.rs +++ b/crates/extensions/collectd_ext/src/error.rs @@ -11,15 +11,15 @@ pub enum DeviceMonitorError { FromInvalidCollectdMeasurement(#[from] crate::collectd::CollectdError), #[error(transparent)] - FromInvalidThinEdgeJson(#[from] tedge_api::group::MeasurementGrouperError), + FromInvalidThinEdgeJson(#[from] tedge_api::measurement::MeasurementGrouperError), #[error(transparent)] FromThinEdgeJsonSerializationError( - #[from] tedge_api::serialize::ThinEdgeJsonSerializationError, + #[from] tedge_api::measurement::ThinEdgeJsonSerializationError, ), #[error(transparent)] - FromBatchingError(#[from] SendError), + FromBatchingError(#[from] SendError), } impl From for RuntimeError {