Implement request response messaging

This commit is contained in:
2023-05-07 19:17:24 +02:00
parent b33795b4e0
commit 2b1d23722d
4 changed files with 117 additions and 18 deletions

View File

@ -26,6 +26,13 @@ impl TryFrom<Vec<u8>> for ChatMessage {
}
}
impl From<ChatMessage> for Vec<u8> {
fn from(value: ChatMessage) -> Self {
let json_string_utf8 = serde_json::to_string(&value).expect("Cannot serialize message");
json_string_utf8.into_bytes()
}
}
#[derive(Debug)]
pub enum NatsParsingError {
// Message was no string at all
@ -41,7 +48,7 @@ impl Display for NatsParsingError {
let message = match self {
NatsParsingError::NoValidUtf8 => "NATS message was no valid UTF-8 string.",
NatsParsingError::CannotDeserializeJson => {
"NATS message is not a valid / expected json."
"NATS message is not a json of expected structure."
}
};
writeln!(f, "{}", message)