Skip to content

Commit

Permalink
Add value restriction metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling authored and erikbosch committed Oct 3, 2024
1 parent 0ad49db commit ea34809
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 1 deletion.
93 changes: 93 additions & 0 deletions databroker/src/grpc/kuksa_val_v2/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,99 @@ impl From<&proto::Datapoint> for broker::DataValue {
}
}

impl From<&broker::Metadata> for proto::Metadata {
fn from(metadata: &broker::Metadata) -> Self {
proto::Metadata {
id: metadata.id,
data_type: proto::DataType::from(metadata.data_type.clone()) as i32,
entry_type: proto::EntryType::from(metadata.entry_type.clone()) as i32,
description: Some(metadata.description.clone()),
comment: None,
deprecation: None,
unit: metadata.unit.clone(),
value_restriction: match metadata.allowed.as_ref() {
Some(allowed) => match allowed {
broker::DataValue::StringArray(vec) => Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::String(
proto::ValueRestrictionString {
allowed_values: vec.clone(),
},
)),
}),
broker::DataValue::Int32Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec.iter().cloned().map(i64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
broker::DataValue::Int64Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
broker::DataValue::Uint32Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec.iter().cloned().map(u64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
broker::DataValue::Uint64Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
broker::DataValue::FloatArray(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec.iter().cloned().map(f64::from).collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
broker::DataValue::DoubleArray(vec) => {
Some(proto::ValueRestriction {
r#type: Some(proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
)),
})
}
_ => None,
},
None => None,
},
}
}
}

impl From<&broker::UpdateError> for proto::Error {
fn from(update_error: &broker::UpdateError) -> Self {
match update_error {
Expand Down
108 changes: 107 additions & 1 deletion databroker/src/grpc/kuksa_val_v2/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,113 @@ impl proto::val_server::Val for broker::DataBroker {
comment: None,
deprecation: None,
unit: entry_metadata.unit.clone(),
value_restriction: None,
value_restriction: match entry.metadata().allowed.as_ref() {
Some(allowed) => match allowed {
broker::DataValue::StringArray(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::String(
proto::ValueRestrictionString {
allowed_values: vec.clone(),
},
),
),
})
}
broker::DataValue::Int32Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec
.iter()
.cloned()
.map(i64::from)
.collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
broker::DataValue::Int64Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::Signed(
proto::ValueRestrictionInt {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
broker::DataValue::Uint32Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec
.iter()
.cloned()
.map(u64::from)
.collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
broker::DataValue::Uint64Array(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::Unsigned(
proto::ValueRestrictionUint {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
broker::DataValue::FloatArray(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec
.iter()
.cloned()
.map(f64::from)
.collect(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
broker::DataValue::DoubleArray(vec) => {
Some(proto::ValueRestriction {
r#type: Some(
proto::value_restriction::Type::FloatingPoint(
proto::ValueRestrictionFloat {
allowed_values: vec.clone(),
min: None, // TODO: Implement
max: None, // TODO: Implement
},
),
),
})
}
_ => None,
},
None => None,
},
})
}
})
Expand Down

0 comments on commit ea34809

Please sign in to comment.