Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove oneof and ValueFailure from Datapoint and some proto naming improvements #72

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions databroker-cli/src/kuksa_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
Err(err) => {
cli::print_error(cmd, &format!("Malformed token: {err}"))?
cli::print_error(cmd, format!("Malformed token: {err}"))?
}
}
}
Expand Down Expand Up @@ -350,12 +350,12 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
Err(err) => {
cli::print_error(cmd, &format!("Malformed token: {err}"))?
cli::print_error(cmd, format!("Malformed token: {err}"))?
}
},
Err(err) => cli::print_error(
cmd,
&format!(
format!(
"Failed to open token file \"{token_filename}\": {err}"
),
)?,
Expand Down
6 changes: 3 additions & 3 deletions databroker-cli/src/sdv_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
Err(err) => {
cli::print_error(cmd, &format!("Malformed token: {err}"))?
cli::print_error(cmd, format!("Malformed token: {err}"))?
}
}
}
Expand Down Expand Up @@ -295,12 +295,12 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
}
Err(err) => {
cli::print_error(cmd, &format!("Malformed token: {err}"))?
cli::print_error(cmd, format!("Malformed token: {err}"))?
}
},
Err(err) => cli::print_error(
cmd,
&format!(
format!(
"Failed to open token file \"{token_filename}\": {err}"
),
)?,
Expand Down
2 changes: 1 addition & 1 deletion databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::permissions::{PermissionError, Permissions};
pub use crate::types;

use crate::query;
pub use crate::types::{ChangeType, DataType, DataValue, EntryType, ValueFailure};
pub use crate::types::{ChangeType, DataType, DataValue, EntryType};

use tokio::sync::{broadcast, mpsc, RwLock};
use tokio_stream::wrappers::ReceiverStream;
Expand Down
128 changes: 50 additions & 78 deletions databroker/src/grpc/kuksa_val_v2/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// * SPDX-License-Identifier: Apache-2.0
// ********************************************************************************/
use databroker_proto::kuksa::val::v2 as proto;
use proto::datapoint::{ValueState::Failure, ValueState::Value};

use crate::broker;

Expand Down Expand Up @@ -48,151 +47,125 @@ impl From<broker::Datapoint> for Option<proto::Datapoint> {
match from.value {
broker::DataValue::NotAvailable => None,
broker::DataValue::Bool(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Bool(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Bool(value)),
}),
}),
broker::DataValue::String(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::String(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::String(value)),
}),
}),
broker::DataValue::Int32(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Int32(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Int32(value)),
}),
}),
broker::DataValue::Int64(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Int64(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Int64(value)),
}),
}),
broker::DataValue::Uint32(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint32(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint32(value)),
}),
}),
broker::DataValue::Uint64(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint64(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint64(value)),
}),
}),
broker::DataValue::Float(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Float(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Float(value)),
}),
}),
broker::DataValue::Double(value) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
typed_value: Some(proto::value::TypedValue::Double(value)),
})),
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Double(value)),
}),
}),
broker::DataValue::BoolArray(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::BoolArray(proto::BoolArray {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::StringArray(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::StringArray(proto::StringArray {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::Int32Array(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Int32Array(proto::Int32Array {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::Int64Array(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Int64Array(proto::Int64Array {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::Uint32Array(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint32Array(proto::Uint32Array {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::Uint64Array(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::Uint64Array(proto::Uint64Array {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::FloatArray(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::FloatArray(proto::FloatArray {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
broker::DataValue::DoubleArray(values) => Some(proto::Datapoint {
value_state: Some(proto::datapoint::ValueState::Value(proto::Value {
timestamp: Some(from.ts.into()),
value: Some(proto::Value {
typed_value: Some(proto::value::TypedValue::DoubleArray(proto::DoubleArray {
values,
})),
})),
timestamp: Some(from.ts.into()),
}),
}),
}
}
}

impl From<&broker::ValueFailure> for i32 {
fn from(from: &broker::ValueFailure) -> Self {
match from {
broker::ValueFailure::Unspecified => 0,
broker::ValueFailure::InvalidValue => 1,
broker::ValueFailure::NotProvided => 2,
broker::ValueFailure::UnknownSignal => 3,
broker::ValueFailure::AccessDenied => 4,
broker::ValueFailure::InternalError => 5,
}
}
}

impl From<&proto::ValueFailure> for broker::ValueFailure {
fn from(value_failure: &proto::ValueFailure) -> Self {
match value_failure {
proto::ValueFailure::Unspecified => broker::ValueFailure::Unspecified,
proto::ValueFailure::InvalidValue => broker::ValueFailure::InvalidValue,
proto::ValueFailure::NotProvided => broker::ValueFailure::NotProvided,
proto::ValueFailure::UnknownSignal => broker::ValueFailure::UnknownSignal,
proto::ValueFailure::AccessDenied => broker::ValueFailure::AccessDenied,
proto::ValueFailure::InternalError => broker::ValueFailure::InternalError,
}
}
}

impl From<&proto::Datapoint> for broker::DataValue {
fn from(datapoint: &proto::Datapoint) -> Self {
match &datapoint.value_state {
Some(Value(value)) => match &value.typed_value {
match &datapoint.value {
Some(value) => match &value.typed_value {
Some(proto::value::TypedValue::String(value)) => {
broker::DataValue::String(value.to_owned())
}
Expand Down Expand Up @@ -229,7 +202,6 @@ impl From<&proto::Datapoint> for broker::DataValue {
}
None => broker::DataValue::NotAvailable,
},
Some(Failure(_)) => broker::DataValue::NotAvailable,
None => broker::DataValue::NotAvailable,
}
}
Expand Down
Loading