feat: add first protocol packet enums
This commit is contained in:
parent
210301df44
commit
58c3975139
8 changed files with 69 additions and 3 deletions
|
@ -7,3 +7,9 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
sea-orm = "0.12"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
uuid = { version = "1.9.1", features = ["v4"] }
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[sea_orm(table_name = "chats")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
pub mod proto;
|
||||
|
||||
pub mod chats;
|
||||
pub mod messages;
|
||||
pub mod users;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[sea_orm(table_name = "messages")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
|
|
40
model/src/proto/c2s.rs
Normal file
40
model/src/proto/c2s.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
/// serverbound packets
|
||||
pub mod s {
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Packet {
|
||||
Chat(crate::messages::Model),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// clientbound packets
|
||||
pub mod c {
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Packet {
|
||||
Chat(crate::messages::Model),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn how_does_this_serialize_again() {
|
||||
panic!(
|
||||
"{}",
|
||||
serde_json::to_string(
|
||||
&super::c::Packet::Chat(
|
||||
crate::messages::Model {
|
||||
id: uuid::Uuid::new_v4(),
|
||||
user_id: uuid::Uuid::new_v4(),
|
||||
chat_id: uuid::Uuid::new_v4(),
|
||||
content: Some("hello world!".to_string()),
|
||||
created: chrono::Utc::now(),
|
||||
updated: None,
|
||||
}
|
||||
)
|
||||
).expect("uhmmm???")
|
||||
)
|
||||
}
|
||||
}
|
2
model/src/proto/mod.rs
Normal file
2
model/src/proto/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod c2s;
|
||||
pub mod s2s;
|
16
model/src/proto/s2s.rs
Normal file
16
model/src/proto/s2s.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Packet {
|
||||
Ping(i64),
|
||||
Pong(i64),
|
||||
Relay(crate::messages::Model),
|
||||
Resolve(ResolvePacket),
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ResolvePacket {
|
||||
ResolveRequest(uuid::Uuid),
|
||||
ResolveResponse(crate::users::Model),
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
|
|
Loading…
Reference in a new issue