dimas_com/
messages.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright © 2024 Stephan Kunz
#![allow(clippy::non_canonical_partial_ord_impl)]

//! Module `messages` provides the different Message`s used with DiMAS.

#[doc(hidden)]
extern crate alloc;

#[cfg(feature = "std")]
extern crate std;

// region:		--- modules
#[cfg(feature = "std")]
use std::prelude::rust_2021::*;
use bitcode::{Decode, Encode};
use core::fmt::Display;
use dimas_core::enums::OperationState;
// endregion:	--- modules

// region:		--- AboutEntity
/// A `DiMAS` entity
#[repr(C)]
#[derive(Encode, Clone, Decode)]
pub struct AboutEntity {
	name: String,
	kind: String,
	zid: String,
	state: OperationState,
}

impl Display for AboutEntity {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(
			f,
			"name: {} kind: {} state: {} zid: {}",
			&self.name, &self.kind, &self.state, &self.zid
		)
	}
}

impl AboutEntity {
	/// Constructor
	#[must_use]
	pub const fn new(name: String, kind: String, zid: String, state: OperationState) -> Self {
		Self {
			name,
			kind,
			zid,
			state,
		}
	}

	/// Get the Name
	#[must_use]
	pub fn name(&self) -> &str {
		&self.name
	}

	/// Get the Kind
	#[must_use]
	pub fn kind(&self) -> &str {
		&self.kind
	}

	/// Get the Zenoh ID
	#[must_use]
	pub fn zid(&self) -> &str {
		&self.zid
	}

	/// Get the state
	#[must_use]
	pub const fn state(&self) -> &OperationState {
		&self.state
	}
}
// endregion:	--- AboutEntity

// region:		--- PingEntity
/// A `DiMAS` entity
#[repr(C)]
#[derive(Encode, Clone, Decode)]
pub struct PingEntity {
	name: String,
	zid: String,
	oneway: i64,
}

impl Display for PingEntity {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		write!(
			f,
			"name: {} zid: {} oneway: {}",
			&self.name, &self.zid, &self.oneway
		)
	}
}

impl PingEntity {
	/// Constructor
	#[must_use]
	pub const fn new(name: String, zid: String, oneway: i64) -> Self {
		Self { name, zid, oneway }
	}

	/// Get the Name
	#[must_use]
	pub fn name(&self) -> &str {
		&self.name
	}

	/// Get the Zenoh ID
	#[must_use]
	pub fn zid(&self) -> &str {
		&self.zid
	}

	/// Get the oneway time
	#[must_use]
	pub const fn oneway(&self) -> i64 {
		self.oneway
	}
}
// endregion:	--- PingEntity

// region:		--- ScoutingEntity
/// A `Zenoh` entity
#[repr(C)]
#[derive(Encode, Clone, Decode)]
pub struct ScoutingEntity {
	zid: String,
	kind: String,
	locators: Vec<String>,
}

impl Display for ScoutingEntity {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		f.debug_struct("ScoutingEntity")
			.field("zid", &self.zid)
			.field("kind", &self.kind)
			.field("locators", &self.locators)
			.finish()
	}
}

impl ScoutingEntity {
	/// Constructor
	#[must_use]
	pub const fn new(zid: String, kind: String, locators: Vec<String>) -> Self {
		Self {
			zid,
			kind,
			locators,
		}
	}

	/// Get the Zenoh ID
	#[must_use]
	pub fn zid(&self) -> &str {
		&self.zid
	}

	/// Get the Kind
	#[must_use]
	pub fn kind(&self) -> &str {
		&self.kind
	}

	/// Get the Locators
	#[must_use]
	pub const fn locators(&self) -> &Vec<String> {
		&self.locators
	}
}
// endregion:	--- ScoutingEntity

// region:		--- ???
// endregion:	--- ???