Implement request response messaging
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user