use rmk_types::protocol::rynk::command::Endpoint;
use rmk_types::protocol::rynk::{RynkError, RynkMessage};
mod behavior;
mod bulk;
mod combo;
mod connection;
mod fork;
mod keymap;
mod layout;
mod macro_data;
mod morse;
mod status;
mod system;
pub(super) trait Handle<E: Endpoint> {
async fn handle(&self, req: E::Request) -> Result<E::Response, RynkError>;
}
pub(super) trait HandleBulk<E: Endpoint> {
async fn handle_bulk(&self, msg: &mut RynkMessage<'_>) -> Result<(), RynkError>;
}
pub(super) async fn serve<E: Endpoint, T: Handle<E>>(h: &T, msg: &mut RynkMessage<'_>) -> Result<(), RynkError> {
let req = msg.decode_request::<E::Request>()?;
let resp = h.handle(req).await?;
msg.encode_response(&resp)
}
pub(super) async fn serve_bulk<E: Endpoint, T: HandleBulk<E>>(
h: &T,
msg: &mut RynkMessage<'_>,
) -> Result<(), RynkError> {
h.handle_bulk(msg).await
}