major server rewrite now all working

This commit is contained in:
Sebastian Moser
2023-01-05 11:19:43 +01:00
parent 134318c13b
commit 3cae3664c3
12 changed files with 972 additions and 378 deletions

View File

@@ -1,4 +1,6 @@
use std::string::FromUtf8Error;
use json;
use crate::server::proto;
@@ -19,11 +21,22 @@ impl MizeError {
return data;
}
pub fn to_message(self: MizeError) -> proto::Response {
pub fn to_message(self: MizeError, origin: proto::Origin) -> proto::Message {
let data = self.to_json();
let mut msg = vec![crate::PROTO_VERSION, proto::MSG_ERROR];
msg.extend(json::stringify(data).into_bytes());
return proto::Response::One(msg);
return proto::Message::from_bytes(msg, origin);
}
}
impl From<FromUtf8Error> for MizeError {
fn from(utf_err: FromUtf8Error) -> MizeError{
let err = MizeError {
code: 109,
kind: "faulty_message".to_string(),
message: "std::string::FromUtf8Error while parsing something from the message".to_string(),
};
return err;
}
}