nautilus_core/
message.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Common message types.
17//!
18//! The [`Params`] type uses `IndexMap<String, String>` for consistent ordering
19//! and simpler, predictable serialization.
20
21use indexmap::IndexMap;
22
23use crate::{UUID4, UnixNanos};
24
25/// Additional parameters for messages.
26pub type Params = IndexMap<String, String>;
27
28/// Represents different types of messages in the system.
29#[derive(Debug, Clone)]
30pub enum Message {
31    /// A command message with an identifier and initialization timestamp.
32    Command {
33        /// The unique identifier for this command.
34        id: UUID4,
35        /// The initialization timestamp.
36        ts_init: UnixNanos,
37    },
38    /// A document message with an identifier and initialization timestamp.
39    Document {
40        /// The unique identifier for this document.
41        id: UUID4,
42        /// The initialization timestamp.
43        ts_init: UnixNanos,
44    },
45    /// An event message with identifiers and timestamps.
46    Event {
47        /// The unique identifier for this event.
48        id: UUID4,
49        /// The initialization timestamp.
50        ts_init: UnixNanos,
51        /// The event timestamp.
52        ts_event: UnixNanos,
53    },
54    /// A request message with an identifier and initialization timestamp.
55    Request {
56        /// The unique identifier for this request.
57        id: UUID4,
58        /// The initialization timestamp.
59        ts_init: UnixNanos,
60    },
61    /// A response message with identifiers, timestamps, and correlation.
62    Response {
63        /// The unique identifier for this response.
64        id: UUID4,
65        /// The initialization timestamp.
66        ts_init: UnixNanos,
67        /// The correlation identifier linking this response to a request.
68        correlation_id: UUID4,
69    },
70}