examples
examples/wayland.rs
use std::ffi::CStr;
use elvwf::prelude::*;
#[derive(Wired, Debug)]
#[wf(header(dsl = "S:32", format = Ne))]
#[wf(align = u32)]
pub struct WlString<'a> {
#[wf(len(slot = S))]
value: &'a CStr,
}
impl<'a> From<&'a CStr> for WlString<'a> {
fn from(value: &'a CStr) -> Self {
Self { value }
}
}
#[derive(Wired, Debug)]
#[wf(header(dsl = "S:16|OP:16=0|ID:32", format = Le, offset = { 8 << 48 }))]
pub struct WlRegistryBind<'a> {
#[wf(value(slot = ID))]
id: u32,
#[wf(len(slot = S))]
payload: WlRegistryBindPayload<'a>,
}
#[derive(Wired, Debug)]
pub struct WlRegistryBindPayload<'a> {
#[wf(value(format = Le))]
interface_id: u32,
#[wf(len(embedded))]
interface_name: WlString<'a>,
#[wf(value(format = Le))]
interface_version: u32,
#[wf(value(format = Le))]
new_id: u32,
}
fn main() {
let msg = WlRegistryBind {
id: 0x2,
payload: WlRegistryBindPayload {
interface_id: 1,
interface_name: c"wl_compositor".into(),
interface_version: 3,
new_id: 3,
},
};
let mut data = [0u8; 64];
let buf = &mut &mut data[..];
msg::encode_value::<WlRegistryBind>(buf, msg).unwrap();
let len = 64 - buf.len();
let buf = &mut &data[..len];
println!("<{len}> {:?}", buf);
let value = msg::decode_value::<WlRegistryBind>(buf, 8).unwrap();
println!("{:?}", value);
}