feat: add first protocol packet enums

This commit is contained in:
əlemi 2024-06-29 00:37:53 +02:00
parent 210301df44
commit 58c3975139
Signed by: alemi
GPG key ID: A4895B84D311642C
8 changed files with 69 additions and 3 deletions

View file

@ -7,3 +7,9 @@ edition = "2021"
[dependencies] [dependencies]
sea-orm = "0.12" 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"

View file

@ -2,7 +2,7 @@
use sea_orm::entity::prelude::*; 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")] #[sea_orm(table_name = "chats")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = false)] #[sea_orm(primary_key, auto_increment = false)]

View file

@ -1,3 +1,5 @@
pub mod proto;
pub mod chats; pub mod chats;
pub mod messages; pub mod messages;
pub mod users; pub mod users;

View file

@ -2,7 +2,7 @@
use sea_orm::entity::prelude::*; 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")] #[sea_orm(table_name = "messages")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = false)] #[sea_orm(primary_key, auto_increment = false)]

40
model/src/proto/c2s.rs Normal file
View 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
View file

@ -0,0 +1,2 @@
pub mod c2s;
pub mod s2s;

16
model/src/proto/s2s.rs Normal file
View 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),
}

View file

@ -2,7 +2,7 @@
use sea_orm::entity::prelude::*; 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")] #[sea_orm(table_name = "users")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = false)] #[sea_orm(primary_key, auto_increment = false)]