1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use async_trait::async_trait;
4use crate::error::RpcResult;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Command {
8 pub command: String,
9 pub args: Vec<serde_json::Value>,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct CommandResponse {
14 pub success: bool,
15 pub result: Option<serde_json::Value>,
16 pub error: Option<String>,
17}
18
19#[async_trait]
20pub trait CommandHandler: Send + Sync {
21 async fn handle(&self, command: &str, args: Vec<serde_json::Value>) -> RpcResult<serde_json::Value>;
22}
23
24pub type CommandHandlers = HashMap<String, Box<dyn CommandHandler>>;
25
26#[derive(Debug, Clone)]
27pub struct RpcMessage {
28 pub content: Vec<u8>,
29 pub correlation_id: String,
30 pub reply_queue: Option<String>,
31 pub delivery_tag: u64,
32}