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:
232
crates/protocol/src/wire.rs
Normal file
232
crates/protocol/src/wire.rs
Normal file
@@ -0,0 +1,232 @@
|
||||
use std::collections::BTreeMap;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use domain::value_objects::{
|
||||
ContainerNode, Direction, DisplayHint, LayoutChild, LayoutNode, Sizing, Value,
|
||||
WidgetError, WidgetState,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireValue {
|
||||
Null,
|
||||
Bool(bool),
|
||||
Number(f64),
|
||||
String(String),
|
||||
Array(Vec<WireValue>),
|
||||
Object(BTreeMap<String, WireValue>),
|
||||
}
|
||||
|
||||
impl From<&Value> for WireValue {
|
||||
fn from(v: &Value) -> Self {
|
||||
match v {
|
||||
Value::Null => WireValue::Null,
|
||||
Value::Bool(b) => WireValue::Bool(*b),
|
||||
Value::Number(n) => WireValue::Number(*n),
|
||||
Value::String(s) => WireValue::String(s.clone()),
|
||||
Value::Array(arr) => WireValue::Array(arr.iter().map(Into::into).collect()),
|
||||
Value::Object(map) => {
|
||||
WireValue::Object(map.iter().map(|(k, v)| (k.clone(), v.into())).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireValue> for Value {
|
||||
fn from(w: WireValue) -> Self {
|
||||
match w {
|
||||
WireValue::Null => Value::Null,
|
||||
WireValue::Bool(b) => Value::Bool(b),
|
||||
WireValue::Number(n) => Value::Number(n),
|
||||
WireValue::String(s) => Value::String(s),
|
||||
WireValue::Array(arr) => Value::Array(arr.into_iter().map(Into::into).collect()),
|
||||
WireValue::Object(map) => {
|
||||
Value::Object(map.into_iter().map(|(k, v)| (k, v.into())).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireWidgetError {
|
||||
SourceUnavailable,
|
||||
ExtractionFailed,
|
||||
}
|
||||
|
||||
impl From<&WidgetError> for WireWidgetError {
|
||||
fn from(e: &WidgetError) -> Self {
|
||||
match e {
|
||||
WidgetError::SourceUnavailable => WireWidgetError::SourceUnavailable,
|
||||
WidgetError::ExtractionFailed => WireWidgetError::ExtractionFailed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireWidgetError> for WidgetError {
|
||||
fn from(w: WireWidgetError) -> Self {
|
||||
match w {
|
||||
WireWidgetError::SourceUnavailable => WidgetError::SourceUnavailable,
|
||||
WireWidgetError::ExtractionFailed => WidgetError::ExtractionFailed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireKeyValue {
|
||||
pub key: String,
|
||||
pub value: WireValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireWidgetState {
|
||||
pub data: Vec<WireKeyValue>,
|
||||
pub error: Option<WireWidgetError>,
|
||||
}
|
||||
|
||||
impl From<&WidgetState> for WireWidgetState {
|
||||
fn from(s: &WidgetState) -> Self {
|
||||
WireWidgetState {
|
||||
data: s.data.iter().map(|(k, v)| WireKeyValue {
|
||||
key: k.clone(),
|
||||
value: v.into(),
|
||||
}).collect(),
|
||||
error: s.error.as_ref().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireWidgetState> for WidgetState {
|
||||
fn from(w: WireWidgetState) -> Self {
|
||||
WidgetState {
|
||||
data: w.data.into_iter().map(|kv| (kv.key, kv.value.into())).collect(),
|
||||
error: w.error.map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireDisplayHint {
|
||||
IconValue,
|
||||
TextBlock,
|
||||
KeyValue,
|
||||
}
|
||||
|
||||
impl From<&DisplayHint> for WireDisplayHint {
|
||||
fn from(h: &DisplayHint) -> Self {
|
||||
match h {
|
||||
DisplayHint::IconValue => WireDisplayHint::IconValue,
|
||||
DisplayHint::TextBlock => WireDisplayHint::TextBlock,
|
||||
DisplayHint::KeyValue => WireDisplayHint::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDisplayHint> for DisplayHint {
|
||||
fn from(w: WireDisplayHint) -> Self {
|
||||
match w {
|
||||
WireDisplayHint::IconValue => DisplayHint::IconValue,
|
||||
WireDisplayHint::TextBlock => DisplayHint::TextBlock,
|
||||
WireDisplayHint::KeyValue => DisplayHint::KeyValue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireSizing {
|
||||
Fixed(u16),
|
||||
Flex(u8),
|
||||
}
|
||||
|
||||
impl From<&Sizing> for WireSizing {
|
||||
fn from(s: &Sizing) -> Self {
|
||||
match s {
|
||||
Sizing::Fixed(px) => WireSizing::Fixed(*px),
|
||||
Sizing::Flex(w) => WireSizing::Flex(*w),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireSizing> for Sizing {
|
||||
fn from(w: WireSizing) -> Self {
|
||||
match w {
|
||||
WireSizing::Fixed(px) => Sizing::Fixed(px),
|
||||
WireSizing::Flex(weight) => Sizing::Flex(weight),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireDirection {
|
||||
Row,
|
||||
Column,
|
||||
}
|
||||
|
||||
impl From<&Direction> for WireDirection {
|
||||
fn from(d: &Direction) -> Self {
|
||||
match d {
|
||||
Direction::Row => WireDirection::Row,
|
||||
Direction::Column => WireDirection::Column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireDirection> for Direction {
|
||||
fn from(w: WireDirection) -> Self {
|
||||
match w {
|
||||
WireDirection::Row => Direction::Row,
|
||||
WireDirection::Column => Direction::Column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireContainerNode {
|
||||
pub direction: WireDirection,
|
||||
pub gap: u8,
|
||||
pub padding: u8,
|
||||
pub children: Vec<WireLayoutChild>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct WireLayoutChild {
|
||||
pub sizing: WireSizing,
|
||||
pub node: WireLayoutNode,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum WireLayoutNode {
|
||||
Container(WireContainerNode),
|
||||
Leaf(u16),
|
||||
}
|
||||
|
||||
impl From<&LayoutNode> for WireLayoutNode {
|
||||
fn from(n: &LayoutNode) -> Self {
|
||||
match n {
|
||||
LayoutNode::Leaf(id) => WireLayoutNode::Leaf(*id),
|
||||
LayoutNode::Container(c) => WireLayoutNode::Container(WireContainerNode {
|
||||
direction: (&c.direction).into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
children: c.children.iter().map(|ch| WireLayoutChild {
|
||||
sizing: (&ch.sizing).into(),
|
||||
node: (&ch.node).into(),
|
||||
}).collect(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WireLayoutNode> for LayoutNode {
|
||||
fn from(w: WireLayoutNode) -> Self {
|
||||
match w {
|
||||
WireLayoutNode::Leaf(id) => LayoutNode::Leaf(id),
|
||||
WireLayoutNode::Container(c) => LayoutNode::Container(ContainerNode {
|
||||
direction: c.direction.into(),
|
||||
gap: c.gap,
|
||||
padding: c.padding,
|
||||
children: c.children.into_iter().map(|ch| LayoutChild {
|
||||
sizing: ch.sizing.into(),
|
||||
node: ch.node.into(),
|
||||
}).collect(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user