src/proto.rs
use std::{ffi::CStr, fmt::Display};
use elvwf::prelude::*;
use elvwlc_derive::WlMsg;
pub trait WlOpCode {
const OP_CODE: u64;
}
#[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 Display for WlString<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.value.to_str().ok().unwrap_or_else(|| "<NON UTF8>"))
}
}
impl<'a> From<&'a CStr> for WlString<'a> {
fn from(value: &'a CStr) -> Self {
Self { value }
}
}
#[derive(Wired, Debug)]
pub struct WlUnknowHeader {
#[wf(value(format = Le))]
pub id: u32,
#[wf(value(format = Le))]
pub op: u16,
#[wf(value(format = Le))]
pub len: u16,
}
#[derive(Wired, Debug)]
#[wf(header(dsl = "S:16|OP:16=T::OP_CODE|ID:32", format = Le, offset = { 8 << 48 }))]
pub struct WlMsg<T: WlOpCode> {
#[wf(value(slot = ID))]
id: u32,
#[wf(len(slot = S))]
payload: T,
}
impl<T: WlOpCode> WlMsg<T> {
pub fn new(id: u32, payload: T) -> Self {
Self { id, payload }
}
pub fn id(&self) -> u32 {
self.id
}
pub fn payload(&self) -> &T {
&self.payload
}
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 0)]
pub struct WlDisplaySync {
#[wf(value(format = Ne))]
pub new_callback: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 1)]
pub struct WlDisplayGetRegistry {
#[wf(value(format = Ne))]
pub new_registry: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 2)]
pub struct WlDisplayError<'a> {
#[wf(value(format = Ne))]
pub object_id: u32,
#[wf(value(format = Ne))]
pub code: u32,
#[wf(len(embedded))]
pub message: WlString<'a>,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 3)]
pub struct WlDisplayIdDeleted {
#[wf(value(format = Ne))]
pub id: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 0)]
pub struct WlRegistryBind<'a> {
#[wf(value(format = Ne))]
pub global_id: u32,
#[wf(len(embedded))]
pub global_name: WlString<'a>,
#[wf(value(format = Ne))]
pub global_version: u32,
#[wf(value(format = Ne))]
pub new_id: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 1)]
pub struct WlRegistryGlobal<'a> {
#[wf(value(format = Ne))]
pub id: u32,
#[wf(len(embedded))]
pub name: WlString<'a>,
#[wf(value(format = Ne))]
pub version: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 2)]
pub struct WlRegistryGlobalRemoved {
#[wf(value(format = Ne))]
pub id: u32,
}
#[derive(WlMsg, Wired, Debug)]
#[wlc(op = 0)]
pub struct WlCallbackDone {
#[wf(value(format = Ne))]
pub callback_data: u32,
}