enigma_packet/
types.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5pub enum MessageType {
6    Text,
7    Voice,
8    Image,
9    Video,
10    File,
11    CallOffer,
12    CallAnswer,
13    CallHangup,
14    GroupInvite,
15    AttachmentInit,
16    AttachmentChunk,
17    AttachmentEnd,
18    AttachmentAbort,
19    AttachmentAck,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
23pub enum AttachmentKind {
24    File,
25    Image,
26    Video,
27    Voice,
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub struct AttachmentMeta {
32    pub attachment_id: Uuid,
33    pub kind: AttachmentKind,
34    pub filename: Option<String>,
35    pub content_type: Option<String>,
36    pub total_size: u64,
37    pub chunk_size: u32,
38    pub chunk_count: u32,
39    pub sha256: Option<[u8; 32]>,
40    pub created_at_ms: Option<u64>,
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44pub struct AttachmentChunkMeta {
45    pub attachment_id: Uuid,
46    pub index: u32,
47    pub offset: u64,
48    pub chunk_size: u32,
49    pub total_size: Option<u64>,
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53pub struct AttachmentAckMeta {
54    pub attachment_id: Uuid,
55    pub received_up_to_index: Option<u32>,
56}
57
58#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
59pub enum MessageMeta {
60    None,
61    Basic {
62        content_type: Option<String>,
63    },
64    AttachmentInit(AttachmentMeta),
65    AttachmentChunk(AttachmentChunkMeta),
66    AttachmentEnd {
67        attachment_id: Uuid,
68        sha256: Option<[u8; 32]>,
69        total_size: u64,
70        chunk_count: u32,
71    },
72    AttachmentAbort {
73        attachment_id: Uuid,
74        reason: Option<String>,
75    },
76    AttachmentAck(AttachmentAckMeta),
77}
78
79impl Default for MessageMeta {
80    fn default() -> Self {
81        MessageMeta::None
82    }
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
86pub struct Message {
87    pub id: Uuid,
88    pub sender: String,
89    pub receiver: String,
90    pub timestamp_ms: u64,
91    pub msg_type: MessageType,
92    pub payload: Vec<u8>,
93    pub meta: MessageMeta,
94}