use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "client_objectiveai_mcp.server_response.Response")]
pub struct Response {
pub id: String,
#[serde(flatten)]
pub payload: super::Payload,
}
impl Response {
pub fn mcp_kind(&self) -> Option<super::super::McpKind> {
self.payload.mcp_kind()
}
pub fn to_wire(
&self,
) -> Result<crate::binary_frame::WireFrame, serde_json::Error> {
let header = serde_json::to_string(self)?;
Ok(match &self.payload {
super::Payload::LaboratoryExportRead(super::JsonRpcResult::Ok {
result,
}) => crate::binary_frame::WireFrame::Binary(
crate::binary_frame::encode(&header, &result.data),
),
_ => crate::binary_frame::WireFrame::Text(header),
})
}
pub fn from_binary(frame: &[u8]) -> Option<Self> {
let (header, payload) = crate::binary_frame::decode(frame)?;
let mut parsed: Self = serde_json::from_str(header).ok()?;
match &mut parsed.payload {
super::Payload::LaboratoryExportRead(super::JsonRpcResult::Ok {
result,
}) => {
result.data = payload.to_vec();
Some(parsed)
}
_ => None,
}
}
}