Skip to content

Commit

Permalink
Update VSS parser
Browse files Browse the repository at this point in the history
Add support for parsing `min`, `max` & `allowed`.
  • Loading branch information
argerus authored and SebastianSchildt committed Jan 23, 2023
1 parent e8f4744 commit 373c4d1
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 306 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions databroker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ clap = { version = "3.1.10", default-features = false, features = [
"env",
] }
sqlparser = "0.16.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
Expand Down
21 changes: 7 additions & 14 deletions databroker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use std::fmt::Write;
use std::io::Read;

use tracing::{debug, info};
use tracing_subscriber::filter::EnvFilter;
Expand Down Expand Up @@ -143,21 +142,18 @@ async fn read_metadata_file(
) -> Result<(), Box<dyn std::error::Error>> {
let path = filename.trim();
info!("Populating metadata from file '{}'", path);
let mut metadata_file = std::fs::OpenOptions::new().read(true).open(path)?;
// metadata_file
let mut data = String::new();
metadata_file.read_to_string(&mut data)?;
let entries = vss::parse_vss(&data)?;
for entry in entries {
debug!("Adding VSS datapoint type {}", entry.name);
let metadata_file = std::fs::OpenOptions::new().read(true).open(filename)?;
let entries = vss::parse_vss_from_reader(&metadata_file)?;
for (path, entry) in entries {
debug!("Adding VSS datapoint type {}", path);

let id = broker
.add_entry(
entry.name.clone(),
path.clone(),
entry.data_type,
databroker::broker::ChangeType::OnChange,
entry.entry_type,
entry.description.unwrap_or_else(|| "".to_owned()),
entry.description,
)
.await;

Expand All @@ -179,10 +175,7 @@ async fn read_metadata_file(
if let Err(errors) = broker.update_entries(ids).await {
// There's only one error (since we're only trying to set one)
if let Some(error) = errors.get(0) {
info!(
"Failed to set default value for {}: {:?}",
entry.name, error.1
);
info!("Failed to set default value for {}: {:?}", path, error.1);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion databroker/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum DataType {
TimestampArray,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EntryType {
Sensor,
Attribute,
Expand Down
Loading

0 comments on commit 373c4d1

Please sign in to comment.