Represent messages
This commit is contained in:
parent
cfaafba77f
commit
286ace55b4
3 changed files with 33 additions and 1 deletions
|
|
@ -6,7 +6,7 @@ use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
// TODO Use base64 representation instead
|
// TODO Use base64 representation instead
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
|
||||||
pub struct Id(#[serde(with = "hex")] [u8; 32]);
|
pub struct Id(#[serde(with = "hex")] [u8; 32]);
|
||||||
|
|
||||||
impl Id {
|
impl Id {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
mod id;
|
mod id;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
mod message;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub use self::id::*;
|
pub use self::id::*;
|
||||||
use self::macros::packets;
|
use self::macros::packets;
|
||||||
|
pub use self::message::*;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct HelloCmd {
|
pub struct HelloCmd {
|
||||||
|
|
|
||||||
30
cove-core/src/message.rs
Normal file
30
cove-core/src/message.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::Id;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Message {
|
||||||
|
pub pred: Option<Id>,
|
||||||
|
pub parent: Option<Id>,
|
||||||
|
pub identity: Id,
|
||||||
|
pub nick: String,
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Message {
|
||||||
|
pub fn id(&self) -> Id {
|
||||||
|
let pred = match self.pred {
|
||||||
|
Some(id) => format!("{id}"),
|
||||||
|
None => "none".to_string(),
|
||||||
|
};
|
||||||
|
let parent = match self.parent {
|
||||||
|
Some(id) => format!("{id}"),
|
||||||
|
None => "none".to_string(),
|
||||||
|
};
|
||||||
|
let identity = self.identity;
|
||||||
|
let nick = Id::of(&self.nick);
|
||||||
|
let content = Id::of(&self.content);
|
||||||
|
let str = format!("message {pred} {parent} {identity} {nick} {content}");
|
||||||
|
Id::of(&str)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue