ensicoin_messages/message/
inv.rs1use ensicoin_serializer::types::Sha256Result;
2use ensicoin_serializer::{Deserialize, Serialize};
3
4use crate::message::{Message, MessageType};
5
6#[derive(Serialize, Deserialize)]
7pub struct InvVect {
8 pub data_type: crate::message::ResourceType,
9 pub hash: Sha256Result,
10}
11
12impl std::fmt::Debug for InvVect {
13 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14 use ensicoin_serializer::hash_to_string;
15 f.debug_struct("InvVect")
16 .field("data_type", &self.data_type)
17 .field("hash", &hash_to_string(&self.hash))
18 .finish()
19 }
20}
21
22#[derive(Serialize, Deserialize, Debug)]
23pub struct Inv {
24 pub inventory: Vec<InvVect>,
25}
26
27impl Message for Inv {
28 fn message_string() -> [u8; 12] {
29 [105, 110, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0]
30 }
31 fn message_type() -> MessageType {
32 MessageType::Inv
33 }
34}
35
36#[derive(Serialize, Deserialize, Debug)]
37pub struct GetData {
38 pub inventory: Vec<InvVect>,
39}
40
41impl Message for GetData {
42 fn message_string() -> [u8; 12] {
43 [103, 101, 116, 100, 97, 116, 97, 0, 0, 0, 0, 0]
44 }
45 fn message_type() -> MessageType {
46 MessageType::GetData
47 }
48}
49
50#[derive(Serialize, Deserialize, Debug)]
51pub struct NotFound {
52 pub inventory: Vec<InvVect>,
53}
54
55impl Message for NotFound {
56 fn message_string() -> [u8; 12] {
57 [110, 111, 116, 102, 111, 117, 110, 100, 0, 0, 0, 0]
58 }
59 fn message_type() -> MessageType {
60 MessageType::NotFound
61 }
62}