pub fn encode_property_changed(
path: &[u32],
prop_name: &str,
value: &Value,
) -> Vec<u8> ⓘExpand description
Encode a propertyChanged frame.
Examples found in repository?
examples/cli.rs (line 1153)
1122fn raw_request(
1123 writer: &Writer,
1124 layout: &Shared<Option<Layout>>,
1125 args: &[&str],
1126 raw: RawValue,
1127) -> Result<Outcome, String> {
1128 if args.len() < 3 {
1129 return Err("usage: raw-press|raw-release <source> <mix> <link|unlink> \
1130 OR raw-bool <source> <mix> <link|unlink> <on|off>"
1131 .into());
1132 }
1133 let source = parse_source(args[0])?;
1134 let mix = parse_mix(args[1])?;
1135 let property = match args[2] {
1136 "link" => "mixLinkRequest",
1137 "unlink" => "mixUnlinkRequest",
1138 other => return Err(format!("expected link|unlink, got {other}")),
1139 };
1140 let value = match raw {
1141 RawValue::Press => Value::Binary(vec![0x01, 0x01, 0x02, 0x01, 0x01, 0x02]),
1142 RawValue::Release => Value::Binary(vec![0x01, 0x01, 0x03, 0x01, 0x01, 0x03]),
1143 RawValue::Bool(b) => Value::Bool(b),
1144 };
1145 let layout_guard = layout.lock().unwrap();
1146 let layout_ref = layout_guard
1147 .as_ref()
1148 .ok_or_else(|| "no Layout yet".to_string())?;
1149 let path = layout_ref
1150 .mix_cell_path(source.to_protocol(), mix.to_protocol())
1151 .ok_or_else(|| "bad cell".to_string())?;
1152 drop(layout_guard);
1153 let body = change_frame::encode_property_changed(&path, property, &value);
1154 writer(body).map_err(|e| format!("write: {e}"))?;
1155 println!("sent 1 frame: {property} = {value:?}");
1156 Ok(Outcome::Continue)
1157}
1158
1159/// `raw-write <PATH> <PROP_NAME> <KIND> <VALUE...>`: send a raw
1160/// propertyChanged frame with arbitrary path, property name, and value.
1161/// PATH is comma-separated `u32`s (e.g. `359,0`). KIND is one of `int`,
1162/// `i64`, `bool`, `dbl`, `str`. For `str`, the remainder of the line is the
1163/// string (allowing spaces). This is the fuzzing / probing primitive:
1164/// bypasses every typed `Command` and lets you write anything to anywhere.
1165fn raw_write(writer: &Writer, args: &[&str]) -> Result<Outcome, String> {
1166 if args.len() < 3 {
1167 return Err(
1168 "usage: raw-write <path,commas,between,u32s> <prop_name> <kind> [<value...>] \
1169 (value defaults to empty for str)"
1170 .into(),
1171 );
1172 }
1173 let path: Vec<u32> = args[0]
1174 .split(',')
1175 .map(|s| s.trim().parse::<u32>())
1176 .collect::<Result<_, _>>()
1177 .map_err(|e| format!("bad path (need comma-separated u32s): {e}"))?;
1178 let prop_name = args[1];
1179 let kind = args[2].to_ascii_lowercase();
1180 let payload = args.get(3..).map(|s| s.join(" ")).unwrap_or_default();
1181 let value = match kind.as_str() {
1182 "int" => Value::Int(payload.parse::<i64>().map_err(|e| format!("int: {e}"))?),
1183 "i64" => Value::Int64(payload.parse::<i64>().map_err(|e| format!("i64: {e}"))?),
1184 "bool" => Value::Bool(parse_bool(&payload)?),
1185 "dbl" | "f64" | "double" => {
1186 Value::Double(payload.parse::<f64>().map_err(|e| format!("dbl: {e}"))?)
1187 }
1188 "str" | "string" => Value::String(payload),
1189 other => return Err(format!("unknown kind: {other}")),
1190 };
1191 let body = change_frame::encode_property_changed(&path, prop_name, &value);
1192 writer(body).map_err(|e| format!("write: {e}"))?;
1193 println!("sent raw {prop_name} = {value:?} at path {path:?}");
1194 Ok(Outcome::Continue)
1195}