message.rs

Overview

This file defines the representation and handling of external messages received by the system. It provides data structures to deserialize incoming message data, convert it into a richer internal format, and expose relevant properties and behaviors for further processing. The primary focus is on transforming raw incoming messages into validated and structured ExternalMessage instances that encapsulate message content, identifiers, and authentication tokens.

Data Structures and Types

IncomingExternalMessage

A struct designed for deserialization of raw external messages. It captures the minimal necessary fields received from an external source:

ExternalMessage

Represents a fully parsed and validated message within the system, wrapping the underlying tvm_block::Message and associated metadata.

Important Implementation Details

Interactions with Other Modules

Usage Example

use std::convert::TryFrom;

let incoming = IncomingExternalMessage {
    id: "abc123".to_string(),
    body: "...".to_string(),
    thread_id: Some("thread-42".to_string()),
    ext_message_token: None,
};

match ExternalMessage::try_from(&incoming) {
    Ok(external_msg) => {
        println!("Message hash: {}", external_msg.hash());
        if external_msg.is_dst_exists() {
            // Further processing
        }
    }
    Err(e) => eprintln!("Failed to convert message: {}", e),
}

Mermaid Class Diagram

classDiagram
class IncomingExternalMessage {
-id: String
-body: String
-thread_id: Option<String>
-ext_message_token: Option<Token>
+id(): &str
}
class ExternalMessage {
-hash: String
-message: Message
-thread_id: ThreadIdentifier
+ext_message_token: Option<Token>
+is_dst_exists(): bool
+hash(): String
+tvm_message(): Message
+thread_id(): ThreadIdentifier
}
IncomingExternalMessage <|.. ExternalMessage : TryFrom

This diagram illustrates the two main structs, their key fields and methods, and the conversion relationship between them.