pub struct PubsubMessage {
pub from: String,
pub data: Vec<u8>,
pub seqno: Vec<u8>,
pub topic_ids: Vec<String>,
pub topic: String,
}Expand description
A message received from or published to a pubsub topic.
§Kubo Equivalent
Corresponds to the message format used in ipfs pubsub sub output.
See core/commands/pubsub.go:pubsubSubCmd.
§Example
use ferripfs_network::PubsubMessage;
// Create a simple message with just sender, topic, and data
let msg = PubsubMessage::simple(
"QmPeerID".to_string(),
"my-topic".to_string(),
b"Hello, world!".to_vec(),
);
assert_eq!(msg.topic, "my-topic");
// Or create a message with all fields
let msg_full = PubsubMessage::new(
"QmPeerID".to_string(),
b"Hello!".to_vec(),
vec![1, 2, 3, 4], // seqno
vec!["my-topic".to_string()], // topic_ids
"my-topic".to_string(),
);
assert_eq!(msg_full.seqno, vec![1, 2, 3, 4]);Fields§
§from: StringPeer ID of the message sender.
data: Vec<u8>Data payload (base64 encoded in JSON).
seqno: Vec<u8>Sequence number for ordering.
topic_ids: Vec<String>Topic IDs the message was received on.
topic: StringPrimary topic (convenience field).
Implementations§
Source§impl PubsubMessage
impl PubsubMessage
Sourcepub fn new(
from: String,
data: Vec<u8>,
seqno: Vec<u8>,
topic_ids: Vec<String>,
topic: String,
) -> Self
pub fn new( from: String, data: Vec<u8>, seqno: Vec<u8>, topic_ids: Vec<String>, topic: String, ) -> Self
Create a new pubsub message with all fields.
§Arguments
from- Peer ID of the senderdata- Message payloadseqno- Sequence number bytestopic_ids- List of topic IDstopic- Primary topic
Sourcepub fn simple(from: String, topic: String, data: Vec<u8>) -> Self
pub fn simple(from: String, topic: String, data: Vec<u8>) -> Self
Create a simple message for a single topic.
This is a convenience method that sets seqno to empty and derives topic_ids from the single topic.
Sourcepub fn with_seqno(
from: String,
topic: String,
data: Vec<u8>,
seqno: Vec<u8>,
) -> Self
pub fn with_seqno( from: String, topic: String, data: Vec<u8>, seqno: Vec<u8>, ) -> Self
Create a message with a sequence number.
Sourcepub fn data_string(&self) -> Option<String>
pub fn data_string(&self) -> Option<String>
Get the message data as a UTF-8 string (if valid).
Trait Implementations§
Source§impl Clone for PubsubMessage
impl Clone for PubsubMessage
Source§fn clone(&self) -> PubsubMessage
fn clone(&self) -> PubsubMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PubsubMessage
impl Debug for PubsubMessage
Source§impl<'de> Deserialize<'de> for PubsubMessage
impl<'de> Deserialize<'de> for PubsubMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PubsubMessage
impl RefUnwindSafe for PubsubMessage
impl Send for PubsubMessage
impl Sync for PubsubMessage
impl Unpin for PubsubMessage
impl UnwindSafe for PubsubMessage
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more