use serde::{Deserialize, Serialize};
use crate::protocol::JsonMessage;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "op", rename = "serviceCallFailure", rename_all = "camelCase")]
pub struct ServiceCallFailure {
pub service_id: u32,
pub call_id: u32,
pub message: String,
}
impl ServiceCallFailure {
pub fn new(service_id: u32, call_id: u32, message: impl Into<String>) -> Self {
Self {
service_id,
call_id,
message: message.into(),
}
}
}
impl JsonMessage for ServiceCallFailure {}
#[cfg(test)]
mod tests {
use super::*;
fn message() -> ServiceCallFailure {
ServiceCallFailure {
service_id: 1,
call_id: 1,
message: "Service does not exist".into(),
}
}
#[test]
fn test_encode() {
insta::assert_json_snapshot!(message());
}
#[test]
fn test_roundtrip() {
let orig = message();
let buf = orig.to_string();
let parsed: ServiceCallFailure = serde_json::from_str(&buf).unwrap();
assert_eq!(parsed, orig);
}
}