Skip to main content

opcua_core/messages/
mod.rs

1//! [RequestMessage] and [ResponseMessage], and utilities for working with these.
2
3use std::io::Read;
4
5use opcua_types::{BinaryEncodable, EncodingResult, NodeId, ObjectId};
6
7mod request;
8mod response;
9
10pub use request::RequestMessage;
11pub use response::ResponseMessage;
12
13use crate::comms::message_chunk::MessageChunkType;
14
15/// Trait implemented by messages and message chunks.
16pub trait MessageType {
17    /// Get the message chunk type.
18    fn message_type(&self) -> MessageChunkType;
19}
20
21/// Trait implemented by messages.
22pub trait Message: BinaryEncodable + MessageType {
23    /// Get the message request handle.
24    fn request_handle(&self) -> u32;
25
26    /// Decode the message by object ID.
27    fn decode_by_object_id<S: Read>(
28        stream: &mut S,
29        object_id: ObjectId,
30        ctx: &opcua_types::Context<'_>,
31    ) -> EncodingResult<Self>
32    where
33        Self: Sized;
34
35    /// Get the type ID of the message.
36    fn type_id(&self) -> NodeId;
37}