add all crates: domain, protocol, application, client, adapters, ESP32 firmware
Server: domain (entities, value objects, ports), protocol (postcard wire types), application (config service, data projection), adapters (config-memory, tcp-server), bootstrap (composition root with fake data). Client: client-domain (layout engine, render tree, HAL ports), client-application (message handling, repaint commands), adapters (tcp-client, display-terminal), client-desktop (end-to-end working). ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking. Display test verified on hardware — landscape orientation, text rendering works. 60 workspace tests, all passing.
This commit is contained in:
58
crates/domain/src/value_objects/value.rs
Normal file
58
crates/domain/src/value_objects/value.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Value {
|
||||
Null,
|
||||
Bool(bool),
|
||||
Number(f64),
|
||||
String(String),
|
||||
Array(Vec<Value>),
|
||||
Object(BTreeMap<String, Value>),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
pub fn estimated_size(&self) -> usize {
|
||||
match self {
|
||||
Value::Null | Value::Bool(_) => 1,
|
||||
Value::Number(_) => 8,
|
||||
Value::String(s) => s.len(),
|
||||
Value::Array(arr) => arr.iter().map(|v| v.estimated_size()).sum(),
|
||||
Value::Object(map) => map
|
||||
.iter()
|
||||
.map(|(k, v)| k.len() + v.estimated_size())
|
||||
.sum(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_path(&self, path: &str) -> Option<&Value> {
|
||||
let path = path.strip_prefix("$").unwrap_or(path);
|
||||
let mut current = self;
|
||||
|
||||
for raw_segment in path.split('.').filter(|s| !s.is_empty()) {
|
||||
if let Some(bracket_pos) = raw_segment.find('[') {
|
||||
let key = &raw_segment[..bracket_pos];
|
||||
let index_str = raw_segment[bracket_pos + 1..].strip_suffix(']')?;
|
||||
let index: usize = index_str.parse().ok()?;
|
||||
|
||||
if !key.is_empty() {
|
||||
match current {
|
||||
Value::Object(map) => current = map.get(key)?,
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
|
||||
match current {
|
||||
Value::Array(arr) => current = arr.get(index)?,
|
||||
_ => return None,
|
||||
}
|
||||
} else {
|
||||
match current {
|
||||
Value::Object(map) => current = map.get(raw_segment)?,
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(current)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user