use alloc::boxed::Box;
use serde::{Deserialize, Serialize};
use crate::types::common::{
ControlType, EnergyManagementRole, Handshake, HandshakeResponse, InstructionStatusUpdate,
PowerForecast, PowerMeasurement, ReceptionStatus, ResourceManagerDetails, RevokeObject,
SelectControlType, SessionRequest,
};
use crate::types::{Id, ddbc, frbc, ombc, pebc, ppbc};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "message_type")]
#[non_exhaustive]
pub enum Message {
#[serde(rename = "Handshake")]
Handshake(Handshake),
#[serde(rename = "HandshakeResponse")]
HandshakeResponse(HandshakeResponse),
#[serde(rename = "ResourceManagerDetails")]
ResourceManagerDetails(Box<ResourceManagerDetails>),
#[serde(rename = "SelectControlType")]
SelectControlType(SelectControlType),
#[serde(rename = "SessionRequest")]
SessionRequest(SessionRequest),
#[serde(rename = "ReceptionStatus")]
ReceptionStatus(ReceptionStatus),
#[serde(rename = "InstructionStatusUpdate")]
InstructionStatusUpdate(InstructionStatusUpdate),
#[serde(rename = "PowerMeasurement")]
PowerMeasurement(PowerMeasurement),
#[serde(rename = "PowerForecast")]
PowerForecast(Box<PowerForecast>),
#[serde(rename = "RevokeObject")]
RevokeObject(RevokeObject),
#[serde(rename = "PEBC.PowerConstraints")]
PebcPowerConstraints(Box<pebc::PowerConstraints>),
#[serde(rename = "PEBC.EnergyConstraint")]
PebcEnergyConstraint(Box<pebc::EnergyConstraint>),
#[serde(rename = "PEBC.Instruction")]
PebcInstruction(Box<pebc::Instruction>),
#[serde(rename = "PPBC.PowerProfileDefinition")]
PpbcPowerProfileDefinition(Box<ppbc::PowerProfileDefinition>),
#[serde(rename = "PPBC.PowerProfileStatus")]
PpbcPowerProfileStatus(Box<ppbc::PowerProfileStatus>),
#[serde(rename = "PPBC.ScheduleInstruction")]
PpbcScheduleInstruction(Box<ppbc::ScheduleInstruction>),
#[serde(rename = "PPBC.StartInterruptionInstruction")]
PpbcStartInterruptionInstruction(Box<ppbc::StartInterruptionInstruction>),
#[serde(rename = "PPBC.EndInterruptionInstruction")]
PpbcEndInterruptionInstruction(Box<ppbc::EndInterruptionInstruction>),
#[serde(rename = "OMBC.SystemDescription")]
OmbcSystemDescription(Box<ombc::SystemDescription>),
#[serde(rename = "OMBC.Status")]
OmbcStatus(Box<ombc::Status>),
#[serde(rename = "OMBC.TimerStatus")]
OmbcTimerStatus(ombc::TimerStatus),
#[serde(rename = "OMBC.Instruction")]
OmbcInstruction(Box<ombc::Instruction>),
#[serde(rename = "FRBC.SystemDescription")]
FrbcSystemDescription(Box<frbc::SystemDescription>),
#[serde(rename = "FRBC.StorageStatus")]
FrbcStorageStatus(frbc::StorageStatus),
#[serde(rename = "FRBC.ActuatorStatus")]
FrbcActuatorStatus(Box<frbc::ActuatorStatus>),
#[serde(rename = "FRBC.TimerStatus")]
FrbcTimerStatus(Box<frbc::TimerStatus>),
#[serde(rename = "FRBC.LeakageBehaviour")]
FrbcLeakageBehaviour(Box<frbc::LeakageBehaviour>),
#[serde(rename = "FRBC.UsageForecast")]
FrbcUsageForecast(Box<frbc::UsageForecast>),
#[serde(rename = "FRBC.FillLevelTargetProfile")]
FrbcFillLevelTargetProfile(Box<frbc::FillLevelTargetProfile>),
#[serde(rename = "FRBC.Instruction")]
FrbcInstruction(Box<frbc::Instruction>),
#[serde(rename = "DDBC.SystemDescription")]
DdbcSystemDescription(Box<ddbc::SystemDescription>),
#[serde(rename = "DDBC.ActuatorStatus")]
DdbcActuatorStatus(Box<ddbc::ActuatorStatus>),
#[serde(rename = "DDBC.TimerStatus")]
DdbcTimerStatus(Box<ddbc::TimerStatus>),
#[serde(rename = "DDBC.AverageDemandRateForecast")]
DdbcAverageDemandRateForecast(Box<ddbc::AverageDemandRateForecast>),
#[serde(rename = "DDBC.PresentDemandStatus")]
DdbcPresentDemandStatus(ddbc::PresentDemandStatus),
#[serde(rename = "DDBC.Instruction")]
DdbcInstruction(Box<ddbc::Instruction>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
#[allow(missing_docs)] pub enum MessageKind {
Handshake,
HandshakeResponse,
ResourceManagerDetails,
SelectControlType,
SessionRequest,
ReceptionStatus,
InstructionStatusUpdate,
PowerMeasurement,
PowerForecast,
RevokeObject,
PebcPowerConstraints,
PebcEnergyConstraint,
PebcInstruction,
PpbcPowerProfileDefinition,
PpbcPowerProfileStatus,
PpbcScheduleInstruction,
PpbcStartInterruptionInstruction,
PpbcEndInterruptionInstruction,
OmbcSystemDescription,
OmbcStatus,
OmbcTimerStatus,
OmbcInstruction,
FrbcSystemDescription,
FrbcStorageStatus,
FrbcActuatorStatus,
FrbcTimerStatus,
FrbcLeakageBehaviour,
FrbcUsageForecast,
FrbcFillLevelTargetProfile,
FrbcInstruction,
DdbcSystemDescription,
DdbcActuatorStatus,
DdbcTimerStatus,
DdbcAverageDemandRateForecast,
DdbcPresentDemandStatus,
DdbcInstruction,
}
macro_rules! message_kinds {
($(($kind:ident, $wire:literal, $variant:ident)),* $(,)?) => {
impl MessageKind {
pub const ALL: &'static [MessageKind] = &[$(MessageKind::$kind),*];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self { $(MessageKind::$kind => $wire),* }
}
#[must_use]
pub fn from_wire(s: &str) -> Option<Self> {
match s { $($wire => Some(MessageKind::$kind),)* _ => None }
}
}
impl Message {
#[must_use]
pub const fn kind(&self) -> MessageKind {
match self { $(Message::$variant(..) => MessageKind::$kind),* }
}
}
};
}
message_kinds![
(Handshake, "Handshake", Handshake),
(HandshakeResponse, "HandshakeResponse", HandshakeResponse),
(
ResourceManagerDetails,
"ResourceManagerDetails",
ResourceManagerDetails
),
(SelectControlType, "SelectControlType", SelectControlType),
(SessionRequest, "SessionRequest", SessionRequest),
(ReceptionStatus, "ReceptionStatus", ReceptionStatus),
(
InstructionStatusUpdate,
"InstructionStatusUpdate",
InstructionStatusUpdate
),
(PowerMeasurement, "PowerMeasurement", PowerMeasurement),
(PowerForecast, "PowerForecast", PowerForecast),
(RevokeObject, "RevokeObject", RevokeObject),
(
PebcPowerConstraints,
"PEBC.PowerConstraints",
PebcPowerConstraints
),
(
PebcEnergyConstraint,
"PEBC.EnergyConstraint",
PebcEnergyConstraint
),
(PebcInstruction, "PEBC.Instruction", PebcInstruction),
(
PpbcPowerProfileDefinition,
"PPBC.PowerProfileDefinition",
PpbcPowerProfileDefinition
),
(
PpbcPowerProfileStatus,
"PPBC.PowerProfileStatus",
PpbcPowerProfileStatus
),
(
PpbcScheduleInstruction,
"PPBC.ScheduleInstruction",
PpbcScheduleInstruction
),
(
PpbcStartInterruptionInstruction,
"PPBC.StartInterruptionInstruction",
PpbcStartInterruptionInstruction
),
(
PpbcEndInterruptionInstruction,
"PPBC.EndInterruptionInstruction",
PpbcEndInterruptionInstruction
),
(
OmbcSystemDescription,
"OMBC.SystemDescription",
OmbcSystemDescription
),
(OmbcStatus, "OMBC.Status", OmbcStatus),
(OmbcTimerStatus, "OMBC.TimerStatus", OmbcTimerStatus),
(OmbcInstruction, "OMBC.Instruction", OmbcInstruction),
(
FrbcSystemDescription,
"FRBC.SystemDescription",
FrbcSystemDescription
),
(FrbcStorageStatus, "FRBC.StorageStatus", FrbcStorageStatus),
(
FrbcActuatorStatus,
"FRBC.ActuatorStatus",
FrbcActuatorStatus
),
(FrbcTimerStatus, "FRBC.TimerStatus", FrbcTimerStatus),
(
FrbcLeakageBehaviour,
"FRBC.LeakageBehaviour",
FrbcLeakageBehaviour
),
(FrbcUsageForecast, "FRBC.UsageForecast", FrbcUsageForecast),
(
FrbcFillLevelTargetProfile,
"FRBC.FillLevelTargetProfile",
FrbcFillLevelTargetProfile
),
(FrbcInstruction, "FRBC.Instruction", FrbcInstruction),
(
DdbcSystemDescription,
"DDBC.SystemDescription",
DdbcSystemDescription
),
(
DdbcActuatorStatus,
"DDBC.ActuatorStatus",
DdbcActuatorStatus
),
(DdbcTimerStatus, "DDBC.TimerStatus", DdbcTimerStatus),
(
DdbcAverageDemandRateForecast,
"DDBC.AverageDemandRateForecast",
DdbcAverageDemandRateForecast
),
(
DdbcPresentDemandStatus,
"DDBC.PresentDemandStatus",
DdbcPresentDemandStatus
),
(DdbcInstruction, "DDBC.Instruction", DdbcInstruction),
];
impl core::fmt::Display for MessageKind {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
impl MessageKind {
#[must_use]
pub const fn control_type(self) -> Option<ControlType> {
use MessageKind as K;
match self {
K::PebcPowerConstraints | K::PebcEnergyConstraint | K::PebcInstruction => {
Some(ControlType::PowerEnvelopeBasedControl)
}
K::PpbcPowerProfileDefinition
| K::PpbcPowerProfileStatus
| K::PpbcScheduleInstruction
| K::PpbcStartInterruptionInstruction
| K::PpbcEndInterruptionInstruction => Some(ControlType::PowerProfileBasedControl),
K::OmbcSystemDescription | K::OmbcStatus | K::OmbcTimerStatus | K::OmbcInstruction => {
Some(ControlType::OperationModeBasedControl)
}
K::FrbcSystemDescription
| K::FrbcStorageStatus
| K::FrbcActuatorStatus
| K::FrbcTimerStatus
| K::FrbcLeakageBehaviour
| K::FrbcUsageForecast
| K::FrbcFillLevelTargetProfile
| K::FrbcInstruction => Some(ControlType::FillRateBasedControl),
K::DdbcSystemDescription
| K::DdbcActuatorStatus
| K::DdbcTimerStatus
| K::DdbcAverageDemandRateForecast
| K::DdbcPresentDemandStatus
| K::DdbcInstruction => Some(ControlType::DemandDrivenBasedControl),
_ => None,
}
}
#[must_use]
pub const fn is_instruction(self) -> bool {
use MessageKind as K;
matches!(
self,
K::PebcInstruction
| K::PpbcScheduleInstruction
| K::PpbcStartInterruptionInstruction
| K::PpbcEndInterruptionInstruction
| K::OmbcInstruction
| K::FrbcInstruction
| K::DdbcInstruction
)
}
#[must_use]
pub const fn sender(self) -> Option<EnergyManagementRole> {
use EnergyManagementRole as Role;
use MessageKind as K;
match self {
K::SelectControlType | K::HandshakeResponse => Some(Role::Cem),
_ if self.is_instruction() => Some(Role::Cem),
K::SessionRequest | K::ReceptionStatus | K::Handshake | K::RevokeObject => None,
_ => Some(Role::Rm),
}
}
#[must_use]
pub const fn exists_in(self, profile: crate::types::WireProfile) -> bool {
!(matches!(self, MessageKind::DdbcPresentDemandStatus)
&& matches!(profile, crate::types::WireProfile::V0_0_2Beta))
}
}
impl Message {
#[must_use]
pub fn id(&self) -> Option<Id> {
use Message as M;
Some(match self {
M::Handshake(m) => m.message_id,
M::HandshakeResponse(m) => m.message_id,
M::ResourceManagerDetails(m) => m.message_id,
M::SelectControlType(m) => m.message_id,
M::SessionRequest(m) => m.message_id,
M::ReceptionStatus(_) => return None,
M::InstructionStatusUpdate(m) => m.message_id,
M::PowerMeasurement(m) => m.message_id,
M::PowerForecast(m) => m.message_id,
M::RevokeObject(m) => m.message_id,
M::PebcPowerConstraints(m) => m.message_id,
M::PebcEnergyConstraint(m) => m.message_id,
M::PebcInstruction(m) => m.message_id,
M::PpbcPowerProfileDefinition(m) => m.message_id,
M::PpbcPowerProfileStatus(m) => m.message_id,
M::PpbcScheduleInstruction(m) => m.message_id,
M::PpbcStartInterruptionInstruction(m) => m.message_id,
M::PpbcEndInterruptionInstruction(m) => m.message_id,
M::OmbcSystemDescription(m) => m.message_id,
M::OmbcStatus(m) => m.message_id,
M::OmbcTimerStatus(m) => m.message_id,
M::OmbcInstruction(m) => m.message_id,
M::FrbcSystemDescription(m) => m.message_id,
M::FrbcStorageStatus(m) => m.message_id,
M::FrbcActuatorStatus(m) => m.message_id,
M::FrbcTimerStatus(m) => m.message_id,
M::FrbcLeakageBehaviour(m) => m.message_id,
M::FrbcUsageForecast(m) => m.message_id,
M::FrbcFillLevelTargetProfile(m) => m.message_id,
M::FrbcInstruction(m) => m.message_id,
M::DdbcSystemDescription(m) => m.message_id,
M::DdbcActuatorStatus(m) => m.message_id,
M::DdbcTimerStatus(m) => m.message_id,
M::DdbcAverageDemandRateForecast(m) => m.message_id,
M::DdbcPresentDemandStatus(m) => m.message_id,
M::DdbcInstruction(m) => m.message_id,
})
}
#[must_use]
pub fn subject_message_id(&self) -> Option<Id> {
match self {
Message::ReceptionStatus(s) => Some(s.subject_message_id),
_ => None,
}
}
#[must_use]
pub fn instruction_id(&self) -> Option<Id> {
use Message as M;
Some(match self {
M::PebcInstruction(m) => m.id,
M::PpbcScheduleInstruction(m) => m.id,
M::PpbcStartInterruptionInstruction(m) => m.id,
M::PpbcEndInterruptionInstruction(m) => m.id,
M::OmbcInstruction(m) => m.id,
M::FrbcInstruction(m) => m.id,
M::DdbcInstruction(m) => m.id,
_ => return None,
})
}
#[must_use]
pub fn revokable_id(&self) -> Option<(crate::types::common::RevokableObjects, Id)> {
use crate::types::common::RevokableObjects as R;
use Message as M;
Some(match self {
M::PebcPowerConstraints(m) => (R::PebcPowerConstraints, m.id),
M::PebcEnergyConstraint(m) => (R::PebcEnergyConstraint, m.id),
M::PebcInstruction(m) => (R::PebcInstruction, m.id),
M::PpbcPowerProfileDefinition(m) => (R::PpbcPowerProfileDefinition, m.id),
M::PpbcScheduleInstruction(m) => (R::PpbcScheduleInstruction, m.id),
M::PpbcStartInterruptionInstruction(m) => (R::PpbcStartInterruptionInstruction, m.id),
M::PpbcEndInterruptionInstruction(m) => (R::PpbcEndInterruptionInstruction, m.id),
M::OmbcInstruction(m) => (R::OmbcInstruction, m.id),
M::FrbcInstruction(m) => (R::FrbcInstruction, m.id),
M::DdbcInstruction(m) => (R::DdbcInstruction, m.id),
M::OmbcSystemDescription(m) => (R::OmbcSystemDescription, m.message_id),
M::FrbcSystemDescription(m) => (R::FrbcSystemDescription, m.message_id),
M::DdbcSystemDescription(m) => (R::DdbcSystemDescription, m.message_id),
_ => return None,
})
}
#[must_use]
pub const fn control_type(&self) -> Option<ControlType> {
self.kind().control_type()
}
#[must_use]
pub const fn is_instruction(&self) -> bool {
self.kind().is_instruction()
}
}
macro_rules! from_payload {
($($ty:ty => $variant:ident $(, $boxed:tt)?);* $(;)?) => {
$(impl From<$ty> for Message {
fn from(value: $ty) -> Self {
Message::$variant(from_payload!(@wrap value $(, $boxed)?))
}
})*
};
(@wrap $v:ident) => { $v };
(@wrap $v:ident, box) => { Box::new($v) };
}
from_payload![
Handshake => Handshake;
HandshakeResponse => HandshakeResponse;
ResourceManagerDetails => ResourceManagerDetails, box;
SelectControlType => SelectControlType;
SessionRequest => SessionRequest;
ReceptionStatus => ReceptionStatus;
InstructionStatusUpdate => InstructionStatusUpdate;
PowerMeasurement => PowerMeasurement;
PowerForecast => PowerForecast, box;
RevokeObject => RevokeObject;
pebc::PowerConstraints => PebcPowerConstraints, box;
pebc::EnergyConstraint => PebcEnergyConstraint, box;
pebc::Instruction => PebcInstruction, box;
ppbc::PowerProfileDefinition => PpbcPowerProfileDefinition, box;
ppbc::PowerProfileStatus => PpbcPowerProfileStatus, box;
ppbc::ScheduleInstruction => PpbcScheduleInstruction, box;
ppbc::StartInterruptionInstruction => PpbcStartInterruptionInstruction, box;
ppbc::EndInterruptionInstruction => PpbcEndInterruptionInstruction, box;
ombc::SystemDescription => OmbcSystemDescription, box;
ombc::Status => OmbcStatus, box;
ombc::TimerStatus => OmbcTimerStatus;
ombc::Instruction => OmbcInstruction, box;
frbc::SystemDescription => FrbcSystemDescription, box;
frbc::StorageStatus => FrbcStorageStatus;
frbc::ActuatorStatus => FrbcActuatorStatus, box;
frbc::TimerStatus => FrbcTimerStatus, box;
frbc::LeakageBehaviour => FrbcLeakageBehaviour, box;
frbc::UsageForecast => FrbcUsageForecast, box;
frbc::FillLevelTargetProfile => FrbcFillLevelTargetProfile, box;
frbc::Instruction => FrbcInstruction, box;
ddbc::SystemDescription => DdbcSystemDescription, box;
ddbc::ActuatorStatus => DdbcActuatorStatus, box;
ddbc::TimerStatus => DdbcTimerStatus, box;
ddbc::AverageDemandRateForecast => DdbcAverageDemandRateForecast, box;
ddbc::PresentDemandStatus => DdbcPresentDemandStatus;
ddbc::Instruction => DdbcInstruction, box;
];
#[cfg(test)]
mod tests {
use super::*;
use crate::types::Timestamp;
use crate::types::common::{ReceptionStatusValues, SessionRequestType};
#[test]
fn every_message_type_in_s2_json_v1_is_present() {
assert_eq!(MessageKind::ALL.len(), 36, "S2 JSON v1.0.0 has 36 messages");
let mut names: alloc::vec::Vec<_> = MessageKind::ALL.iter().map(|k| k.as_str()).collect();
names.sort_unstable();
let before = names.len();
names.dedup();
assert_eq!(names.len(), before, "duplicate message_type");
}
#[test]
fn wire_names_round_trip_through_the_parser() {
for kind in MessageKind::ALL {
assert_eq!(MessageKind::from_wire(kind.as_str()), Some(*kind));
}
assert_eq!(MessageKind::from_wire("Nope"), None);
assert_eq!(MessageKind::from_wire("frbc.instruction"), None);
}
#[test]
fn control_types_are_read_off_the_message_type_prefix() {
for kind in MessageKind::ALL {
let expected = kind
.as_str()
.split_once('.')
.and_then(|(prefix, _)| match prefix {
"PEBC" => Some(ControlType::PowerEnvelopeBasedControl),
"PPBC" => Some(ControlType::PowerProfileBasedControl),
"OMBC" => Some(ControlType::OperationModeBasedControl),
"FRBC" => Some(ControlType::FillRateBasedControl),
"DDBC" => Some(ControlType::DemandDrivenBasedControl),
_ => None,
});
assert_eq!(kind.control_type(), expected, "{kind}");
}
}
#[test]
fn instructions_are_exactly_the_seven() {
let instructions: alloc::vec::Vec<_> = MessageKind::ALL
.iter()
.filter(|k| k.is_instruction())
.map(|k| k.as_str())
.collect();
assert_eq!(
instructions,
alloc::vec![
"PEBC.Instruction",
"PPBC.ScheduleInstruction",
"PPBC.StartInterruptionInstruction",
"PPBC.EndInterruptionInstruction",
"OMBC.Instruction",
"FRBC.Instruction",
"DDBC.Instruction",
]
);
}
#[test]
fn reception_status_is_the_one_message_with_no_id_of_its_own() {
let rs = Message::from(ReceptionStatus::ok(Id::new_const("m1")));
assert_eq!(rs.id(), None);
assert_eq!(rs.subject_message_id(), Some(Id::new_const("m1")));
for kind in MessageKind::ALL {
if *kind != MessageKind::ReceptionStatus {
assert!(kind.as_str() != "ReceptionStatus");
}
}
}
#[test]
fn the_tag_is_first_on_the_wire_and_matches_the_kind() {
let m = Message::from(SessionRequest {
message_id: Id::new_const("m1"),
request: SessionRequestType::Terminate,
diagnostic_label: None,
});
let json = serde_json::to_string(&m).unwrap();
assert!(
json.starts_with(r#"{"message_type":"SessionRequest","message_id":"m1""#),
"{json}"
);
let back: Message = serde_json::from_str(&json).unwrap();
assert_eq!(back, m);
assert_eq!(back.kind(), MessageKind::SessionRequest);
}
#[test]
fn unknown_fields_are_refused_through_the_enum_too() {
let ok =
r#"{"message_type":"FRBC.StorageStatus","message_id":"m1","present_fill_level":1.0}"#;
assert!(serde_json::from_str::<Message>(ok).is_ok());
let bad = r#"{"message_type":"FRBC.StorageStatus","message_id":"m1","present_fill_level":1.0,"extra":1}"#;
assert!(serde_json::from_str::<Message>(bad).is_err());
}
#[test]
fn an_unknown_message_type_is_an_error_not_a_silent_variant() {
let json = r#"{"message_type":"FRBC.SomethingNew","message_id":"m1"}"#;
assert!(serde_json::from_str::<Message>(json).is_err());
}
#[test]
fn revokable_objects_line_up_with_the_messages_that_publish_them() {
let instruction = frbc::Instruction {
message_id: Id::new_const("m1"),
id: Id::new_const("instr0"),
actuator_id: Id::new_const("a1"),
operation_mode: Id::new_const("om1"),
operation_mode_factor: 1.0,
execution_time: Timestamp::UNIX_EPOCH,
abnormal_condition: false,
};
let m = Message::from(instruction);
assert_eq!(m.instruction_id(), Some(Id::new_const("instr0")));
let (object_type, id) = m.revokable_id().unwrap();
assert_eq!(
object_type,
crate::types::common::RevokableObjects::FrbcInstruction
);
assert_eq!(id, Id::new_const("instr0"));
assert_eq!(
object_type.control_type(),
ControlType::FillRateBasedControl
);
}
#[test]
fn the_new_message_exists_only_in_the_newer_profile() {
use crate::types::WireProfile;
assert!(MessageKind::DdbcPresentDemandStatus.exists_in(WireProfile::V1_0_0));
assert!(!MessageKind::DdbcPresentDemandStatus.exists_in(WireProfile::V0_0_2Beta));
for kind in MessageKind::ALL {
if *kind != MessageKind::DdbcPresentDemandStatus {
assert!(kind.exists_in(WireProfile::V0_0_2Beta), "{kind}");
assert!(kind.exists_in(WireProfile::V1_0_0), "{kind}");
}
}
}
#[test]
fn the_enum_stays_small_enough_to_move_cheaply() {
let size = core::mem::size_of::<Message>();
assert!(size <= 160, "Message grew to {size} bytes");
assert_eq!(core::mem::size_of::<Box<frbc::Instruction>>(), 8);
}
#[test]
fn reception_status_values_are_not_confused_with_statuses() {
let s = ReceptionStatus::error(
Id::new_const("m1"),
ReceptionStatusValues::InvalidContent,
"S2-STATE-001: nope",
);
let json = serde_json::to_string(&Message::from(s)).unwrap();
assert!(json.contains(r#""status":"INVALID_CONTENT""#));
assert!(json.contains("S2-STATE-001"));
}
}