feat(protocol): add StateBlob, the opaque payload of ApplyState

A transparent wrapper of serde_json::Value with a hand written schema (an object, named State), so that SocketMessage can carry ApplyState without the crate knowing the daemon's State type (D15/D16). On the wire it is exactly the state JSON.

Verified: native cargo test -p komorebi-protocol: 5 unit + 3 golden + 1 doctest passed, 0 failed.
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:53 -07:00
1 parent 5c129ab59d
commit d3ecfb0acb
1 file changed
+38 -1
+38 -1
View File
@@ -1 +1,38 @@
//! Placeholder: filled in by a later step 2 revision.
//! `SocketMessage`, the one message type of every komorebi socket.
use serde::Deserialize;
use serde::Serialize;
/// A state of the window manager as the JSON that `ApplyState` carries.
///
/// The daemon that handles `ApplyState` (Windows only) reads it into its own `State` type, which
/// does not live in this crate. On the wire it is exactly that state: the type is transparent.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct StateBlob(pub serde_json::Value);
#[cfg(feature = "schemars")]
impl schemars::JsonSchema for StateBlob {
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("State")
}
fn json_schema(_generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"description": "The state of the window manager, as `komorebic state` prints it",
"type": "object"
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_state_blob_is_written_and_read_as_the_json_it_holds() {
let text = r#"{"monitors":{"elements":[]}}"#;
let blob: StateBlob = serde_json::from_str(text).unwrap();
assert_eq!(serde_json::to_string(&blob).unwrap(), text);
}
}