libp2p_pubsub_core/
message.rs1use bytes::Bytes;
7use libp2p::identity::PeerId;
8
9use crate::topic::TopicHash;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct Message {
14 pub from: Option<PeerId>,
16 pub data: Vec<u8>,
18 pub sequence_number: Option<Bytes>,
20 pub topic: TopicHash,
22 pub signature: Option<Vec<u8>>,
24 pub key: Option<Vec<u8>>,
26}
27
28impl Message {
29 #[must_use]
31 pub fn new(topic: impl Into<TopicHash>, data: impl Into<Vec<u8>>) -> Self {
32 Self {
33 from: None,
34 data: data.into(),
35 sequence_number: None,
36 topic: topic.into(),
37 signature: None,
38 key: None,
39 }
40 }
41
42 #[must_use]
44 pub fn new_with_sequence_number(
45 topic: impl Into<TopicHash>,
46 data: impl Into<Vec<u8>>,
47 seq_no: impl Into<Vec<u8>>,
48 ) -> Self {
49 Self {
50 from: None,
51 data: data.into(),
52 sequence_number: Some(Bytes::from(seq_no.into())),
53 topic: topic.into(),
54 signature: None,
55 key: None,
56 }
57 }
58}