pub struct SharedMessage {
pub id: SharedObjectId,
pub message_type: MessageType,
pub target_id: Option<SharedObjectId>,
pub data: Value,
pub timestamp: DateTime<Utc>,
pub signature: Option<Vec<u8>>,
pub hash: String,
}
Expand description
A message that can be shared between nodes
Fields§
§id: SharedObjectId
Unique message identifier
message_type: MessageType
Message type
target_id: Option<SharedObjectId>
Target object ID (if applicable)
data: Value
Message payload
timestamp: DateTime<Utc>
Timestamp when message was created
signature: Option<Vec<u8>>
Optional signature for authenticated messages
hash: String
Hash of the message content
Implementations§
Sourcepub fn new(message_type: MessageType, data: Value) -> Self
pub fn new(message_type: MessageType, data: Value) -> Self
Create a new shared message
Sourcepub fn new_with_target(
message_type: MessageType,
target_id: SharedObjectId,
data: Value,
) -> Self
pub fn new_with_target( message_type: MessageType, target_id: SharedObjectId, data: Value, ) -> Self
Create a new message with a target
Sourcepub fn custom<T: Serialize>(
message_type: impl Into<String>,
data: T,
) -> Result<Self>
pub fn custom<T: Serialize>( message_type: impl Into<String>, data: T, ) -> Result<Self>
Create a custom message
Sourcepub fn sign(&mut self, private_key: &PrivateKey) -> Result<()>
pub fn sign(&mut self, private_key: &PrivateKey) -> Result<()>
Sign this message with the given private key
Sourcepub fn verify_signature(&self, public_key: &PublicKey) -> Result<bool>
pub fn verify_signature(&self, public_key: &PublicKey) -> Result<bool>
Verify the signature of this message
Sourcepub fn calculate_hash(&self) -> String
pub fn calculate_hash(&self) -> String
Calculate the hash of this message
Sourcepub fn verify_hash(&self) -> bool
pub fn verify_hash(&self) -> bool
Verify the message hash
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Create message from bytes
Trait Implementations§
Source§fn clone(&self) -> SharedMessage
fn clone(&self) -> SharedMessage
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§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§
Blanket Implementations§
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