updater_thread now works and we listen on unix_socket

This commit is contained in:
Sebastian Moser
2024-06-19 21:50:52 +02:00
parent 7340aaa37a
commit 053742f849
19 changed files with 797 additions and 413 deletions

View File

@@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::iter::Map;
use std::sync::{Arc, Mutex};
use ciborium::Value as CborValue;
use log::trace;
use tracing::{instrument, trace};
use colored::Colorize;
use crate::id::MizeId;
@@ -11,6 +11,7 @@ use crate::instance::store::{Store, IdIter};
use crate::error::{MizeError, MizeResult, IntoMizeResult};
use crate::item::{Item, ItemData};
use crate::instance::Instance;
use crate::item::get_raw_from_cbor;
#[derive(Clone, Debug)]
pub struct MemStore {
@@ -49,7 +50,9 @@ impl Store for MemStore {
inner.next_id += 1;
return Ok(id_string);
}
#[instrument(name="MemStore::get_value_raw" skip(self))]
fn get_value_raw(&self, id: MizeId) -> MizeResult<Vec<u8>> {
trace!("[ {} ] id: {:?}", "ARG".yellow(), id);
let inner = self.inner.lock()?;
let cbor_val = inner.map.get(&id_to_u64(id.clone())?)
@@ -131,74 +134,6 @@ fn str_to_u64(id_str: &str) -> MizeResult<u64> {
.mize_result_msg(format!("Could not parse the store_part of mizeid {} into a u64 for the MemStore", id_str))
}
pub fn get_raw_from_cbor<'a>(value: &'a CborValue, path: Vec<&String>) -> MizeResult<&'a [u8]> {
trace!("[ {} ] get_raw_from_cbor()", "CALL".yellow());
trace!("[ {} ] value: {:?}", "ARG".yellow(), value);
trace!("[ {} ] path: {:?}", "ARG".yellow(), path);
let mut path_iter = path.clone().into_iter();
let path_el = match path_iter.nth(0) {
Some(val) => val,
None => {
// our base case
let ret_val = match value {
CborValue::Bytes(vec) => {
trace!("[ {} ] ret value: {:?}", "RET".yellow(), &vec[..]);
return Ok(&vec[..]);
},
CborValue::Text(string) => {
trace!("[ {} ] ret value: {:?}", "RET".yellow(), string.as_bytes());
return Ok(string.as_bytes());
},
other => {
return Err(MizeError::new()
.msg("path is empty and the value is neither Bytes nor Text"));
},
};
},
};
trace!("hoooooooo: {:?}", path_el);
match value {
CborValue::Bytes(vec) => {
trace!("[ {} ] ret value: {:?}", "RET".yellow(), &vec[..]);
return Ok(&vec[..]);
},
CborValue::Text(string) => {
trace!("[ {} ] ret value: {:?}", "RET".yellow(), string.as_bytes());
return Ok(string.as_bytes());
},
CborValue::Map(map) => {
let mut inner_val: &CborValue = &CborValue::Null;
let mut inner_val_found = false;
// find the inner_val at path
for (key, val) in map.into_iter() {
if let CborValue::Text(key_text) = key {
if key_text == path_el {
inner_val = val;
inner_val_found = true;
}
}
}
// if there is no value at that path
if inner_val_found == false {
return Err(MizeError::new()
// jesus christ, this is a pfusch...
.msg(format!("get_raw_from_cbor: Path '{}' not Found", path.clone().into_iter().map(|v| v.to_owned()).collect::<Vec<String>>().join("/"))))
}
//path_iter.next();
let inner_path = path_iter.collect();
trace!("hiiiiii: {:?}", inner_path);
let ret_value = get_raw_from_cbor(inner_val, inner_path);
trace!("[ {} ] ret value: {:?}", "RET".yellow(), ret_value);
return ret_value;
},
_ => Err(MizeError::new().msg("get_raw_from_cbor: value is not a map, text or bytes")),
}
}