Skip to main content

ocpp_kit/v2_0_1/
action.rs

1// @generated by `cargo xtask codegen` from the vendored OCPP JSON schemas.
2// DO NOT EDIT — re-run the generator instead. CI fails if this file is stale.
3
4//! The OCPP 2.0.1 action set, and the direction-aware payload unions used for dispatch.
5
6#![allow(unused_imports, clippy::doc_markdown, clippy::struct_excessive_bools)]
7#![allow(
8    clippy::too_many_lines,
9    clippy::too_many_arguments,
10    clippy::wildcard_imports
11)]
12#![allow(clippy::match_same_arms, clippy::fn_params_excessive_bools)]
13
14use alloc::string::String;
15use alloc::vec::Vec;
16
17use serde::{Deserialize, Serialize};
18
19use super::messages::*;
20use crate::decode::{DecodeError, DecodeOptions};
21use crate::message::{MessageKind, Origin};
22use crate::validate::{Validate, ValidationPath, Violations};
23use serde_json::value::RawValue;
24
25/// Every action defined by OCPP 2.0.1.
26///
27/// The variants are ordered as in the specification's action index.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29#[non_exhaustive]
30pub enum Action {
31    /// `Authorize` — C — Authorization.
32    Authorize,
33    /// `BootNotification` — B — Provisioning.
34    BootNotification,
35    /// `CancelReservation` — H — Reservation.
36    CancelReservation,
37    /// `CertificateSigned` — A — Security.
38    CertificateSigned,
39    /// `ChangeAvailability` — G — Availability.
40    ChangeAvailability,
41    /// `ClearCache` — C — Authorization.
42    ClearCache,
43    /// `ClearChargingProfile` — K — Smart Charging.
44    ClearChargingProfile,
45    /// `ClearDisplayMessage` — O — Display Message.
46    ClearDisplayMessage,
47    /// `ClearVariableMonitoring` — N — Diagnostics.
48    ClearVariableMonitoring,
49    /// `ClearedChargingLimit` — K — Smart Charging.
50    ClearedChargingLimit,
51    /// `CostUpdated` — I — Tariff and Cost.
52    CostUpdated,
53    /// `CustomerInformation` — N — Diagnostics.
54    CustomerInformation,
55    /// `DataTransfer` — P — Data Transfer.
56    DataTransfer,
57    /// `DeleteCertificate` — M — Certificate Management.
58    DeleteCertificate,
59    /// `FirmwareStatusNotification` — L — Firmware Management.
60    FirmwareStatusNotification,
61    /// `Get15118EVCertificate` — M — Certificate Management.
62    Get15118EVCertificate,
63    /// `GetBaseReport` — B — Provisioning.
64    GetBaseReport,
65    /// `GetCertificateStatus` — M — Certificate Management.
66    GetCertificateStatus,
67    /// `GetChargingProfiles` — K — Smart Charging.
68    GetChargingProfiles,
69    /// `GetCompositeSchedule` — K — Smart Charging.
70    GetCompositeSchedule,
71    /// `GetDisplayMessages` — O — Display Message.
72    GetDisplayMessages,
73    /// `GetInstalledCertificateIds` — M — Certificate Management.
74    GetInstalledCertificateIds,
75    /// `GetLocalListVersion` — D — Local Authorization List Management.
76    GetLocalListVersion,
77    /// `GetLog` — N — Diagnostics.
78    GetLog,
79    /// `GetMonitoringReport` — N — Diagnostics.
80    GetMonitoringReport,
81    /// `GetReport` — B — Provisioning.
82    GetReport,
83    /// `GetTransactionStatus` — E — Transactions.
84    GetTransactionStatus,
85    /// `GetVariables` — B — Provisioning.
86    GetVariables,
87    /// `Heartbeat` — G — Availability.
88    Heartbeat,
89    /// `InstallCertificate` — M — Certificate Management.
90    InstallCertificate,
91    /// `LogStatusNotification` — N — Diagnostics.
92    LogStatusNotification,
93    /// `MeterValues` — J — Meter Values.
94    MeterValues,
95    /// `NotifyChargingLimit` — K — Smart Charging.
96    NotifyChargingLimit,
97    /// `NotifyCustomerInformation` — N — Diagnostics.
98    NotifyCustomerInformation,
99    /// `NotifyDisplayMessages` — O — Display Message.
100    NotifyDisplayMessages,
101    /// `NotifyEVChargingNeeds` — K — Smart Charging.
102    NotifyEVChargingNeeds,
103    /// `NotifyEVChargingSchedule` — K — Smart Charging.
104    NotifyEVChargingSchedule,
105    /// `NotifyEvent` — N — Diagnostics.
106    NotifyEvent,
107    /// `NotifyMonitoringReport` — N — Diagnostics.
108    NotifyMonitoringReport,
109    /// `NotifyReport` — B — Provisioning.
110    NotifyReport,
111    /// `PublishFirmware` — L — Firmware Management.
112    PublishFirmware,
113    /// `PublishFirmwareStatusNotification` — L — Firmware Management.
114    PublishFirmwareStatusNotification,
115    /// `ReportChargingProfiles` — K — Smart Charging.
116    ReportChargingProfiles,
117    /// `RequestStartTransaction` — F — Remote Control.
118    RequestStartTransaction,
119    /// `RequestStopTransaction` — F — Remote Control.
120    RequestStopTransaction,
121    /// `ReservationStatusUpdate` — H — Reservation.
122    ReservationStatusUpdate,
123    /// `ReserveNow` — H — Reservation.
124    ReserveNow,
125    /// `Reset` — B — Provisioning.
126    Reset,
127    /// `SecurityEventNotification` — A — Security.
128    SecurityEventNotification,
129    /// `SendLocalList` — D — Local Authorization List Management.
130    SendLocalList,
131    /// `SetChargingProfile` — K — Smart Charging.
132    SetChargingProfile,
133    /// `SetDisplayMessage` — O — Display Message.
134    SetDisplayMessage,
135    /// `SetMonitoringBase` — N — Diagnostics.
136    SetMonitoringBase,
137    /// `SetMonitoringLevel` — N — Diagnostics.
138    SetMonitoringLevel,
139    /// `SetNetworkProfile` — B — Provisioning.
140    SetNetworkProfile,
141    /// `SetVariableMonitoring` — N — Diagnostics.
142    SetVariableMonitoring,
143    /// `SetVariables` — B — Provisioning.
144    SetVariables,
145    /// `SignCertificate` — A — Security.
146    SignCertificate,
147    /// `StatusNotification` — G — Availability.
148    StatusNotification,
149    /// `TransactionEvent` — E — Transactions.
150    TransactionEvent,
151    /// `TriggerMessage` — F — Remote Control.
152    TriggerMessage,
153    /// `UnlockConnector` — F — Remote Control.
154    UnlockConnector,
155    /// `UnpublishFirmware` — L — Firmware Management.
156    UnpublishFirmware,
157    /// `UpdateFirmware` — L — Firmware Management.
158    UpdateFirmware,
159}
160
161impl Action {
162    /// Every action of this version, in specification order.
163    pub const ALL: &'static [Action] = &[
164        Action::Authorize,
165        Action::BootNotification,
166        Action::CancelReservation,
167        Action::CertificateSigned,
168        Action::ChangeAvailability,
169        Action::ClearCache,
170        Action::ClearChargingProfile,
171        Action::ClearDisplayMessage,
172        Action::ClearVariableMonitoring,
173        Action::ClearedChargingLimit,
174        Action::CostUpdated,
175        Action::CustomerInformation,
176        Action::DataTransfer,
177        Action::DeleteCertificate,
178        Action::FirmwareStatusNotification,
179        Action::Get15118EVCertificate,
180        Action::GetBaseReport,
181        Action::GetCertificateStatus,
182        Action::GetChargingProfiles,
183        Action::GetCompositeSchedule,
184        Action::GetDisplayMessages,
185        Action::GetInstalledCertificateIds,
186        Action::GetLocalListVersion,
187        Action::GetLog,
188        Action::GetMonitoringReport,
189        Action::GetReport,
190        Action::GetTransactionStatus,
191        Action::GetVariables,
192        Action::Heartbeat,
193        Action::InstallCertificate,
194        Action::LogStatusNotification,
195        Action::MeterValues,
196        Action::NotifyChargingLimit,
197        Action::NotifyCustomerInformation,
198        Action::NotifyDisplayMessages,
199        Action::NotifyEVChargingNeeds,
200        Action::NotifyEVChargingSchedule,
201        Action::NotifyEvent,
202        Action::NotifyMonitoringReport,
203        Action::NotifyReport,
204        Action::PublishFirmware,
205        Action::PublishFirmwareStatusNotification,
206        Action::ReportChargingProfiles,
207        Action::RequestStartTransaction,
208        Action::RequestStopTransaction,
209        Action::ReservationStatusUpdate,
210        Action::ReserveNow,
211        Action::Reset,
212        Action::SecurityEventNotification,
213        Action::SendLocalList,
214        Action::SetChargingProfile,
215        Action::SetDisplayMessage,
216        Action::SetMonitoringBase,
217        Action::SetMonitoringLevel,
218        Action::SetNetworkProfile,
219        Action::SetVariableMonitoring,
220        Action::SetVariables,
221        Action::SignCertificate,
222        Action::StatusNotification,
223        Action::TransactionEvent,
224        Action::TriggerMessage,
225        Action::UnlockConnector,
226        Action::UnpublishFirmware,
227        Action::UpdateFirmware,
228    ];
229
230    /// The action name as it appears on the wire.
231    #[must_use]
232    pub const fn as_str(self) -> &'static str {
233        match self {
234            Action::Authorize => "Authorize",
235            Action::BootNotification => "BootNotification",
236            Action::CancelReservation => "CancelReservation",
237            Action::CertificateSigned => "CertificateSigned",
238            Action::ChangeAvailability => "ChangeAvailability",
239            Action::ClearCache => "ClearCache",
240            Action::ClearChargingProfile => "ClearChargingProfile",
241            Action::ClearDisplayMessage => "ClearDisplayMessage",
242            Action::ClearVariableMonitoring => "ClearVariableMonitoring",
243            Action::ClearedChargingLimit => "ClearedChargingLimit",
244            Action::CostUpdated => "CostUpdated",
245            Action::CustomerInformation => "CustomerInformation",
246            Action::DataTransfer => "DataTransfer",
247            Action::DeleteCertificate => "DeleteCertificate",
248            Action::FirmwareStatusNotification => "FirmwareStatusNotification",
249            Action::Get15118EVCertificate => "Get15118EVCertificate",
250            Action::GetBaseReport => "GetBaseReport",
251            Action::GetCertificateStatus => "GetCertificateStatus",
252            Action::GetChargingProfiles => "GetChargingProfiles",
253            Action::GetCompositeSchedule => "GetCompositeSchedule",
254            Action::GetDisplayMessages => "GetDisplayMessages",
255            Action::GetInstalledCertificateIds => "GetInstalledCertificateIds",
256            Action::GetLocalListVersion => "GetLocalListVersion",
257            Action::GetLog => "GetLog",
258            Action::GetMonitoringReport => "GetMonitoringReport",
259            Action::GetReport => "GetReport",
260            Action::GetTransactionStatus => "GetTransactionStatus",
261            Action::GetVariables => "GetVariables",
262            Action::Heartbeat => "Heartbeat",
263            Action::InstallCertificate => "InstallCertificate",
264            Action::LogStatusNotification => "LogStatusNotification",
265            Action::MeterValues => "MeterValues",
266            Action::NotifyChargingLimit => "NotifyChargingLimit",
267            Action::NotifyCustomerInformation => "NotifyCustomerInformation",
268            Action::NotifyDisplayMessages => "NotifyDisplayMessages",
269            Action::NotifyEVChargingNeeds => "NotifyEVChargingNeeds",
270            Action::NotifyEVChargingSchedule => "NotifyEVChargingSchedule",
271            Action::NotifyEvent => "NotifyEvent",
272            Action::NotifyMonitoringReport => "NotifyMonitoringReport",
273            Action::NotifyReport => "NotifyReport",
274            Action::PublishFirmware => "PublishFirmware",
275            Action::PublishFirmwareStatusNotification => "PublishFirmwareStatusNotification",
276            Action::ReportChargingProfiles => "ReportChargingProfiles",
277            Action::RequestStartTransaction => "RequestStartTransaction",
278            Action::RequestStopTransaction => "RequestStopTransaction",
279            Action::ReservationStatusUpdate => "ReservationStatusUpdate",
280            Action::ReserveNow => "ReserveNow",
281            Action::Reset => "Reset",
282            Action::SecurityEventNotification => "SecurityEventNotification",
283            Action::SendLocalList => "SendLocalList",
284            Action::SetChargingProfile => "SetChargingProfile",
285            Action::SetDisplayMessage => "SetDisplayMessage",
286            Action::SetMonitoringBase => "SetMonitoringBase",
287            Action::SetMonitoringLevel => "SetMonitoringLevel",
288            Action::SetNetworkProfile => "SetNetworkProfile",
289            Action::SetVariableMonitoring => "SetVariableMonitoring",
290            Action::SetVariables => "SetVariables",
291            Action::SignCertificate => "SignCertificate",
292            Action::StatusNotification => "StatusNotification",
293            Action::TransactionEvent => "TransactionEvent",
294            Action::TriggerMessage => "TriggerMessage",
295            Action::UnlockConnector => "UnlockConnector",
296            Action::UnpublishFirmware => "UnpublishFirmware",
297            Action::UpdateFirmware => "UpdateFirmware",
298        }
299    }
300
301    /// Parses a wire action name. Returns `None` for actions this version does not define.
302    #[must_use]
303    pub fn from_wire(name: &str) -> Option<Self> {
304        Some(match name {
305            "Authorize" => Action::Authorize,
306            "BootNotification" => Action::BootNotification,
307            "CancelReservation" => Action::CancelReservation,
308            "CertificateSigned" => Action::CertificateSigned,
309            "ChangeAvailability" => Action::ChangeAvailability,
310            "ClearCache" => Action::ClearCache,
311            "ClearChargingProfile" => Action::ClearChargingProfile,
312            "ClearDisplayMessage" => Action::ClearDisplayMessage,
313            "ClearVariableMonitoring" => Action::ClearVariableMonitoring,
314            "ClearedChargingLimit" => Action::ClearedChargingLimit,
315            "CostUpdated" => Action::CostUpdated,
316            "CustomerInformation" => Action::CustomerInformation,
317            "DataTransfer" => Action::DataTransfer,
318            "DeleteCertificate" => Action::DeleteCertificate,
319            "FirmwareStatusNotification" => Action::FirmwareStatusNotification,
320            "Get15118EVCertificate" => Action::Get15118EVCertificate,
321            "GetBaseReport" => Action::GetBaseReport,
322            "GetCertificateStatus" => Action::GetCertificateStatus,
323            "GetChargingProfiles" => Action::GetChargingProfiles,
324            "GetCompositeSchedule" => Action::GetCompositeSchedule,
325            "GetDisplayMessages" => Action::GetDisplayMessages,
326            "GetInstalledCertificateIds" => Action::GetInstalledCertificateIds,
327            "GetLocalListVersion" => Action::GetLocalListVersion,
328            "GetLog" => Action::GetLog,
329            "GetMonitoringReport" => Action::GetMonitoringReport,
330            "GetReport" => Action::GetReport,
331            "GetTransactionStatus" => Action::GetTransactionStatus,
332            "GetVariables" => Action::GetVariables,
333            "Heartbeat" => Action::Heartbeat,
334            "InstallCertificate" => Action::InstallCertificate,
335            "LogStatusNotification" => Action::LogStatusNotification,
336            "MeterValues" => Action::MeterValues,
337            "NotifyChargingLimit" => Action::NotifyChargingLimit,
338            "NotifyCustomerInformation" => Action::NotifyCustomerInformation,
339            "NotifyDisplayMessages" => Action::NotifyDisplayMessages,
340            "NotifyEVChargingNeeds" => Action::NotifyEVChargingNeeds,
341            "NotifyEVChargingSchedule" => Action::NotifyEVChargingSchedule,
342            "NotifyEvent" => Action::NotifyEvent,
343            "NotifyMonitoringReport" => Action::NotifyMonitoringReport,
344            "NotifyReport" => Action::NotifyReport,
345            "PublishFirmware" => Action::PublishFirmware,
346            "PublishFirmwareStatusNotification" => Action::PublishFirmwareStatusNotification,
347            "ReportChargingProfiles" => Action::ReportChargingProfiles,
348            "RequestStartTransaction" => Action::RequestStartTransaction,
349            "RequestStopTransaction" => Action::RequestStopTransaction,
350            "ReservationStatusUpdate" => Action::ReservationStatusUpdate,
351            "ReserveNow" => Action::ReserveNow,
352            "Reset" => Action::Reset,
353            "SecurityEventNotification" => Action::SecurityEventNotification,
354            "SendLocalList" => Action::SendLocalList,
355            "SetChargingProfile" => Action::SetChargingProfile,
356            "SetDisplayMessage" => Action::SetDisplayMessage,
357            "SetMonitoringBase" => Action::SetMonitoringBase,
358            "SetMonitoringLevel" => Action::SetMonitoringLevel,
359            "SetNetworkProfile" => Action::SetNetworkProfile,
360            "SetVariableMonitoring" => Action::SetVariableMonitoring,
361            "SetVariables" => Action::SetVariables,
362            "SignCertificate" => Action::SignCertificate,
363            "StatusNotification" => Action::StatusNotification,
364            "TransactionEvent" => Action::TransactionEvent,
365            "TriggerMessage" => Action::TriggerMessage,
366            "UnlockConnector" => Action::UnlockConnector,
367            "UnpublishFirmware" => Action::UnpublishFirmware,
368            "UpdateFirmware" => Action::UpdateFirmware,
369            _ => return None,
370        })
371    }
372
373    /// Whether this action is a `CALL` or an unconfirmed `SEND`.
374    #[must_use]
375    pub const fn kind(self) -> MessageKind {
376        MessageKind::Call
377    }
378
379    /// Which peer originates this action.
380    #[must_use]
381    pub const fn origin(self) -> Origin {
382        match self {
383            Action::Authorize => Origin::ChargingStation,
384            Action::BootNotification => Origin::ChargingStation,
385            Action::CancelReservation => Origin::Csms,
386            Action::CertificateSigned => Origin::Csms,
387            Action::ChangeAvailability => Origin::Csms,
388            Action::ClearCache => Origin::Csms,
389            Action::ClearChargingProfile => Origin::Csms,
390            Action::ClearDisplayMessage => Origin::Csms,
391            Action::ClearVariableMonitoring => Origin::Csms,
392            Action::ClearedChargingLimit => Origin::ChargingStation,
393            Action::CostUpdated => Origin::Csms,
394            Action::CustomerInformation => Origin::Csms,
395            Action::DataTransfer => Origin::Both,
396            Action::DeleteCertificate => Origin::Csms,
397            Action::FirmwareStatusNotification => Origin::ChargingStation,
398            Action::Get15118EVCertificate => Origin::ChargingStation,
399            Action::GetBaseReport => Origin::Csms,
400            Action::GetCertificateStatus => Origin::ChargingStation,
401            Action::GetChargingProfiles => Origin::Csms,
402            Action::GetCompositeSchedule => Origin::Csms,
403            Action::GetDisplayMessages => Origin::Csms,
404            Action::GetInstalledCertificateIds => Origin::Csms,
405            Action::GetLocalListVersion => Origin::Csms,
406            Action::GetLog => Origin::Csms,
407            Action::GetMonitoringReport => Origin::Csms,
408            Action::GetReport => Origin::Csms,
409            Action::GetTransactionStatus => Origin::Csms,
410            Action::GetVariables => Origin::Csms,
411            Action::Heartbeat => Origin::ChargingStation,
412            Action::InstallCertificate => Origin::Csms,
413            Action::LogStatusNotification => Origin::ChargingStation,
414            Action::MeterValues => Origin::ChargingStation,
415            Action::NotifyChargingLimit => Origin::ChargingStation,
416            Action::NotifyCustomerInformation => Origin::ChargingStation,
417            Action::NotifyDisplayMessages => Origin::ChargingStation,
418            Action::NotifyEVChargingNeeds => Origin::ChargingStation,
419            Action::NotifyEVChargingSchedule => Origin::ChargingStation,
420            Action::NotifyEvent => Origin::ChargingStation,
421            Action::NotifyMonitoringReport => Origin::ChargingStation,
422            Action::NotifyReport => Origin::ChargingStation,
423            Action::PublishFirmware => Origin::Csms,
424            Action::PublishFirmwareStatusNotification => Origin::ChargingStation,
425            Action::ReportChargingProfiles => Origin::ChargingStation,
426            Action::RequestStartTransaction => Origin::Csms,
427            Action::RequestStopTransaction => Origin::Csms,
428            Action::ReservationStatusUpdate => Origin::ChargingStation,
429            Action::ReserveNow => Origin::Csms,
430            Action::Reset => Origin::Csms,
431            Action::SecurityEventNotification => Origin::ChargingStation,
432            Action::SendLocalList => Origin::Csms,
433            Action::SetChargingProfile => Origin::Csms,
434            Action::SetDisplayMessage => Origin::Csms,
435            Action::SetMonitoringBase => Origin::Csms,
436            Action::SetMonitoringLevel => Origin::Csms,
437            Action::SetNetworkProfile => Origin::Csms,
438            Action::SetVariableMonitoring => Origin::Csms,
439            Action::SetVariables => Origin::Csms,
440            Action::SignCertificate => Origin::ChargingStation,
441            Action::StatusNotification => Origin::ChargingStation,
442            Action::TransactionEvent => Origin::ChargingStation,
443            Action::TriggerMessage => Origin::Csms,
444            Action::UnlockConnector => Origin::Csms,
445            Action::UnpublishFirmware => Origin::Csms,
446            Action::UpdateFirmware => Origin::Csms,
447        }
448    }
449
450    /// The functional block (2.x) or feature profile (1.6) this action belongs to.
451    #[must_use]
452    pub const fn block(self) -> &'static str {
453        match self {
454            Action::Authorize => "C",
455            Action::BootNotification => "B",
456            Action::CancelReservation => "H",
457            Action::CertificateSigned => "A",
458            Action::ChangeAvailability => "G",
459            Action::ClearCache => "C",
460            Action::ClearChargingProfile => "K",
461            Action::ClearDisplayMessage => "O",
462            Action::ClearVariableMonitoring => "N",
463            Action::ClearedChargingLimit => "K",
464            Action::CostUpdated => "I",
465            Action::CustomerInformation => "N",
466            Action::DataTransfer => "P",
467            Action::DeleteCertificate => "M",
468            Action::FirmwareStatusNotification => "L",
469            Action::Get15118EVCertificate => "M",
470            Action::GetBaseReport => "B",
471            Action::GetCertificateStatus => "M",
472            Action::GetChargingProfiles => "K",
473            Action::GetCompositeSchedule => "K",
474            Action::GetDisplayMessages => "O",
475            Action::GetInstalledCertificateIds => "M",
476            Action::GetLocalListVersion => "D",
477            Action::GetLog => "N",
478            Action::GetMonitoringReport => "N",
479            Action::GetReport => "B",
480            Action::GetTransactionStatus => "E",
481            Action::GetVariables => "B",
482            Action::Heartbeat => "G",
483            Action::InstallCertificate => "M",
484            Action::LogStatusNotification => "N",
485            Action::MeterValues => "J",
486            Action::NotifyChargingLimit => "K",
487            Action::NotifyCustomerInformation => "N",
488            Action::NotifyDisplayMessages => "O",
489            Action::NotifyEVChargingNeeds => "K",
490            Action::NotifyEVChargingSchedule => "K",
491            Action::NotifyEvent => "N",
492            Action::NotifyMonitoringReport => "N",
493            Action::NotifyReport => "B",
494            Action::PublishFirmware => "L",
495            Action::PublishFirmwareStatusNotification => "L",
496            Action::ReportChargingProfiles => "K",
497            Action::RequestStartTransaction => "F",
498            Action::RequestStopTransaction => "F",
499            Action::ReservationStatusUpdate => "H",
500            Action::ReserveNow => "H",
501            Action::Reset => "B",
502            Action::SecurityEventNotification => "A",
503            Action::SendLocalList => "D",
504            Action::SetChargingProfile => "K",
505            Action::SetDisplayMessage => "O",
506            Action::SetMonitoringBase => "N",
507            Action::SetMonitoringLevel => "N",
508            Action::SetNetworkProfile => "B",
509            Action::SetVariableMonitoring => "N",
510            Action::SetVariables => "B",
511            Action::SignCertificate => "A",
512            Action::StatusNotification => "G",
513            Action::TransactionEvent => "E",
514            Action::TriggerMessage => "F",
515            Action::UnlockConnector => "F",
516            Action::UnpublishFirmware => "L",
517            Action::UpdateFirmware => "L",
518        }
519    }
520}
521
522impl crate::message::ActionName for Action {
523    fn all() -> &'static [Self] {
524        Self::ALL
525    }
526    fn as_str(&self) -> &'static str {
527        Action::as_str(*self)
528    }
529    fn from_wire(name: &str) -> Option<Self> {
530        Action::from_wire(name)
531    }
532    fn kind(&self) -> MessageKind {
533        Action::kind(*self)
534    }
535    fn origin(&self) -> Origin {
536        Action::origin(*self)
537    }
538    fn block(&self) -> &'static str {
539        Action::block(*self)
540    }
541}
542
543impl core::fmt::Display for Action {
544    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
545        f.write_str(self.as_str())
546    }
547}
548
549impl core::str::FromStr for Action {
550    type Err = crate::message::UnknownAction;
551    fn from_str(s: &str) -> Result<Self, Self::Err> {
552        Self::from_wire(s).ok_or(crate::message::UnknownAction)
553    }
554}
555
556impl Serialize for Action {
557    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
558        ser.serialize_str(self.as_str())
559    }
560}
561
562impl<'de> Deserialize<'de> for Action {
563    fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
564        let s = <&str as Deserialize>::deserialize(de)?;
565        Self::from_wire(s).ok_or_else(|| serde::de::Error::custom("unknown OCPP action"))
566    }
567}
568
569impl Action {
570    /// Whether this action is answered at all.
571    ///
572    /// `false` only for a `SEND` (OCPP 2.1 `NotifyPeriodicEventStream`).
573    #[must_use]
574    pub const fn has_response(self) -> bool {
575        matches!(self.kind(), MessageKind::Call)
576    }
577}
578
579/// Decodes a request payload into its typed form and serializes it back.
580///
581/// The round trip is the strongest cheap check that the generated types cover a payload
582/// completely: anything the types do not model is missing from the output. It backs
583/// `ocpp-cli validate` and the schema conformance suite.
584pub fn transcode_request(
585    action: Action,
586    payload: &RawValue,
587    options: &DecodeOptions,
588) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
589    match action {
590        Action::Authorize => crate::decode::transcode::<AuthorizeRequest>(payload, options),
591        Action::BootNotification => {
592            crate::decode::transcode::<BootNotificationRequest>(payload, options)
593        }
594        Action::CancelReservation => {
595            crate::decode::transcode::<CancelReservationRequest>(payload, options)
596        }
597        Action::CertificateSigned => {
598            crate::decode::transcode::<CertificateSignedRequest>(payload, options)
599        }
600        Action::ChangeAvailability => {
601            crate::decode::transcode::<ChangeAvailabilityRequest>(payload, options)
602        }
603        Action::ClearCache => crate::decode::transcode::<ClearCacheRequest>(payload, options),
604        Action::ClearChargingProfile => {
605            crate::decode::transcode::<ClearChargingProfileRequest>(payload, options)
606        }
607        Action::ClearDisplayMessage => {
608            crate::decode::transcode::<ClearDisplayMessageRequest>(payload, options)
609        }
610        Action::ClearVariableMonitoring => {
611            crate::decode::transcode::<ClearVariableMonitoringRequest>(payload, options)
612        }
613        Action::ClearedChargingLimit => {
614            crate::decode::transcode::<ClearedChargingLimitRequest>(payload, options)
615        }
616        Action::CostUpdated => crate::decode::transcode::<CostUpdatedRequest>(payload, options),
617        Action::CustomerInformation => {
618            crate::decode::transcode::<CustomerInformationRequest>(payload, options)
619        }
620        Action::DataTransfer => crate::decode::transcode::<DataTransferRequest>(payload, options),
621        Action::DeleteCertificate => {
622            crate::decode::transcode::<DeleteCertificateRequest>(payload, options)
623        }
624        Action::FirmwareStatusNotification => {
625            crate::decode::transcode::<FirmwareStatusNotificationRequest>(payload, options)
626        }
627        Action::Get15118EVCertificate => {
628            crate::decode::transcode::<Get15118EVCertificateRequest>(payload, options)
629        }
630        Action::GetBaseReport => crate::decode::transcode::<GetBaseReportRequest>(payload, options),
631        Action::GetCertificateStatus => {
632            crate::decode::transcode::<GetCertificateStatusRequest>(payload, options)
633        }
634        Action::GetChargingProfiles => {
635            crate::decode::transcode::<GetChargingProfilesRequest>(payload, options)
636        }
637        Action::GetCompositeSchedule => {
638            crate::decode::transcode::<GetCompositeScheduleRequest>(payload, options)
639        }
640        Action::GetDisplayMessages => {
641            crate::decode::transcode::<GetDisplayMessagesRequest>(payload, options)
642        }
643        Action::GetInstalledCertificateIds => {
644            crate::decode::transcode::<GetInstalledCertificateIdsRequest>(payload, options)
645        }
646        Action::GetLocalListVersion => {
647            crate::decode::transcode::<GetLocalListVersionRequest>(payload, options)
648        }
649        Action::GetLog => crate::decode::transcode::<GetLogRequest>(payload, options),
650        Action::GetMonitoringReport => {
651            crate::decode::transcode::<GetMonitoringReportRequest>(payload, options)
652        }
653        Action::GetReport => crate::decode::transcode::<GetReportRequest>(payload, options),
654        Action::GetTransactionStatus => {
655            crate::decode::transcode::<GetTransactionStatusRequest>(payload, options)
656        }
657        Action::GetVariables => crate::decode::transcode::<GetVariablesRequest>(payload, options),
658        Action::Heartbeat => crate::decode::transcode::<HeartbeatRequest>(payload, options),
659        Action::InstallCertificate => {
660            crate::decode::transcode::<InstallCertificateRequest>(payload, options)
661        }
662        Action::LogStatusNotification => {
663            crate::decode::transcode::<LogStatusNotificationRequest>(payload, options)
664        }
665        Action::MeterValues => crate::decode::transcode::<MeterValuesRequest>(payload, options),
666        Action::NotifyChargingLimit => {
667            crate::decode::transcode::<NotifyChargingLimitRequest>(payload, options)
668        }
669        Action::NotifyCustomerInformation => {
670            crate::decode::transcode::<NotifyCustomerInformationRequest>(payload, options)
671        }
672        Action::NotifyDisplayMessages => {
673            crate::decode::transcode::<NotifyDisplayMessagesRequest>(payload, options)
674        }
675        Action::NotifyEVChargingNeeds => {
676            crate::decode::transcode::<NotifyEVChargingNeedsRequest>(payload, options)
677        }
678        Action::NotifyEVChargingSchedule => {
679            crate::decode::transcode::<NotifyEVChargingScheduleRequest>(payload, options)
680        }
681        Action::NotifyEvent => crate::decode::transcode::<NotifyEventRequest>(payload, options),
682        Action::NotifyMonitoringReport => {
683            crate::decode::transcode::<NotifyMonitoringReportRequest>(payload, options)
684        }
685        Action::NotifyReport => crate::decode::transcode::<NotifyReportRequest>(payload, options),
686        Action::PublishFirmware => {
687            crate::decode::transcode::<PublishFirmwareRequest>(payload, options)
688        }
689        Action::PublishFirmwareStatusNotification => {
690            crate::decode::transcode::<PublishFirmwareStatusNotificationRequest>(payload, options)
691        }
692        Action::ReportChargingProfiles => {
693            crate::decode::transcode::<ReportChargingProfilesRequest>(payload, options)
694        }
695        Action::RequestStartTransaction => {
696            crate::decode::transcode::<RequestStartTransactionRequest>(payload, options)
697        }
698        Action::RequestStopTransaction => {
699            crate::decode::transcode::<RequestStopTransactionRequest>(payload, options)
700        }
701        Action::ReservationStatusUpdate => {
702            crate::decode::transcode::<ReservationStatusUpdateRequest>(payload, options)
703        }
704        Action::ReserveNow => crate::decode::transcode::<ReserveNowRequest>(payload, options),
705        Action::Reset => crate::decode::transcode::<ResetRequest>(payload, options),
706        Action::SecurityEventNotification => {
707            crate::decode::transcode::<SecurityEventNotificationRequest>(payload, options)
708        }
709        Action::SendLocalList => crate::decode::transcode::<SendLocalListRequest>(payload, options),
710        Action::SetChargingProfile => {
711            crate::decode::transcode::<SetChargingProfileRequest>(payload, options)
712        }
713        Action::SetDisplayMessage => {
714            crate::decode::transcode::<SetDisplayMessageRequest>(payload, options)
715        }
716        Action::SetMonitoringBase => {
717            crate::decode::transcode::<SetMonitoringBaseRequest>(payload, options)
718        }
719        Action::SetMonitoringLevel => {
720            crate::decode::transcode::<SetMonitoringLevelRequest>(payload, options)
721        }
722        Action::SetNetworkProfile => {
723            crate::decode::transcode::<SetNetworkProfileRequest>(payload, options)
724        }
725        Action::SetVariableMonitoring => {
726            crate::decode::transcode::<SetVariableMonitoringRequest>(payload, options)
727        }
728        Action::SetVariables => crate::decode::transcode::<SetVariablesRequest>(payload, options),
729        Action::SignCertificate => {
730            crate::decode::transcode::<SignCertificateRequest>(payload, options)
731        }
732        Action::StatusNotification => {
733            crate::decode::transcode::<StatusNotificationRequest>(payload, options)
734        }
735        Action::TransactionEvent => {
736            crate::decode::transcode::<TransactionEventRequest>(payload, options)
737        }
738        Action::TriggerMessage => {
739            crate::decode::transcode::<TriggerMessageRequest>(payload, options)
740        }
741        Action::UnlockConnector => {
742            crate::decode::transcode::<UnlockConnectorRequest>(payload, options)
743        }
744        Action::UnpublishFirmware => {
745            crate::decode::transcode::<UnpublishFirmwareRequest>(payload, options)
746        }
747        Action::UpdateFirmware => {
748            crate::decode::transcode::<UpdateFirmwareRequest>(payload, options)
749        }
750    }
751}
752
753/// Decodes a response payload into its typed form and serializes it back.
754///
755/// Returns [`DecodeError::unsupported_action`] for a `SEND`, which has no response.
756pub fn transcode_response(
757    action: Action,
758    payload: &RawValue,
759    options: &DecodeOptions,
760) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
761    match action {
762        Action::Authorize => crate::decode::transcode::<AuthorizeResponse>(payload, options),
763        Action::BootNotification => {
764            crate::decode::transcode::<BootNotificationResponse>(payload, options)
765        }
766        Action::CancelReservation => {
767            crate::decode::transcode::<CancelReservationResponse>(payload, options)
768        }
769        Action::CertificateSigned => {
770            crate::decode::transcode::<CertificateSignedResponse>(payload, options)
771        }
772        Action::ChangeAvailability => {
773            crate::decode::transcode::<ChangeAvailabilityResponse>(payload, options)
774        }
775        Action::ClearCache => crate::decode::transcode::<ClearCacheResponse>(payload, options),
776        Action::ClearChargingProfile => {
777            crate::decode::transcode::<ClearChargingProfileResponse>(payload, options)
778        }
779        Action::ClearDisplayMessage => {
780            crate::decode::transcode::<ClearDisplayMessageResponse>(payload, options)
781        }
782        Action::ClearVariableMonitoring => {
783            crate::decode::transcode::<ClearVariableMonitoringResponse>(payload, options)
784        }
785        Action::ClearedChargingLimit => {
786            crate::decode::transcode::<ClearedChargingLimitResponse>(payload, options)
787        }
788        Action::CostUpdated => crate::decode::transcode::<CostUpdatedResponse>(payload, options),
789        Action::CustomerInformation => {
790            crate::decode::transcode::<CustomerInformationResponse>(payload, options)
791        }
792        Action::DataTransfer => crate::decode::transcode::<DataTransferResponse>(payload, options),
793        Action::DeleteCertificate => {
794            crate::decode::transcode::<DeleteCertificateResponse>(payload, options)
795        }
796        Action::FirmwareStatusNotification => {
797            crate::decode::transcode::<FirmwareStatusNotificationResponse>(payload, options)
798        }
799        Action::Get15118EVCertificate => {
800            crate::decode::transcode::<Get15118EVCertificateResponse>(payload, options)
801        }
802        Action::GetBaseReport => {
803            crate::decode::transcode::<GetBaseReportResponse>(payload, options)
804        }
805        Action::GetCertificateStatus => {
806            crate::decode::transcode::<GetCertificateStatusResponse>(payload, options)
807        }
808        Action::GetChargingProfiles => {
809            crate::decode::transcode::<GetChargingProfilesResponse>(payload, options)
810        }
811        Action::GetCompositeSchedule => {
812            crate::decode::transcode::<GetCompositeScheduleResponse>(payload, options)
813        }
814        Action::GetDisplayMessages => {
815            crate::decode::transcode::<GetDisplayMessagesResponse>(payload, options)
816        }
817        Action::GetInstalledCertificateIds => {
818            crate::decode::transcode::<GetInstalledCertificateIdsResponse>(payload, options)
819        }
820        Action::GetLocalListVersion => {
821            crate::decode::transcode::<GetLocalListVersionResponse>(payload, options)
822        }
823        Action::GetLog => crate::decode::transcode::<GetLogResponse>(payload, options),
824        Action::GetMonitoringReport => {
825            crate::decode::transcode::<GetMonitoringReportResponse>(payload, options)
826        }
827        Action::GetReport => crate::decode::transcode::<GetReportResponse>(payload, options),
828        Action::GetTransactionStatus => {
829            crate::decode::transcode::<GetTransactionStatusResponse>(payload, options)
830        }
831        Action::GetVariables => crate::decode::transcode::<GetVariablesResponse>(payload, options),
832        Action::Heartbeat => crate::decode::transcode::<HeartbeatResponse>(payload, options),
833        Action::InstallCertificate => {
834            crate::decode::transcode::<InstallCertificateResponse>(payload, options)
835        }
836        Action::LogStatusNotification => {
837            crate::decode::transcode::<LogStatusNotificationResponse>(payload, options)
838        }
839        Action::MeterValues => crate::decode::transcode::<MeterValuesResponse>(payload, options),
840        Action::NotifyChargingLimit => {
841            crate::decode::transcode::<NotifyChargingLimitResponse>(payload, options)
842        }
843        Action::NotifyCustomerInformation => {
844            crate::decode::transcode::<NotifyCustomerInformationResponse>(payload, options)
845        }
846        Action::NotifyDisplayMessages => {
847            crate::decode::transcode::<NotifyDisplayMessagesResponse>(payload, options)
848        }
849        Action::NotifyEVChargingNeeds => {
850            crate::decode::transcode::<NotifyEVChargingNeedsResponse>(payload, options)
851        }
852        Action::NotifyEVChargingSchedule => {
853            crate::decode::transcode::<NotifyEVChargingScheduleResponse>(payload, options)
854        }
855        Action::NotifyEvent => crate::decode::transcode::<NotifyEventResponse>(payload, options),
856        Action::NotifyMonitoringReport => {
857            crate::decode::transcode::<NotifyMonitoringReportResponse>(payload, options)
858        }
859        Action::NotifyReport => crate::decode::transcode::<NotifyReportResponse>(payload, options),
860        Action::PublishFirmware => {
861            crate::decode::transcode::<PublishFirmwareResponse>(payload, options)
862        }
863        Action::PublishFirmwareStatusNotification => {
864            crate::decode::transcode::<PublishFirmwareStatusNotificationResponse>(payload, options)
865        }
866        Action::ReportChargingProfiles => {
867            crate::decode::transcode::<ReportChargingProfilesResponse>(payload, options)
868        }
869        Action::RequestStartTransaction => {
870            crate::decode::transcode::<RequestStartTransactionResponse>(payload, options)
871        }
872        Action::RequestStopTransaction => {
873            crate::decode::transcode::<RequestStopTransactionResponse>(payload, options)
874        }
875        Action::ReservationStatusUpdate => {
876            crate::decode::transcode::<ReservationStatusUpdateResponse>(payload, options)
877        }
878        Action::ReserveNow => crate::decode::transcode::<ReserveNowResponse>(payload, options),
879        Action::Reset => crate::decode::transcode::<ResetResponse>(payload, options),
880        Action::SecurityEventNotification => {
881            crate::decode::transcode::<SecurityEventNotificationResponse>(payload, options)
882        }
883        Action::SendLocalList => {
884            crate::decode::transcode::<SendLocalListResponse>(payload, options)
885        }
886        Action::SetChargingProfile => {
887            crate::decode::transcode::<SetChargingProfileResponse>(payload, options)
888        }
889        Action::SetDisplayMessage => {
890            crate::decode::transcode::<SetDisplayMessageResponse>(payload, options)
891        }
892        Action::SetMonitoringBase => {
893            crate::decode::transcode::<SetMonitoringBaseResponse>(payload, options)
894        }
895        Action::SetMonitoringLevel => {
896            crate::decode::transcode::<SetMonitoringLevelResponse>(payload, options)
897        }
898        Action::SetNetworkProfile => {
899            crate::decode::transcode::<SetNetworkProfileResponse>(payload, options)
900        }
901        Action::SetVariableMonitoring => {
902            crate::decode::transcode::<SetVariableMonitoringResponse>(payload, options)
903        }
904        Action::SetVariables => crate::decode::transcode::<SetVariablesResponse>(payload, options),
905        Action::SignCertificate => {
906            crate::decode::transcode::<SignCertificateResponse>(payload, options)
907        }
908        Action::StatusNotification => {
909            crate::decode::transcode::<StatusNotificationResponse>(payload, options)
910        }
911        Action::TransactionEvent => {
912            crate::decode::transcode::<TransactionEventResponse>(payload, options)
913        }
914        Action::TriggerMessage => {
915            crate::decode::transcode::<TriggerMessageResponse>(payload, options)
916        }
917        Action::UnlockConnector => {
918            crate::decode::transcode::<UnlockConnectorResponse>(payload, options)
919        }
920        Action::UnpublishFirmware => {
921            crate::decode::transcode::<UnpublishFirmwareResponse>(payload, options)
922        }
923        Action::UpdateFirmware => {
924            crate::decode::transcode::<UpdateFirmwareResponse>(payload, options)
925        }
926    }
927}
928
929/// A request originated by the **Charging Station** (CS → CSMS) in OCPP 2.0.1.
930#[derive(Clone, Debug, PartialEq)]
931#[non_exhaustive]
932#[allow(clippy::large_enum_variant)]
933pub enum CsRequest {
934    /// `Authorize`.
935    Authorize(AuthorizeRequest),
936    /// `BootNotification`.
937    BootNotification(BootNotificationRequest),
938    /// `ClearedChargingLimit`.
939    ClearedChargingLimit(ClearedChargingLimitRequest),
940    /// `DataTransfer`.
941    DataTransfer(DataTransferRequest),
942    /// `FirmwareStatusNotification`.
943    FirmwareStatusNotification(FirmwareStatusNotificationRequest),
944    /// `Get15118EVCertificate`.
945    Get15118EVCertificate(Get15118EVCertificateRequest),
946    /// `GetCertificateStatus`.
947    GetCertificateStatus(GetCertificateStatusRequest),
948    /// `Heartbeat`.
949    Heartbeat(HeartbeatRequest),
950    /// `LogStatusNotification`.
951    LogStatusNotification(LogStatusNotificationRequest),
952    /// `MeterValues`.
953    MeterValues(MeterValuesRequest),
954    /// `NotifyChargingLimit`.
955    NotifyChargingLimit(NotifyChargingLimitRequest),
956    /// `NotifyCustomerInformation`.
957    NotifyCustomerInformation(NotifyCustomerInformationRequest),
958    /// `NotifyDisplayMessages`.
959    NotifyDisplayMessages(NotifyDisplayMessagesRequest),
960    /// `NotifyEVChargingNeeds`.
961    NotifyEVChargingNeeds(NotifyEVChargingNeedsRequest),
962    /// `NotifyEVChargingSchedule`.
963    NotifyEVChargingSchedule(NotifyEVChargingScheduleRequest),
964    /// `NotifyEvent`.
965    NotifyEvent(NotifyEventRequest),
966    /// `NotifyMonitoringReport`.
967    NotifyMonitoringReport(NotifyMonitoringReportRequest),
968    /// `NotifyReport`.
969    NotifyReport(NotifyReportRequest),
970    /// `PublishFirmwareStatusNotification`.
971    PublishFirmwareStatusNotification(PublishFirmwareStatusNotificationRequest),
972    /// `ReportChargingProfiles`.
973    ReportChargingProfiles(ReportChargingProfilesRequest),
974    /// `ReservationStatusUpdate`.
975    ReservationStatusUpdate(ReservationStatusUpdateRequest),
976    /// `SecurityEventNotification`.
977    SecurityEventNotification(SecurityEventNotificationRequest),
978    /// `SignCertificate`.
979    SignCertificate(SignCertificateRequest),
980    /// `StatusNotification`.
981    StatusNotification(StatusNotificationRequest),
982    /// `TransactionEvent`.
983    TransactionEvent(TransactionEventRequest),
984}
985
986impl CsRequest {
987    /// The action this payload belongs to.
988    #[must_use]
989    pub const fn action(&self) -> Action {
990        match self {
991            Self::Authorize(_) => Action::Authorize,
992            Self::BootNotification(_) => Action::BootNotification,
993            Self::ClearedChargingLimit(_) => Action::ClearedChargingLimit,
994            Self::DataTransfer(_) => Action::DataTransfer,
995            Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
996            Self::Get15118EVCertificate(_) => Action::Get15118EVCertificate,
997            Self::GetCertificateStatus(_) => Action::GetCertificateStatus,
998            Self::Heartbeat(_) => Action::Heartbeat,
999            Self::LogStatusNotification(_) => Action::LogStatusNotification,
1000            Self::MeterValues(_) => Action::MeterValues,
1001            Self::NotifyChargingLimit(_) => Action::NotifyChargingLimit,
1002            Self::NotifyCustomerInformation(_) => Action::NotifyCustomerInformation,
1003            Self::NotifyDisplayMessages(_) => Action::NotifyDisplayMessages,
1004            Self::NotifyEVChargingNeeds(_) => Action::NotifyEVChargingNeeds,
1005            Self::NotifyEVChargingSchedule(_) => Action::NotifyEVChargingSchedule,
1006            Self::NotifyEvent(_) => Action::NotifyEvent,
1007            Self::NotifyMonitoringReport(_) => Action::NotifyMonitoringReport,
1008            Self::NotifyReport(_) => Action::NotifyReport,
1009            Self::PublishFirmwareStatusNotification(_) => Action::PublishFirmwareStatusNotification,
1010            Self::ReportChargingProfiles(_) => Action::ReportChargingProfiles,
1011            Self::ReservationStatusUpdate(_) => Action::ReservationStatusUpdate,
1012            Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
1013            Self::SignCertificate(_) => Action::SignCertificate,
1014            Self::StatusNotification(_) => Action::StatusNotification,
1015            Self::TransactionEvent(_) => Action::TransactionEvent,
1016        }
1017    }
1018
1019    /// Decodes a raw JSON payload for `action`, classifying every failure so the
1020    /// caller can answer with the correct OCPP error code.
1021    pub fn decode(
1022        action: Action,
1023        payload: &RawValue,
1024        options: &DecodeOptions,
1025    ) -> Result<Self, DecodeError> {
1026        Ok(match action {
1027            Action::Authorize => Self::Authorize(
1028                crate::decode::decode_payload::<AuthorizeRequest>(payload, options)?,
1029            ),
1030            Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
1031                BootNotificationRequest,
1032            >(payload, options)?),
1033            Action::ClearedChargingLimit => {
1034                Self::ClearedChargingLimit(crate::decode::decode_payload::<
1035                    ClearedChargingLimitRequest,
1036                >(payload, options)?)
1037            }
1038            Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
1039                DataTransferRequest,
1040            >(payload, options)?),
1041            Action::FirmwareStatusNotification => {
1042                Self::FirmwareStatusNotification(crate::decode::decode_payload::<
1043                    FirmwareStatusNotificationRequest,
1044                >(payload, options)?)
1045            }
1046            Action::Get15118EVCertificate => {
1047                Self::Get15118EVCertificate(crate::decode::decode_payload::<
1048                    Get15118EVCertificateRequest,
1049                >(payload, options)?)
1050            }
1051            Action::GetCertificateStatus => {
1052                Self::GetCertificateStatus(crate::decode::decode_payload::<
1053                    GetCertificateStatusRequest,
1054                >(payload, options)?)
1055            }
1056            Action::Heartbeat => Self::Heartbeat(
1057                crate::decode::decode_payload::<HeartbeatRequest>(payload, options)?,
1058            ),
1059            Action::LogStatusNotification => {
1060                Self::LogStatusNotification(crate::decode::decode_payload::<
1061                    LogStatusNotificationRequest,
1062                >(payload, options)?)
1063            }
1064            Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
1065                MeterValuesRequest,
1066            >(payload, options)?),
1067            Action::NotifyChargingLimit => {
1068                Self::NotifyChargingLimit(crate::decode::decode_payload::<
1069                    NotifyChargingLimitRequest,
1070                >(payload, options)?)
1071            }
1072            Action::NotifyCustomerInformation => {
1073                Self::NotifyCustomerInformation(crate::decode::decode_payload::<
1074                    NotifyCustomerInformationRequest,
1075                >(payload, options)?)
1076            }
1077            Action::NotifyDisplayMessages => {
1078                Self::NotifyDisplayMessages(crate::decode::decode_payload::<
1079                    NotifyDisplayMessagesRequest,
1080                >(payload, options)?)
1081            }
1082            Action::NotifyEVChargingNeeds => {
1083                Self::NotifyEVChargingNeeds(crate::decode::decode_payload::<
1084                    NotifyEVChargingNeedsRequest,
1085                >(payload, options)?)
1086            }
1087            Action::NotifyEVChargingSchedule => {
1088                Self::NotifyEVChargingSchedule(crate::decode::decode_payload::<
1089                    NotifyEVChargingScheduleRequest,
1090                >(payload, options)?)
1091            }
1092            Action::NotifyEvent => Self::NotifyEvent(crate::decode::decode_payload::<
1093                NotifyEventRequest,
1094            >(payload, options)?),
1095            Action::NotifyMonitoringReport => {
1096                Self::NotifyMonitoringReport(crate::decode::decode_payload::<
1097                    NotifyMonitoringReportRequest,
1098                >(payload, options)?)
1099            }
1100            Action::NotifyReport => Self::NotifyReport(crate::decode::decode_payload::<
1101                NotifyReportRequest,
1102            >(payload, options)?),
1103            Action::PublishFirmwareStatusNotification => {
1104                Self::PublishFirmwareStatusNotification(crate::decode::decode_payload::<
1105                    PublishFirmwareStatusNotificationRequest,
1106                >(payload, options)?)
1107            }
1108            Action::ReportChargingProfiles => {
1109                Self::ReportChargingProfiles(crate::decode::decode_payload::<
1110                    ReportChargingProfilesRequest,
1111                >(payload, options)?)
1112            }
1113            Action::ReservationStatusUpdate => {
1114                Self::ReservationStatusUpdate(crate::decode::decode_payload::<
1115                    ReservationStatusUpdateRequest,
1116                >(payload, options)?)
1117            }
1118            Action::SecurityEventNotification => {
1119                Self::SecurityEventNotification(crate::decode::decode_payload::<
1120                    SecurityEventNotificationRequest,
1121                >(payload, options)?)
1122            }
1123            Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
1124                SignCertificateRequest,
1125            >(payload, options)?),
1126            Action::StatusNotification => Self::StatusNotification(
1127                crate::decode::decode_payload::<StatusNotificationRequest>(payload, options)?,
1128            ),
1129            Action::TransactionEvent => Self::TransactionEvent(crate::decode::decode_payload::<
1130                TransactionEventRequest,
1131            >(payload, options)?),
1132            other => return Err(DecodeError::unsupported_action(other.as_str())),
1133        })
1134    }
1135
1136    /// [`decode`](Self::decode), also returning every [`Repair`](crate::decode::Repair)
1137    /// the lenient options applied.
1138    pub fn decode_reporting(
1139        action: Action,
1140        payload: &RawValue,
1141        options: &DecodeOptions,
1142    ) -> Result<crate::decode::Decoded<Self>, DecodeError> {
1143        Ok(match action {
1144            Action::Authorize => {
1145                crate::decode::decode_payload_reporting::<AuthorizeRequest>(payload, options)?
1146                    .map(Self::Authorize)
1147            }
1148            Action::BootNotification => crate::decode::decode_payload_reporting::<
1149                BootNotificationRequest,
1150            >(payload, options)?
1151            .map(Self::BootNotification),
1152            Action::ClearedChargingLimit => crate::decode::decode_payload_reporting::<
1153                ClearedChargingLimitRequest,
1154            >(payload, options)?
1155            .map(Self::ClearedChargingLimit),
1156            Action::DataTransfer => {
1157                crate::decode::decode_payload_reporting::<DataTransferRequest>(payload, options)?
1158                    .map(Self::DataTransfer)
1159            }
1160            Action::FirmwareStatusNotification => crate::decode::decode_payload_reporting::<
1161                FirmwareStatusNotificationRequest,
1162            >(payload, options)?
1163            .map(Self::FirmwareStatusNotification),
1164            Action::Get15118EVCertificate => crate::decode::decode_payload_reporting::<
1165                Get15118EVCertificateRequest,
1166            >(payload, options)?
1167            .map(Self::Get15118EVCertificate),
1168            Action::GetCertificateStatus => crate::decode::decode_payload_reporting::<
1169                GetCertificateStatusRequest,
1170            >(payload, options)?
1171            .map(Self::GetCertificateStatus),
1172            Action::Heartbeat => {
1173                crate::decode::decode_payload_reporting::<HeartbeatRequest>(payload, options)?
1174                    .map(Self::Heartbeat)
1175            }
1176            Action::LogStatusNotification => crate::decode::decode_payload_reporting::<
1177                LogStatusNotificationRequest,
1178            >(payload, options)?
1179            .map(Self::LogStatusNotification),
1180            Action::MeterValues => {
1181                crate::decode::decode_payload_reporting::<MeterValuesRequest>(payload, options)?
1182                    .map(Self::MeterValues)
1183            }
1184            Action::NotifyChargingLimit => crate::decode::decode_payload_reporting::<
1185                NotifyChargingLimitRequest,
1186            >(payload, options)?
1187            .map(Self::NotifyChargingLimit),
1188            Action::NotifyCustomerInformation => crate::decode::decode_payload_reporting::<
1189                NotifyCustomerInformationRequest,
1190            >(payload, options)?
1191            .map(Self::NotifyCustomerInformation),
1192            Action::NotifyDisplayMessages => crate::decode::decode_payload_reporting::<
1193                NotifyDisplayMessagesRequest,
1194            >(payload, options)?
1195            .map(Self::NotifyDisplayMessages),
1196            Action::NotifyEVChargingNeeds => crate::decode::decode_payload_reporting::<
1197                NotifyEVChargingNeedsRequest,
1198            >(payload, options)?
1199            .map(Self::NotifyEVChargingNeeds),
1200            Action::NotifyEVChargingSchedule => crate::decode::decode_payload_reporting::<
1201                NotifyEVChargingScheduleRequest,
1202            >(payload, options)?
1203            .map(Self::NotifyEVChargingSchedule),
1204            Action::NotifyEvent => {
1205                crate::decode::decode_payload_reporting::<NotifyEventRequest>(payload, options)?
1206                    .map(Self::NotifyEvent)
1207            }
1208            Action::NotifyMonitoringReport => crate::decode::decode_payload_reporting::<
1209                NotifyMonitoringReportRequest,
1210            >(payload, options)?
1211            .map(Self::NotifyMonitoringReport),
1212            Action::NotifyReport => {
1213                crate::decode::decode_payload_reporting::<NotifyReportRequest>(payload, options)?
1214                    .map(Self::NotifyReport)
1215            }
1216            Action::PublishFirmwareStatusNotification => crate::decode::decode_payload_reporting::<
1217                PublishFirmwareStatusNotificationRequest,
1218            >(payload, options)?
1219            .map(Self::PublishFirmwareStatusNotification),
1220            Action::ReportChargingProfiles => crate::decode::decode_payload_reporting::<
1221                ReportChargingProfilesRequest,
1222            >(payload, options)?
1223            .map(Self::ReportChargingProfiles),
1224            Action::ReservationStatusUpdate => crate::decode::decode_payload_reporting::<
1225                ReservationStatusUpdateRequest,
1226            >(payload, options)?
1227            .map(Self::ReservationStatusUpdate),
1228            Action::SecurityEventNotification => crate::decode::decode_payload_reporting::<
1229                SecurityEventNotificationRequest,
1230            >(payload, options)?
1231            .map(Self::SecurityEventNotification),
1232            Action::SignCertificate => {
1233                crate::decode::decode_payload_reporting::<SignCertificateRequest>(payload, options)?
1234                    .map(Self::SignCertificate)
1235            }
1236            Action::StatusNotification => crate::decode::decode_payload_reporting::<
1237                StatusNotificationRequest,
1238            >(payload, options)?
1239            .map(Self::StatusNotification),
1240            Action::TransactionEvent => crate::decode::decode_payload_reporting::<
1241                TransactionEventRequest,
1242            >(payload, options)?
1243            .map(Self::TransactionEvent),
1244            other => return Err(DecodeError::unsupported_action(other.as_str())),
1245        })
1246    }
1247
1248    /// Serializes the payload object (without the OCPP-J frame).
1249    pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
1250        match self {
1251            Self::Authorize(p) => serde_json::to_string(p),
1252            Self::BootNotification(p) => serde_json::to_string(p),
1253            Self::ClearedChargingLimit(p) => serde_json::to_string(p),
1254            Self::DataTransfer(p) => serde_json::to_string(p),
1255            Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
1256            Self::Get15118EVCertificate(p) => serde_json::to_string(p),
1257            Self::GetCertificateStatus(p) => serde_json::to_string(p),
1258            Self::Heartbeat(p) => serde_json::to_string(p),
1259            Self::LogStatusNotification(p) => serde_json::to_string(p),
1260            Self::MeterValues(p) => serde_json::to_string(p),
1261            Self::NotifyChargingLimit(p) => serde_json::to_string(p),
1262            Self::NotifyCustomerInformation(p) => serde_json::to_string(p),
1263            Self::NotifyDisplayMessages(p) => serde_json::to_string(p),
1264            Self::NotifyEVChargingNeeds(p) => serde_json::to_string(p),
1265            Self::NotifyEVChargingSchedule(p) => serde_json::to_string(p),
1266            Self::NotifyEvent(p) => serde_json::to_string(p),
1267            Self::NotifyMonitoringReport(p) => serde_json::to_string(p),
1268            Self::NotifyReport(p) => serde_json::to_string(p),
1269            Self::PublishFirmwareStatusNotification(p) => serde_json::to_string(p),
1270            Self::ReportChargingProfiles(p) => serde_json::to_string(p),
1271            Self::ReservationStatusUpdate(p) => serde_json::to_string(p),
1272            Self::SecurityEventNotification(p) => serde_json::to_string(p),
1273            Self::SignCertificate(p) => serde_json::to_string(p),
1274            Self::StatusNotification(p) => serde_json::to_string(p),
1275            Self::TransactionEvent(p) => serde_json::to_string(p),
1276        }
1277    }
1278}
1279
1280impl Validate for CsRequest {
1281    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
1282        match self {
1283            Self::Authorize(p) => p.validate_at(path, out),
1284            Self::BootNotification(p) => p.validate_at(path, out),
1285            Self::ClearedChargingLimit(p) => p.validate_at(path, out),
1286            Self::DataTransfer(p) => p.validate_at(path, out),
1287            Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
1288            Self::Get15118EVCertificate(p) => p.validate_at(path, out),
1289            Self::GetCertificateStatus(p) => p.validate_at(path, out),
1290            Self::Heartbeat(p) => p.validate_at(path, out),
1291            Self::LogStatusNotification(p) => p.validate_at(path, out),
1292            Self::MeterValues(p) => p.validate_at(path, out),
1293            Self::NotifyChargingLimit(p) => p.validate_at(path, out),
1294            Self::NotifyCustomerInformation(p) => p.validate_at(path, out),
1295            Self::NotifyDisplayMessages(p) => p.validate_at(path, out),
1296            Self::NotifyEVChargingNeeds(p) => p.validate_at(path, out),
1297            Self::NotifyEVChargingSchedule(p) => p.validate_at(path, out),
1298            Self::NotifyEvent(p) => p.validate_at(path, out),
1299            Self::NotifyMonitoringReport(p) => p.validate_at(path, out),
1300            Self::NotifyReport(p) => p.validate_at(path, out),
1301            Self::PublishFirmwareStatusNotification(p) => p.validate_at(path, out),
1302            Self::ReportChargingProfiles(p) => p.validate_at(path, out),
1303            Self::ReservationStatusUpdate(p) => p.validate_at(path, out),
1304            Self::SecurityEventNotification(p) => p.validate_at(path, out),
1305            Self::SignCertificate(p) => p.validate_at(path, out),
1306            Self::StatusNotification(p) => p.validate_at(path, out),
1307            Self::TransactionEvent(p) => p.validate_at(path, out),
1308        }
1309    }
1310}
1311
1312impl serde::Serialize for CsRequest {
1313    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
1314        match self {
1315            Self::Authorize(p) => p.serialize(ser),
1316            Self::BootNotification(p) => p.serialize(ser),
1317            Self::ClearedChargingLimit(p) => p.serialize(ser),
1318            Self::DataTransfer(p) => p.serialize(ser),
1319            Self::FirmwareStatusNotification(p) => p.serialize(ser),
1320            Self::Get15118EVCertificate(p) => p.serialize(ser),
1321            Self::GetCertificateStatus(p) => p.serialize(ser),
1322            Self::Heartbeat(p) => p.serialize(ser),
1323            Self::LogStatusNotification(p) => p.serialize(ser),
1324            Self::MeterValues(p) => p.serialize(ser),
1325            Self::NotifyChargingLimit(p) => p.serialize(ser),
1326            Self::NotifyCustomerInformation(p) => p.serialize(ser),
1327            Self::NotifyDisplayMessages(p) => p.serialize(ser),
1328            Self::NotifyEVChargingNeeds(p) => p.serialize(ser),
1329            Self::NotifyEVChargingSchedule(p) => p.serialize(ser),
1330            Self::NotifyEvent(p) => p.serialize(ser),
1331            Self::NotifyMonitoringReport(p) => p.serialize(ser),
1332            Self::NotifyReport(p) => p.serialize(ser),
1333            Self::PublishFirmwareStatusNotification(p) => p.serialize(ser),
1334            Self::ReportChargingProfiles(p) => p.serialize(ser),
1335            Self::ReservationStatusUpdate(p) => p.serialize(ser),
1336            Self::SecurityEventNotification(p) => p.serialize(ser),
1337            Self::SignCertificate(p) => p.serialize(ser),
1338            Self::StatusNotification(p) => p.serialize(ser),
1339            Self::TransactionEvent(p) => p.serialize(ser),
1340        }
1341    }
1342}
1343
1344impl crate::message::Sealed for CsRequest {}
1345
1346impl crate::message::DecodeRequest for CsRequest {
1347    type Action = Action;
1348
1349    fn decode_reporting(
1350        action: Action,
1351        payload: &RawValue,
1352        options: &DecodeOptions,
1353    ) -> Result<crate::decode::Decoded<Self>, DecodeError> {
1354        CsRequest::decode_reporting(action, payload, options)
1355    }
1356}
1357
1358/// The CSMS's answer to a [`CsRequest`] (CSMS → CS) in OCPP 2.0.1.
1359///
1360/// `SEND`-only actions have no response and are therefore absent from this enum.
1361#[derive(Clone, Debug, PartialEq)]
1362#[non_exhaustive]
1363#[allow(clippy::large_enum_variant)]
1364pub enum CsResponse {
1365    /// `Authorize`.
1366    Authorize(AuthorizeResponse),
1367    /// `BootNotification`.
1368    BootNotification(BootNotificationResponse),
1369    /// `ClearedChargingLimit`.
1370    ClearedChargingLimit(ClearedChargingLimitResponse),
1371    /// `DataTransfer`.
1372    DataTransfer(DataTransferResponse),
1373    /// `FirmwareStatusNotification`.
1374    FirmwareStatusNotification(FirmwareStatusNotificationResponse),
1375    /// `Get15118EVCertificate`.
1376    Get15118EVCertificate(Get15118EVCertificateResponse),
1377    /// `GetCertificateStatus`.
1378    GetCertificateStatus(GetCertificateStatusResponse),
1379    /// `Heartbeat`.
1380    Heartbeat(HeartbeatResponse),
1381    /// `LogStatusNotification`.
1382    LogStatusNotification(LogStatusNotificationResponse),
1383    /// `MeterValues`.
1384    MeterValues(MeterValuesResponse),
1385    /// `NotifyChargingLimit`.
1386    NotifyChargingLimit(NotifyChargingLimitResponse),
1387    /// `NotifyCustomerInformation`.
1388    NotifyCustomerInformation(NotifyCustomerInformationResponse),
1389    /// `NotifyDisplayMessages`.
1390    NotifyDisplayMessages(NotifyDisplayMessagesResponse),
1391    /// `NotifyEVChargingNeeds`.
1392    NotifyEVChargingNeeds(NotifyEVChargingNeedsResponse),
1393    /// `NotifyEVChargingSchedule`.
1394    NotifyEVChargingSchedule(NotifyEVChargingScheduleResponse),
1395    /// `NotifyEvent`.
1396    NotifyEvent(NotifyEventResponse),
1397    /// `NotifyMonitoringReport`.
1398    NotifyMonitoringReport(NotifyMonitoringReportResponse),
1399    /// `NotifyReport`.
1400    NotifyReport(NotifyReportResponse),
1401    /// `PublishFirmwareStatusNotification`.
1402    PublishFirmwareStatusNotification(PublishFirmwareStatusNotificationResponse),
1403    /// `ReportChargingProfiles`.
1404    ReportChargingProfiles(ReportChargingProfilesResponse),
1405    /// `ReservationStatusUpdate`.
1406    ReservationStatusUpdate(ReservationStatusUpdateResponse),
1407    /// `SecurityEventNotification`.
1408    SecurityEventNotification(SecurityEventNotificationResponse),
1409    /// `SignCertificate`.
1410    SignCertificate(SignCertificateResponse),
1411    /// `StatusNotification`.
1412    StatusNotification(StatusNotificationResponse),
1413    /// `TransactionEvent`.
1414    TransactionEvent(TransactionEventResponse),
1415}
1416
1417impl CsResponse {
1418    /// The action this payload belongs to.
1419    #[must_use]
1420    pub const fn action(&self) -> Action {
1421        match self {
1422            Self::Authorize(_) => Action::Authorize,
1423            Self::BootNotification(_) => Action::BootNotification,
1424            Self::ClearedChargingLimit(_) => Action::ClearedChargingLimit,
1425            Self::DataTransfer(_) => Action::DataTransfer,
1426            Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
1427            Self::Get15118EVCertificate(_) => Action::Get15118EVCertificate,
1428            Self::GetCertificateStatus(_) => Action::GetCertificateStatus,
1429            Self::Heartbeat(_) => Action::Heartbeat,
1430            Self::LogStatusNotification(_) => Action::LogStatusNotification,
1431            Self::MeterValues(_) => Action::MeterValues,
1432            Self::NotifyChargingLimit(_) => Action::NotifyChargingLimit,
1433            Self::NotifyCustomerInformation(_) => Action::NotifyCustomerInformation,
1434            Self::NotifyDisplayMessages(_) => Action::NotifyDisplayMessages,
1435            Self::NotifyEVChargingNeeds(_) => Action::NotifyEVChargingNeeds,
1436            Self::NotifyEVChargingSchedule(_) => Action::NotifyEVChargingSchedule,
1437            Self::NotifyEvent(_) => Action::NotifyEvent,
1438            Self::NotifyMonitoringReport(_) => Action::NotifyMonitoringReport,
1439            Self::NotifyReport(_) => Action::NotifyReport,
1440            Self::PublishFirmwareStatusNotification(_) => Action::PublishFirmwareStatusNotification,
1441            Self::ReportChargingProfiles(_) => Action::ReportChargingProfiles,
1442            Self::ReservationStatusUpdate(_) => Action::ReservationStatusUpdate,
1443            Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
1444            Self::SignCertificate(_) => Action::SignCertificate,
1445            Self::StatusNotification(_) => Action::StatusNotification,
1446            Self::TransactionEvent(_) => Action::TransactionEvent,
1447        }
1448    }
1449
1450    /// Decodes a raw JSON payload for `action`, classifying every failure so the
1451    /// caller can answer with the correct OCPP error code.
1452    pub fn decode(
1453        action: Action,
1454        payload: &RawValue,
1455        options: &DecodeOptions,
1456    ) -> Result<Self, DecodeError> {
1457        Ok(match action {
1458            Action::Authorize => Self::Authorize(
1459                crate::decode::decode_payload::<AuthorizeResponse>(payload, options)?,
1460            ),
1461            Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
1462                BootNotificationResponse,
1463            >(payload, options)?),
1464            Action::ClearedChargingLimit => {
1465                Self::ClearedChargingLimit(crate::decode::decode_payload::<
1466                    ClearedChargingLimitResponse,
1467                >(payload, options)?)
1468            }
1469            Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
1470                DataTransferResponse,
1471            >(payload, options)?),
1472            Action::FirmwareStatusNotification => {
1473                Self::FirmwareStatusNotification(crate::decode::decode_payload::<
1474                    FirmwareStatusNotificationResponse,
1475                >(payload, options)?)
1476            }
1477            Action::Get15118EVCertificate => {
1478                Self::Get15118EVCertificate(crate::decode::decode_payload::<
1479                    Get15118EVCertificateResponse,
1480                >(payload, options)?)
1481            }
1482            Action::GetCertificateStatus => {
1483                Self::GetCertificateStatus(crate::decode::decode_payload::<
1484                    GetCertificateStatusResponse,
1485                >(payload, options)?)
1486            }
1487            Action::Heartbeat => Self::Heartbeat(
1488                crate::decode::decode_payload::<HeartbeatResponse>(payload, options)?,
1489            ),
1490            Action::LogStatusNotification => {
1491                Self::LogStatusNotification(crate::decode::decode_payload::<
1492                    LogStatusNotificationResponse,
1493                >(payload, options)?)
1494            }
1495            Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
1496                MeterValuesResponse,
1497            >(payload, options)?),
1498            Action::NotifyChargingLimit => {
1499                Self::NotifyChargingLimit(crate::decode::decode_payload::<
1500                    NotifyChargingLimitResponse,
1501                >(payload, options)?)
1502            }
1503            Action::NotifyCustomerInformation => {
1504                Self::NotifyCustomerInformation(crate::decode::decode_payload::<
1505                    NotifyCustomerInformationResponse,
1506                >(payload, options)?)
1507            }
1508            Action::NotifyDisplayMessages => {
1509                Self::NotifyDisplayMessages(crate::decode::decode_payload::<
1510                    NotifyDisplayMessagesResponse,
1511                >(payload, options)?)
1512            }
1513            Action::NotifyEVChargingNeeds => {
1514                Self::NotifyEVChargingNeeds(crate::decode::decode_payload::<
1515                    NotifyEVChargingNeedsResponse,
1516                >(payload, options)?)
1517            }
1518            Action::NotifyEVChargingSchedule => {
1519                Self::NotifyEVChargingSchedule(crate::decode::decode_payload::<
1520                    NotifyEVChargingScheduleResponse,
1521                >(payload, options)?)
1522            }
1523            Action::NotifyEvent => Self::NotifyEvent(crate::decode::decode_payload::<
1524                NotifyEventResponse,
1525            >(payload, options)?),
1526            Action::NotifyMonitoringReport => {
1527                Self::NotifyMonitoringReport(crate::decode::decode_payload::<
1528                    NotifyMonitoringReportResponse,
1529                >(payload, options)?)
1530            }
1531            Action::NotifyReport => Self::NotifyReport(crate::decode::decode_payload::<
1532                NotifyReportResponse,
1533            >(payload, options)?),
1534            Action::PublishFirmwareStatusNotification => {
1535                Self::PublishFirmwareStatusNotification(crate::decode::decode_payload::<
1536                    PublishFirmwareStatusNotificationResponse,
1537                >(payload, options)?)
1538            }
1539            Action::ReportChargingProfiles => {
1540                Self::ReportChargingProfiles(crate::decode::decode_payload::<
1541                    ReportChargingProfilesResponse,
1542                >(payload, options)?)
1543            }
1544            Action::ReservationStatusUpdate => {
1545                Self::ReservationStatusUpdate(crate::decode::decode_payload::<
1546                    ReservationStatusUpdateResponse,
1547                >(payload, options)?)
1548            }
1549            Action::SecurityEventNotification => {
1550                Self::SecurityEventNotification(crate::decode::decode_payload::<
1551                    SecurityEventNotificationResponse,
1552                >(payload, options)?)
1553            }
1554            Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
1555                SignCertificateResponse,
1556            >(payload, options)?),
1557            Action::StatusNotification => Self::StatusNotification(
1558                crate::decode::decode_payload::<StatusNotificationResponse>(payload, options)?,
1559            ),
1560            Action::TransactionEvent => Self::TransactionEvent(crate::decode::decode_payload::<
1561                TransactionEventResponse,
1562            >(payload, options)?),
1563            other => return Err(DecodeError::unsupported_action(other.as_str())),
1564        })
1565    }
1566
1567    /// Serializes the payload object (without the OCPP-J frame).
1568    pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
1569        match self {
1570            Self::Authorize(p) => serde_json::to_string(p),
1571            Self::BootNotification(p) => serde_json::to_string(p),
1572            Self::ClearedChargingLimit(p) => serde_json::to_string(p),
1573            Self::DataTransfer(p) => serde_json::to_string(p),
1574            Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
1575            Self::Get15118EVCertificate(p) => serde_json::to_string(p),
1576            Self::GetCertificateStatus(p) => serde_json::to_string(p),
1577            Self::Heartbeat(p) => serde_json::to_string(p),
1578            Self::LogStatusNotification(p) => serde_json::to_string(p),
1579            Self::MeterValues(p) => serde_json::to_string(p),
1580            Self::NotifyChargingLimit(p) => serde_json::to_string(p),
1581            Self::NotifyCustomerInformation(p) => serde_json::to_string(p),
1582            Self::NotifyDisplayMessages(p) => serde_json::to_string(p),
1583            Self::NotifyEVChargingNeeds(p) => serde_json::to_string(p),
1584            Self::NotifyEVChargingSchedule(p) => serde_json::to_string(p),
1585            Self::NotifyEvent(p) => serde_json::to_string(p),
1586            Self::NotifyMonitoringReport(p) => serde_json::to_string(p),
1587            Self::NotifyReport(p) => serde_json::to_string(p),
1588            Self::PublishFirmwareStatusNotification(p) => serde_json::to_string(p),
1589            Self::ReportChargingProfiles(p) => serde_json::to_string(p),
1590            Self::ReservationStatusUpdate(p) => serde_json::to_string(p),
1591            Self::SecurityEventNotification(p) => serde_json::to_string(p),
1592            Self::SignCertificate(p) => serde_json::to_string(p),
1593            Self::StatusNotification(p) => serde_json::to_string(p),
1594            Self::TransactionEvent(p) => serde_json::to_string(p),
1595        }
1596    }
1597}
1598
1599impl Validate for CsResponse {
1600    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
1601        match self {
1602            Self::Authorize(p) => p.validate_at(path, out),
1603            Self::BootNotification(p) => p.validate_at(path, out),
1604            Self::ClearedChargingLimit(p) => p.validate_at(path, out),
1605            Self::DataTransfer(p) => p.validate_at(path, out),
1606            Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
1607            Self::Get15118EVCertificate(p) => p.validate_at(path, out),
1608            Self::GetCertificateStatus(p) => p.validate_at(path, out),
1609            Self::Heartbeat(p) => p.validate_at(path, out),
1610            Self::LogStatusNotification(p) => p.validate_at(path, out),
1611            Self::MeterValues(p) => p.validate_at(path, out),
1612            Self::NotifyChargingLimit(p) => p.validate_at(path, out),
1613            Self::NotifyCustomerInformation(p) => p.validate_at(path, out),
1614            Self::NotifyDisplayMessages(p) => p.validate_at(path, out),
1615            Self::NotifyEVChargingNeeds(p) => p.validate_at(path, out),
1616            Self::NotifyEVChargingSchedule(p) => p.validate_at(path, out),
1617            Self::NotifyEvent(p) => p.validate_at(path, out),
1618            Self::NotifyMonitoringReport(p) => p.validate_at(path, out),
1619            Self::NotifyReport(p) => p.validate_at(path, out),
1620            Self::PublishFirmwareStatusNotification(p) => p.validate_at(path, out),
1621            Self::ReportChargingProfiles(p) => p.validate_at(path, out),
1622            Self::ReservationStatusUpdate(p) => p.validate_at(path, out),
1623            Self::SecurityEventNotification(p) => p.validate_at(path, out),
1624            Self::SignCertificate(p) => p.validate_at(path, out),
1625            Self::StatusNotification(p) => p.validate_at(path, out),
1626            Self::TransactionEvent(p) => p.validate_at(path, out),
1627        }
1628    }
1629}
1630
1631impl serde::Serialize for CsResponse {
1632    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
1633        match self {
1634            Self::Authorize(p) => p.serialize(ser),
1635            Self::BootNotification(p) => p.serialize(ser),
1636            Self::ClearedChargingLimit(p) => p.serialize(ser),
1637            Self::DataTransfer(p) => p.serialize(ser),
1638            Self::FirmwareStatusNotification(p) => p.serialize(ser),
1639            Self::Get15118EVCertificate(p) => p.serialize(ser),
1640            Self::GetCertificateStatus(p) => p.serialize(ser),
1641            Self::Heartbeat(p) => p.serialize(ser),
1642            Self::LogStatusNotification(p) => p.serialize(ser),
1643            Self::MeterValues(p) => p.serialize(ser),
1644            Self::NotifyChargingLimit(p) => p.serialize(ser),
1645            Self::NotifyCustomerInformation(p) => p.serialize(ser),
1646            Self::NotifyDisplayMessages(p) => p.serialize(ser),
1647            Self::NotifyEVChargingNeeds(p) => p.serialize(ser),
1648            Self::NotifyEVChargingSchedule(p) => p.serialize(ser),
1649            Self::NotifyEvent(p) => p.serialize(ser),
1650            Self::NotifyMonitoringReport(p) => p.serialize(ser),
1651            Self::NotifyReport(p) => p.serialize(ser),
1652            Self::PublishFirmwareStatusNotification(p) => p.serialize(ser),
1653            Self::ReportChargingProfiles(p) => p.serialize(ser),
1654            Self::ReservationStatusUpdate(p) => p.serialize(ser),
1655            Self::SecurityEventNotification(p) => p.serialize(ser),
1656            Self::SignCertificate(p) => p.serialize(ser),
1657            Self::StatusNotification(p) => p.serialize(ser),
1658            Self::TransactionEvent(p) => p.serialize(ser),
1659        }
1660    }
1661}
1662
1663/// A request originated by the **CSMS** (CSMS → CS) in OCPP 2.0.1.
1664#[derive(Clone, Debug, PartialEq)]
1665#[non_exhaustive]
1666#[allow(clippy::large_enum_variant)]
1667pub enum CsmsRequest {
1668    /// `CancelReservation`.
1669    CancelReservation(CancelReservationRequest),
1670    /// `CertificateSigned`.
1671    CertificateSigned(CertificateSignedRequest),
1672    /// `ChangeAvailability`.
1673    ChangeAvailability(ChangeAvailabilityRequest),
1674    /// `ClearCache`.
1675    ClearCache(ClearCacheRequest),
1676    /// `ClearChargingProfile`.
1677    ClearChargingProfile(ClearChargingProfileRequest),
1678    /// `ClearDisplayMessage`.
1679    ClearDisplayMessage(ClearDisplayMessageRequest),
1680    /// `ClearVariableMonitoring`.
1681    ClearVariableMonitoring(ClearVariableMonitoringRequest),
1682    /// `CostUpdated`.
1683    CostUpdated(CostUpdatedRequest),
1684    /// `CustomerInformation`.
1685    CustomerInformation(CustomerInformationRequest),
1686    /// `DataTransfer`.
1687    DataTransfer(DataTransferRequest),
1688    /// `DeleteCertificate`.
1689    DeleteCertificate(DeleteCertificateRequest),
1690    /// `GetBaseReport`.
1691    GetBaseReport(GetBaseReportRequest),
1692    /// `GetChargingProfiles`.
1693    GetChargingProfiles(GetChargingProfilesRequest),
1694    /// `GetCompositeSchedule`.
1695    GetCompositeSchedule(GetCompositeScheduleRequest),
1696    /// `GetDisplayMessages`.
1697    GetDisplayMessages(GetDisplayMessagesRequest),
1698    /// `GetInstalledCertificateIds`.
1699    GetInstalledCertificateIds(GetInstalledCertificateIdsRequest),
1700    /// `GetLocalListVersion`.
1701    GetLocalListVersion(GetLocalListVersionRequest),
1702    /// `GetLog`.
1703    GetLog(GetLogRequest),
1704    /// `GetMonitoringReport`.
1705    GetMonitoringReport(GetMonitoringReportRequest),
1706    /// `GetReport`.
1707    GetReport(GetReportRequest),
1708    /// `GetTransactionStatus`.
1709    GetTransactionStatus(GetTransactionStatusRequest),
1710    /// `GetVariables`.
1711    GetVariables(GetVariablesRequest),
1712    /// `InstallCertificate`.
1713    InstallCertificate(InstallCertificateRequest),
1714    /// `PublishFirmware`.
1715    PublishFirmware(PublishFirmwareRequest),
1716    /// `RequestStartTransaction`.
1717    RequestStartTransaction(RequestStartTransactionRequest),
1718    /// `RequestStopTransaction`.
1719    RequestStopTransaction(RequestStopTransactionRequest),
1720    /// `ReserveNow`.
1721    ReserveNow(ReserveNowRequest),
1722    /// `Reset`.
1723    Reset(ResetRequest),
1724    /// `SendLocalList`.
1725    SendLocalList(SendLocalListRequest),
1726    /// `SetChargingProfile`.
1727    SetChargingProfile(SetChargingProfileRequest),
1728    /// `SetDisplayMessage`.
1729    SetDisplayMessage(SetDisplayMessageRequest),
1730    /// `SetMonitoringBase`.
1731    SetMonitoringBase(SetMonitoringBaseRequest),
1732    /// `SetMonitoringLevel`.
1733    SetMonitoringLevel(SetMonitoringLevelRequest),
1734    /// `SetNetworkProfile`.
1735    SetNetworkProfile(SetNetworkProfileRequest),
1736    /// `SetVariableMonitoring`.
1737    SetVariableMonitoring(SetVariableMonitoringRequest),
1738    /// `SetVariables`.
1739    SetVariables(SetVariablesRequest),
1740    /// `TriggerMessage`.
1741    TriggerMessage(TriggerMessageRequest),
1742    /// `UnlockConnector`.
1743    UnlockConnector(UnlockConnectorRequest),
1744    /// `UnpublishFirmware`.
1745    UnpublishFirmware(UnpublishFirmwareRequest),
1746    /// `UpdateFirmware`.
1747    UpdateFirmware(UpdateFirmwareRequest),
1748}
1749
1750impl CsmsRequest {
1751    /// The action this payload belongs to.
1752    #[must_use]
1753    pub const fn action(&self) -> Action {
1754        match self {
1755            Self::CancelReservation(_) => Action::CancelReservation,
1756            Self::CertificateSigned(_) => Action::CertificateSigned,
1757            Self::ChangeAvailability(_) => Action::ChangeAvailability,
1758            Self::ClearCache(_) => Action::ClearCache,
1759            Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
1760            Self::ClearDisplayMessage(_) => Action::ClearDisplayMessage,
1761            Self::ClearVariableMonitoring(_) => Action::ClearVariableMonitoring,
1762            Self::CostUpdated(_) => Action::CostUpdated,
1763            Self::CustomerInformation(_) => Action::CustomerInformation,
1764            Self::DataTransfer(_) => Action::DataTransfer,
1765            Self::DeleteCertificate(_) => Action::DeleteCertificate,
1766            Self::GetBaseReport(_) => Action::GetBaseReport,
1767            Self::GetChargingProfiles(_) => Action::GetChargingProfiles,
1768            Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
1769            Self::GetDisplayMessages(_) => Action::GetDisplayMessages,
1770            Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
1771            Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
1772            Self::GetLog(_) => Action::GetLog,
1773            Self::GetMonitoringReport(_) => Action::GetMonitoringReport,
1774            Self::GetReport(_) => Action::GetReport,
1775            Self::GetTransactionStatus(_) => Action::GetTransactionStatus,
1776            Self::GetVariables(_) => Action::GetVariables,
1777            Self::InstallCertificate(_) => Action::InstallCertificate,
1778            Self::PublishFirmware(_) => Action::PublishFirmware,
1779            Self::RequestStartTransaction(_) => Action::RequestStartTransaction,
1780            Self::RequestStopTransaction(_) => Action::RequestStopTransaction,
1781            Self::ReserveNow(_) => Action::ReserveNow,
1782            Self::Reset(_) => Action::Reset,
1783            Self::SendLocalList(_) => Action::SendLocalList,
1784            Self::SetChargingProfile(_) => Action::SetChargingProfile,
1785            Self::SetDisplayMessage(_) => Action::SetDisplayMessage,
1786            Self::SetMonitoringBase(_) => Action::SetMonitoringBase,
1787            Self::SetMonitoringLevel(_) => Action::SetMonitoringLevel,
1788            Self::SetNetworkProfile(_) => Action::SetNetworkProfile,
1789            Self::SetVariableMonitoring(_) => Action::SetVariableMonitoring,
1790            Self::SetVariables(_) => Action::SetVariables,
1791            Self::TriggerMessage(_) => Action::TriggerMessage,
1792            Self::UnlockConnector(_) => Action::UnlockConnector,
1793            Self::UnpublishFirmware(_) => Action::UnpublishFirmware,
1794            Self::UpdateFirmware(_) => Action::UpdateFirmware,
1795        }
1796    }
1797
1798    /// Decodes a raw JSON payload for `action`, classifying every failure so the
1799    /// caller can answer with the correct OCPP error code.
1800    pub fn decode(
1801        action: Action,
1802        payload: &RawValue,
1803        options: &DecodeOptions,
1804    ) -> Result<Self, DecodeError> {
1805        Ok(match action {
1806            Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
1807                CancelReservationRequest,
1808            >(payload, options)?),
1809            Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
1810                CertificateSignedRequest,
1811            >(payload, options)?),
1812            Action::ChangeAvailability => Self::ChangeAvailability(
1813                crate::decode::decode_payload::<ChangeAvailabilityRequest>(payload, options)?,
1814            ),
1815            Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
1816                ClearCacheRequest,
1817            >(payload, options)?),
1818            Action::ClearChargingProfile => {
1819                Self::ClearChargingProfile(crate::decode::decode_payload::<
1820                    ClearChargingProfileRequest,
1821                >(payload, options)?)
1822            }
1823            Action::ClearDisplayMessage => {
1824                Self::ClearDisplayMessage(crate::decode::decode_payload::<
1825                    ClearDisplayMessageRequest,
1826                >(payload, options)?)
1827            }
1828            Action::ClearVariableMonitoring => {
1829                Self::ClearVariableMonitoring(crate::decode::decode_payload::<
1830                    ClearVariableMonitoringRequest,
1831                >(payload, options)?)
1832            }
1833            Action::CostUpdated => Self::CostUpdated(crate::decode::decode_payload::<
1834                CostUpdatedRequest,
1835            >(payload, options)?),
1836            Action::CustomerInformation => {
1837                Self::CustomerInformation(crate::decode::decode_payload::<
1838                    CustomerInformationRequest,
1839                >(payload, options)?)
1840            }
1841            Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
1842                DataTransferRequest,
1843            >(payload, options)?),
1844            Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
1845                DeleteCertificateRequest,
1846            >(payload, options)?),
1847            Action::GetBaseReport => Self::GetBaseReport(crate::decode::decode_payload::<
1848                GetBaseReportRequest,
1849            >(payload, options)?),
1850            Action::GetChargingProfiles => {
1851                Self::GetChargingProfiles(crate::decode::decode_payload::<
1852                    GetChargingProfilesRequest,
1853                >(payload, options)?)
1854            }
1855            Action::GetCompositeSchedule => {
1856                Self::GetCompositeSchedule(crate::decode::decode_payload::<
1857                    GetCompositeScheduleRequest,
1858                >(payload, options)?)
1859            }
1860            Action::GetDisplayMessages => Self::GetDisplayMessages(
1861                crate::decode::decode_payload::<GetDisplayMessagesRequest>(payload, options)?,
1862            ),
1863            Action::GetInstalledCertificateIds => {
1864                Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
1865                    GetInstalledCertificateIdsRequest,
1866                >(payload, options)?)
1867            }
1868            Action::GetLocalListVersion => {
1869                Self::GetLocalListVersion(crate::decode::decode_payload::<
1870                    GetLocalListVersionRequest,
1871                >(payload, options)?)
1872            }
1873            Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogRequest>(
1874                payload, options,
1875            )?),
1876            Action::GetMonitoringReport => {
1877                Self::GetMonitoringReport(crate::decode::decode_payload::<
1878                    GetMonitoringReportRequest,
1879                >(payload, options)?)
1880            }
1881            Action::GetReport => Self::GetReport(
1882                crate::decode::decode_payload::<GetReportRequest>(payload, options)?,
1883            ),
1884            Action::GetTransactionStatus => {
1885                Self::GetTransactionStatus(crate::decode::decode_payload::<
1886                    GetTransactionStatusRequest,
1887                >(payload, options)?)
1888            }
1889            Action::GetVariables => Self::GetVariables(crate::decode::decode_payload::<
1890                GetVariablesRequest,
1891            >(payload, options)?),
1892            Action::InstallCertificate => Self::InstallCertificate(
1893                crate::decode::decode_payload::<InstallCertificateRequest>(payload, options)?,
1894            ),
1895            Action::PublishFirmware => Self::PublishFirmware(crate::decode::decode_payload::<
1896                PublishFirmwareRequest,
1897            >(payload, options)?),
1898            Action::RequestStartTransaction => {
1899                Self::RequestStartTransaction(crate::decode::decode_payload::<
1900                    RequestStartTransactionRequest,
1901                >(payload, options)?)
1902            }
1903            Action::RequestStopTransaction => {
1904                Self::RequestStopTransaction(crate::decode::decode_payload::<
1905                    RequestStopTransactionRequest,
1906                >(payload, options)?)
1907            }
1908            Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
1909                ReserveNowRequest,
1910            >(payload, options)?),
1911            Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetRequest>(
1912                payload, options,
1913            )?),
1914            Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
1915                SendLocalListRequest,
1916            >(payload, options)?),
1917            Action::SetChargingProfile => Self::SetChargingProfile(
1918                crate::decode::decode_payload::<SetChargingProfileRequest>(payload, options)?,
1919            ),
1920            Action::SetDisplayMessage => Self::SetDisplayMessage(crate::decode::decode_payload::<
1921                SetDisplayMessageRequest,
1922            >(payload, options)?),
1923            Action::SetMonitoringBase => Self::SetMonitoringBase(crate::decode::decode_payload::<
1924                SetMonitoringBaseRequest,
1925            >(payload, options)?),
1926            Action::SetMonitoringLevel => Self::SetMonitoringLevel(
1927                crate::decode::decode_payload::<SetMonitoringLevelRequest>(payload, options)?,
1928            ),
1929            Action::SetNetworkProfile => Self::SetNetworkProfile(crate::decode::decode_payload::<
1930                SetNetworkProfileRequest,
1931            >(payload, options)?),
1932            Action::SetVariableMonitoring => {
1933                Self::SetVariableMonitoring(crate::decode::decode_payload::<
1934                    SetVariableMonitoringRequest,
1935                >(payload, options)?)
1936            }
1937            Action::SetVariables => Self::SetVariables(crate::decode::decode_payload::<
1938                SetVariablesRequest,
1939            >(payload, options)?),
1940            Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
1941                TriggerMessageRequest,
1942            >(payload, options)?),
1943            Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
1944                UnlockConnectorRequest,
1945            >(payload, options)?),
1946            Action::UnpublishFirmware => Self::UnpublishFirmware(crate::decode::decode_payload::<
1947                UnpublishFirmwareRequest,
1948            >(payload, options)?),
1949            Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
1950                UpdateFirmwareRequest,
1951            >(payload, options)?),
1952            other => return Err(DecodeError::unsupported_action(other.as_str())),
1953        })
1954    }
1955
1956    /// [`decode`](Self::decode), also returning every [`Repair`](crate::decode::Repair)
1957    /// the lenient options applied.
1958    pub fn decode_reporting(
1959        action: Action,
1960        payload: &RawValue,
1961        options: &DecodeOptions,
1962    ) -> Result<crate::decode::Decoded<Self>, DecodeError> {
1963        Ok(match action {
1964            Action::CancelReservation => crate::decode::decode_payload_reporting::<
1965                CancelReservationRequest,
1966            >(payload, options)?
1967            .map(Self::CancelReservation),
1968            Action::CertificateSigned => crate::decode::decode_payload_reporting::<
1969                CertificateSignedRequest,
1970            >(payload, options)?
1971            .map(Self::CertificateSigned),
1972            Action::ChangeAvailability => crate::decode::decode_payload_reporting::<
1973                ChangeAvailabilityRequest,
1974            >(payload, options)?
1975            .map(Self::ChangeAvailability),
1976            Action::ClearCache => {
1977                crate::decode::decode_payload_reporting::<ClearCacheRequest>(payload, options)?
1978                    .map(Self::ClearCache)
1979            }
1980            Action::ClearChargingProfile => crate::decode::decode_payload_reporting::<
1981                ClearChargingProfileRequest,
1982            >(payload, options)?
1983            .map(Self::ClearChargingProfile),
1984            Action::ClearDisplayMessage => crate::decode::decode_payload_reporting::<
1985                ClearDisplayMessageRequest,
1986            >(payload, options)?
1987            .map(Self::ClearDisplayMessage),
1988            Action::ClearVariableMonitoring => crate::decode::decode_payload_reporting::<
1989                ClearVariableMonitoringRequest,
1990            >(payload, options)?
1991            .map(Self::ClearVariableMonitoring),
1992            Action::CostUpdated => {
1993                crate::decode::decode_payload_reporting::<CostUpdatedRequest>(payload, options)?
1994                    .map(Self::CostUpdated)
1995            }
1996            Action::CustomerInformation => crate::decode::decode_payload_reporting::<
1997                CustomerInformationRequest,
1998            >(payload, options)?
1999            .map(Self::CustomerInformation),
2000            Action::DataTransfer => {
2001                crate::decode::decode_payload_reporting::<DataTransferRequest>(payload, options)?
2002                    .map(Self::DataTransfer)
2003            }
2004            Action::DeleteCertificate => crate::decode::decode_payload_reporting::<
2005                DeleteCertificateRequest,
2006            >(payload, options)?
2007            .map(Self::DeleteCertificate),
2008            Action::GetBaseReport => {
2009                crate::decode::decode_payload_reporting::<GetBaseReportRequest>(payload, options)?
2010                    .map(Self::GetBaseReport)
2011            }
2012            Action::GetChargingProfiles => crate::decode::decode_payload_reporting::<
2013                GetChargingProfilesRequest,
2014            >(payload, options)?
2015            .map(Self::GetChargingProfiles),
2016            Action::GetCompositeSchedule => crate::decode::decode_payload_reporting::<
2017                GetCompositeScheduleRequest,
2018            >(payload, options)?
2019            .map(Self::GetCompositeSchedule),
2020            Action::GetDisplayMessages => crate::decode::decode_payload_reporting::<
2021                GetDisplayMessagesRequest,
2022            >(payload, options)?
2023            .map(Self::GetDisplayMessages),
2024            Action::GetInstalledCertificateIds => crate::decode::decode_payload_reporting::<
2025                GetInstalledCertificateIdsRequest,
2026            >(payload, options)?
2027            .map(Self::GetInstalledCertificateIds),
2028            Action::GetLocalListVersion => crate::decode::decode_payload_reporting::<
2029                GetLocalListVersionRequest,
2030            >(payload, options)?
2031            .map(Self::GetLocalListVersion),
2032            Action::GetLog => {
2033                crate::decode::decode_payload_reporting::<GetLogRequest>(payload, options)?
2034                    .map(Self::GetLog)
2035            }
2036            Action::GetMonitoringReport => crate::decode::decode_payload_reporting::<
2037                GetMonitoringReportRequest,
2038            >(payload, options)?
2039            .map(Self::GetMonitoringReport),
2040            Action::GetReport => {
2041                crate::decode::decode_payload_reporting::<GetReportRequest>(payload, options)?
2042                    .map(Self::GetReport)
2043            }
2044            Action::GetTransactionStatus => crate::decode::decode_payload_reporting::<
2045                GetTransactionStatusRequest,
2046            >(payload, options)?
2047            .map(Self::GetTransactionStatus),
2048            Action::GetVariables => {
2049                crate::decode::decode_payload_reporting::<GetVariablesRequest>(payload, options)?
2050                    .map(Self::GetVariables)
2051            }
2052            Action::InstallCertificate => crate::decode::decode_payload_reporting::<
2053                InstallCertificateRequest,
2054            >(payload, options)?
2055            .map(Self::InstallCertificate),
2056            Action::PublishFirmware => {
2057                crate::decode::decode_payload_reporting::<PublishFirmwareRequest>(payload, options)?
2058                    .map(Self::PublishFirmware)
2059            }
2060            Action::RequestStartTransaction => crate::decode::decode_payload_reporting::<
2061                RequestStartTransactionRequest,
2062            >(payload, options)?
2063            .map(Self::RequestStartTransaction),
2064            Action::RequestStopTransaction => crate::decode::decode_payload_reporting::<
2065                RequestStopTransactionRequest,
2066            >(payload, options)?
2067            .map(Self::RequestStopTransaction),
2068            Action::ReserveNow => {
2069                crate::decode::decode_payload_reporting::<ReserveNowRequest>(payload, options)?
2070                    .map(Self::ReserveNow)
2071            }
2072            Action::Reset => {
2073                crate::decode::decode_payload_reporting::<ResetRequest>(payload, options)?
2074                    .map(Self::Reset)
2075            }
2076            Action::SendLocalList => {
2077                crate::decode::decode_payload_reporting::<SendLocalListRequest>(payload, options)?
2078                    .map(Self::SendLocalList)
2079            }
2080            Action::SetChargingProfile => crate::decode::decode_payload_reporting::<
2081                SetChargingProfileRequest,
2082            >(payload, options)?
2083            .map(Self::SetChargingProfile),
2084            Action::SetDisplayMessage => crate::decode::decode_payload_reporting::<
2085                SetDisplayMessageRequest,
2086            >(payload, options)?
2087            .map(Self::SetDisplayMessage),
2088            Action::SetMonitoringBase => crate::decode::decode_payload_reporting::<
2089                SetMonitoringBaseRequest,
2090            >(payload, options)?
2091            .map(Self::SetMonitoringBase),
2092            Action::SetMonitoringLevel => crate::decode::decode_payload_reporting::<
2093                SetMonitoringLevelRequest,
2094            >(payload, options)?
2095            .map(Self::SetMonitoringLevel),
2096            Action::SetNetworkProfile => crate::decode::decode_payload_reporting::<
2097                SetNetworkProfileRequest,
2098            >(payload, options)?
2099            .map(Self::SetNetworkProfile),
2100            Action::SetVariableMonitoring => crate::decode::decode_payload_reporting::<
2101                SetVariableMonitoringRequest,
2102            >(payload, options)?
2103            .map(Self::SetVariableMonitoring),
2104            Action::SetVariables => {
2105                crate::decode::decode_payload_reporting::<SetVariablesRequest>(payload, options)?
2106                    .map(Self::SetVariables)
2107            }
2108            Action::TriggerMessage => {
2109                crate::decode::decode_payload_reporting::<TriggerMessageRequest>(payload, options)?
2110                    .map(Self::TriggerMessage)
2111            }
2112            Action::UnlockConnector => {
2113                crate::decode::decode_payload_reporting::<UnlockConnectorRequest>(payload, options)?
2114                    .map(Self::UnlockConnector)
2115            }
2116            Action::UnpublishFirmware => crate::decode::decode_payload_reporting::<
2117                UnpublishFirmwareRequest,
2118            >(payload, options)?
2119            .map(Self::UnpublishFirmware),
2120            Action::UpdateFirmware => {
2121                crate::decode::decode_payload_reporting::<UpdateFirmwareRequest>(payload, options)?
2122                    .map(Self::UpdateFirmware)
2123            }
2124            other => return Err(DecodeError::unsupported_action(other.as_str())),
2125        })
2126    }
2127
2128    /// Serializes the payload object (without the OCPP-J frame).
2129    pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
2130        match self {
2131            Self::CancelReservation(p) => serde_json::to_string(p),
2132            Self::CertificateSigned(p) => serde_json::to_string(p),
2133            Self::ChangeAvailability(p) => serde_json::to_string(p),
2134            Self::ClearCache(p) => serde_json::to_string(p),
2135            Self::ClearChargingProfile(p) => serde_json::to_string(p),
2136            Self::ClearDisplayMessage(p) => serde_json::to_string(p),
2137            Self::ClearVariableMonitoring(p) => serde_json::to_string(p),
2138            Self::CostUpdated(p) => serde_json::to_string(p),
2139            Self::CustomerInformation(p) => serde_json::to_string(p),
2140            Self::DataTransfer(p) => serde_json::to_string(p),
2141            Self::DeleteCertificate(p) => serde_json::to_string(p),
2142            Self::GetBaseReport(p) => serde_json::to_string(p),
2143            Self::GetChargingProfiles(p) => serde_json::to_string(p),
2144            Self::GetCompositeSchedule(p) => serde_json::to_string(p),
2145            Self::GetDisplayMessages(p) => serde_json::to_string(p),
2146            Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
2147            Self::GetLocalListVersion(p) => serde_json::to_string(p),
2148            Self::GetLog(p) => serde_json::to_string(p),
2149            Self::GetMonitoringReport(p) => serde_json::to_string(p),
2150            Self::GetReport(p) => serde_json::to_string(p),
2151            Self::GetTransactionStatus(p) => serde_json::to_string(p),
2152            Self::GetVariables(p) => serde_json::to_string(p),
2153            Self::InstallCertificate(p) => serde_json::to_string(p),
2154            Self::PublishFirmware(p) => serde_json::to_string(p),
2155            Self::RequestStartTransaction(p) => serde_json::to_string(p),
2156            Self::RequestStopTransaction(p) => serde_json::to_string(p),
2157            Self::ReserveNow(p) => serde_json::to_string(p),
2158            Self::Reset(p) => serde_json::to_string(p),
2159            Self::SendLocalList(p) => serde_json::to_string(p),
2160            Self::SetChargingProfile(p) => serde_json::to_string(p),
2161            Self::SetDisplayMessage(p) => serde_json::to_string(p),
2162            Self::SetMonitoringBase(p) => serde_json::to_string(p),
2163            Self::SetMonitoringLevel(p) => serde_json::to_string(p),
2164            Self::SetNetworkProfile(p) => serde_json::to_string(p),
2165            Self::SetVariableMonitoring(p) => serde_json::to_string(p),
2166            Self::SetVariables(p) => serde_json::to_string(p),
2167            Self::TriggerMessage(p) => serde_json::to_string(p),
2168            Self::UnlockConnector(p) => serde_json::to_string(p),
2169            Self::UnpublishFirmware(p) => serde_json::to_string(p),
2170            Self::UpdateFirmware(p) => serde_json::to_string(p),
2171        }
2172    }
2173}
2174
2175impl Validate for CsmsRequest {
2176    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
2177        match self {
2178            Self::CancelReservation(p) => p.validate_at(path, out),
2179            Self::CertificateSigned(p) => p.validate_at(path, out),
2180            Self::ChangeAvailability(p) => p.validate_at(path, out),
2181            Self::ClearCache(p) => p.validate_at(path, out),
2182            Self::ClearChargingProfile(p) => p.validate_at(path, out),
2183            Self::ClearDisplayMessage(p) => p.validate_at(path, out),
2184            Self::ClearVariableMonitoring(p) => p.validate_at(path, out),
2185            Self::CostUpdated(p) => p.validate_at(path, out),
2186            Self::CustomerInformation(p) => p.validate_at(path, out),
2187            Self::DataTransfer(p) => p.validate_at(path, out),
2188            Self::DeleteCertificate(p) => p.validate_at(path, out),
2189            Self::GetBaseReport(p) => p.validate_at(path, out),
2190            Self::GetChargingProfiles(p) => p.validate_at(path, out),
2191            Self::GetCompositeSchedule(p) => p.validate_at(path, out),
2192            Self::GetDisplayMessages(p) => p.validate_at(path, out),
2193            Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
2194            Self::GetLocalListVersion(p) => p.validate_at(path, out),
2195            Self::GetLog(p) => p.validate_at(path, out),
2196            Self::GetMonitoringReport(p) => p.validate_at(path, out),
2197            Self::GetReport(p) => p.validate_at(path, out),
2198            Self::GetTransactionStatus(p) => p.validate_at(path, out),
2199            Self::GetVariables(p) => p.validate_at(path, out),
2200            Self::InstallCertificate(p) => p.validate_at(path, out),
2201            Self::PublishFirmware(p) => p.validate_at(path, out),
2202            Self::RequestStartTransaction(p) => p.validate_at(path, out),
2203            Self::RequestStopTransaction(p) => p.validate_at(path, out),
2204            Self::ReserveNow(p) => p.validate_at(path, out),
2205            Self::Reset(p) => p.validate_at(path, out),
2206            Self::SendLocalList(p) => p.validate_at(path, out),
2207            Self::SetChargingProfile(p) => p.validate_at(path, out),
2208            Self::SetDisplayMessage(p) => p.validate_at(path, out),
2209            Self::SetMonitoringBase(p) => p.validate_at(path, out),
2210            Self::SetMonitoringLevel(p) => p.validate_at(path, out),
2211            Self::SetNetworkProfile(p) => p.validate_at(path, out),
2212            Self::SetVariableMonitoring(p) => p.validate_at(path, out),
2213            Self::SetVariables(p) => p.validate_at(path, out),
2214            Self::TriggerMessage(p) => p.validate_at(path, out),
2215            Self::UnlockConnector(p) => p.validate_at(path, out),
2216            Self::UnpublishFirmware(p) => p.validate_at(path, out),
2217            Self::UpdateFirmware(p) => p.validate_at(path, out),
2218        }
2219    }
2220}
2221
2222impl serde::Serialize for CsmsRequest {
2223    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
2224        match self {
2225            Self::CancelReservation(p) => p.serialize(ser),
2226            Self::CertificateSigned(p) => p.serialize(ser),
2227            Self::ChangeAvailability(p) => p.serialize(ser),
2228            Self::ClearCache(p) => p.serialize(ser),
2229            Self::ClearChargingProfile(p) => p.serialize(ser),
2230            Self::ClearDisplayMessage(p) => p.serialize(ser),
2231            Self::ClearVariableMonitoring(p) => p.serialize(ser),
2232            Self::CostUpdated(p) => p.serialize(ser),
2233            Self::CustomerInformation(p) => p.serialize(ser),
2234            Self::DataTransfer(p) => p.serialize(ser),
2235            Self::DeleteCertificate(p) => p.serialize(ser),
2236            Self::GetBaseReport(p) => p.serialize(ser),
2237            Self::GetChargingProfiles(p) => p.serialize(ser),
2238            Self::GetCompositeSchedule(p) => p.serialize(ser),
2239            Self::GetDisplayMessages(p) => p.serialize(ser),
2240            Self::GetInstalledCertificateIds(p) => p.serialize(ser),
2241            Self::GetLocalListVersion(p) => p.serialize(ser),
2242            Self::GetLog(p) => p.serialize(ser),
2243            Self::GetMonitoringReport(p) => p.serialize(ser),
2244            Self::GetReport(p) => p.serialize(ser),
2245            Self::GetTransactionStatus(p) => p.serialize(ser),
2246            Self::GetVariables(p) => p.serialize(ser),
2247            Self::InstallCertificate(p) => p.serialize(ser),
2248            Self::PublishFirmware(p) => p.serialize(ser),
2249            Self::RequestStartTransaction(p) => p.serialize(ser),
2250            Self::RequestStopTransaction(p) => p.serialize(ser),
2251            Self::ReserveNow(p) => p.serialize(ser),
2252            Self::Reset(p) => p.serialize(ser),
2253            Self::SendLocalList(p) => p.serialize(ser),
2254            Self::SetChargingProfile(p) => p.serialize(ser),
2255            Self::SetDisplayMessage(p) => p.serialize(ser),
2256            Self::SetMonitoringBase(p) => p.serialize(ser),
2257            Self::SetMonitoringLevel(p) => p.serialize(ser),
2258            Self::SetNetworkProfile(p) => p.serialize(ser),
2259            Self::SetVariableMonitoring(p) => p.serialize(ser),
2260            Self::SetVariables(p) => p.serialize(ser),
2261            Self::TriggerMessage(p) => p.serialize(ser),
2262            Self::UnlockConnector(p) => p.serialize(ser),
2263            Self::UnpublishFirmware(p) => p.serialize(ser),
2264            Self::UpdateFirmware(p) => p.serialize(ser),
2265        }
2266    }
2267}
2268
2269impl crate::message::Sealed for CsmsRequest {}
2270
2271impl crate::message::DecodeRequest for CsmsRequest {
2272    type Action = Action;
2273
2274    fn decode_reporting(
2275        action: Action,
2276        payload: &RawValue,
2277        options: &DecodeOptions,
2278    ) -> Result<crate::decode::Decoded<Self>, DecodeError> {
2279        CsmsRequest::decode_reporting(action, payload, options)
2280    }
2281}
2282
2283/// The Charging Station's answer to a [`CsmsRequest`] (CS → CSMS) in OCPP 2.0.1.
2284#[derive(Clone, Debug, PartialEq)]
2285#[non_exhaustive]
2286#[allow(clippy::large_enum_variant)]
2287pub enum CsmsResponse {
2288    /// `CancelReservation`.
2289    CancelReservation(CancelReservationResponse),
2290    /// `CertificateSigned`.
2291    CertificateSigned(CertificateSignedResponse),
2292    /// `ChangeAvailability`.
2293    ChangeAvailability(ChangeAvailabilityResponse),
2294    /// `ClearCache`.
2295    ClearCache(ClearCacheResponse),
2296    /// `ClearChargingProfile`.
2297    ClearChargingProfile(ClearChargingProfileResponse),
2298    /// `ClearDisplayMessage`.
2299    ClearDisplayMessage(ClearDisplayMessageResponse),
2300    /// `ClearVariableMonitoring`.
2301    ClearVariableMonitoring(ClearVariableMonitoringResponse),
2302    /// `CostUpdated`.
2303    CostUpdated(CostUpdatedResponse),
2304    /// `CustomerInformation`.
2305    CustomerInformation(CustomerInformationResponse),
2306    /// `DataTransfer`.
2307    DataTransfer(DataTransferResponse),
2308    /// `DeleteCertificate`.
2309    DeleteCertificate(DeleteCertificateResponse),
2310    /// `GetBaseReport`.
2311    GetBaseReport(GetBaseReportResponse),
2312    /// `GetChargingProfiles`.
2313    GetChargingProfiles(GetChargingProfilesResponse),
2314    /// `GetCompositeSchedule`.
2315    GetCompositeSchedule(GetCompositeScheduleResponse),
2316    /// `GetDisplayMessages`.
2317    GetDisplayMessages(GetDisplayMessagesResponse),
2318    /// `GetInstalledCertificateIds`.
2319    GetInstalledCertificateIds(GetInstalledCertificateIdsResponse),
2320    /// `GetLocalListVersion`.
2321    GetLocalListVersion(GetLocalListVersionResponse),
2322    /// `GetLog`.
2323    GetLog(GetLogResponse),
2324    /// `GetMonitoringReport`.
2325    GetMonitoringReport(GetMonitoringReportResponse),
2326    /// `GetReport`.
2327    GetReport(GetReportResponse),
2328    /// `GetTransactionStatus`.
2329    GetTransactionStatus(GetTransactionStatusResponse),
2330    /// `GetVariables`.
2331    GetVariables(GetVariablesResponse),
2332    /// `InstallCertificate`.
2333    InstallCertificate(InstallCertificateResponse),
2334    /// `PublishFirmware`.
2335    PublishFirmware(PublishFirmwareResponse),
2336    /// `RequestStartTransaction`.
2337    RequestStartTransaction(RequestStartTransactionResponse),
2338    /// `RequestStopTransaction`.
2339    RequestStopTransaction(RequestStopTransactionResponse),
2340    /// `ReserveNow`.
2341    ReserveNow(ReserveNowResponse),
2342    /// `Reset`.
2343    Reset(ResetResponse),
2344    /// `SendLocalList`.
2345    SendLocalList(SendLocalListResponse),
2346    /// `SetChargingProfile`.
2347    SetChargingProfile(SetChargingProfileResponse),
2348    /// `SetDisplayMessage`.
2349    SetDisplayMessage(SetDisplayMessageResponse),
2350    /// `SetMonitoringBase`.
2351    SetMonitoringBase(SetMonitoringBaseResponse),
2352    /// `SetMonitoringLevel`.
2353    SetMonitoringLevel(SetMonitoringLevelResponse),
2354    /// `SetNetworkProfile`.
2355    SetNetworkProfile(SetNetworkProfileResponse),
2356    /// `SetVariableMonitoring`.
2357    SetVariableMonitoring(SetVariableMonitoringResponse),
2358    /// `SetVariables`.
2359    SetVariables(SetVariablesResponse),
2360    /// `TriggerMessage`.
2361    TriggerMessage(TriggerMessageResponse),
2362    /// `UnlockConnector`.
2363    UnlockConnector(UnlockConnectorResponse),
2364    /// `UnpublishFirmware`.
2365    UnpublishFirmware(UnpublishFirmwareResponse),
2366    /// `UpdateFirmware`.
2367    UpdateFirmware(UpdateFirmwareResponse),
2368}
2369
2370impl CsmsResponse {
2371    /// The action this payload belongs to.
2372    #[must_use]
2373    pub const fn action(&self) -> Action {
2374        match self {
2375            Self::CancelReservation(_) => Action::CancelReservation,
2376            Self::CertificateSigned(_) => Action::CertificateSigned,
2377            Self::ChangeAvailability(_) => Action::ChangeAvailability,
2378            Self::ClearCache(_) => Action::ClearCache,
2379            Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
2380            Self::ClearDisplayMessage(_) => Action::ClearDisplayMessage,
2381            Self::ClearVariableMonitoring(_) => Action::ClearVariableMonitoring,
2382            Self::CostUpdated(_) => Action::CostUpdated,
2383            Self::CustomerInformation(_) => Action::CustomerInformation,
2384            Self::DataTransfer(_) => Action::DataTransfer,
2385            Self::DeleteCertificate(_) => Action::DeleteCertificate,
2386            Self::GetBaseReport(_) => Action::GetBaseReport,
2387            Self::GetChargingProfiles(_) => Action::GetChargingProfiles,
2388            Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
2389            Self::GetDisplayMessages(_) => Action::GetDisplayMessages,
2390            Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
2391            Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
2392            Self::GetLog(_) => Action::GetLog,
2393            Self::GetMonitoringReport(_) => Action::GetMonitoringReport,
2394            Self::GetReport(_) => Action::GetReport,
2395            Self::GetTransactionStatus(_) => Action::GetTransactionStatus,
2396            Self::GetVariables(_) => Action::GetVariables,
2397            Self::InstallCertificate(_) => Action::InstallCertificate,
2398            Self::PublishFirmware(_) => Action::PublishFirmware,
2399            Self::RequestStartTransaction(_) => Action::RequestStartTransaction,
2400            Self::RequestStopTransaction(_) => Action::RequestStopTransaction,
2401            Self::ReserveNow(_) => Action::ReserveNow,
2402            Self::Reset(_) => Action::Reset,
2403            Self::SendLocalList(_) => Action::SendLocalList,
2404            Self::SetChargingProfile(_) => Action::SetChargingProfile,
2405            Self::SetDisplayMessage(_) => Action::SetDisplayMessage,
2406            Self::SetMonitoringBase(_) => Action::SetMonitoringBase,
2407            Self::SetMonitoringLevel(_) => Action::SetMonitoringLevel,
2408            Self::SetNetworkProfile(_) => Action::SetNetworkProfile,
2409            Self::SetVariableMonitoring(_) => Action::SetVariableMonitoring,
2410            Self::SetVariables(_) => Action::SetVariables,
2411            Self::TriggerMessage(_) => Action::TriggerMessage,
2412            Self::UnlockConnector(_) => Action::UnlockConnector,
2413            Self::UnpublishFirmware(_) => Action::UnpublishFirmware,
2414            Self::UpdateFirmware(_) => Action::UpdateFirmware,
2415        }
2416    }
2417
2418    /// Decodes a raw JSON payload for `action`, classifying every failure so the
2419    /// caller can answer with the correct OCPP error code.
2420    pub fn decode(
2421        action: Action,
2422        payload: &RawValue,
2423        options: &DecodeOptions,
2424    ) -> Result<Self, DecodeError> {
2425        Ok(match action {
2426            Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
2427                CancelReservationResponse,
2428            >(payload, options)?),
2429            Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
2430                CertificateSignedResponse,
2431            >(payload, options)?),
2432            Action::ChangeAvailability => Self::ChangeAvailability(
2433                crate::decode::decode_payload::<ChangeAvailabilityResponse>(payload, options)?,
2434            ),
2435            Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
2436                ClearCacheResponse,
2437            >(payload, options)?),
2438            Action::ClearChargingProfile => {
2439                Self::ClearChargingProfile(crate::decode::decode_payload::<
2440                    ClearChargingProfileResponse,
2441                >(payload, options)?)
2442            }
2443            Action::ClearDisplayMessage => {
2444                Self::ClearDisplayMessage(crate::decode::decode_payload::<
2445                    ClearDisplayMessageResponse,
2446                >(payload, options)?)
2447            }
2448            Action::ClearVariableMonitoring => {
2449                Self::ClearVariableMonitoring(crate::decode::decode_payload::<
2450                    ClearVariableMonitoringResponse,
2451                >(payload, options)?)
2452            }
2453            Action::CostUpdated => Self::CostUpdated(crate::decode::decode_payload::<
2454                CostUpdatedResponse,
2455            >(payload, options)?),
2456            Action::CustomerInformation => {
2457                Self::CustomerInformation(crate::decode::decode_payload::<
2458                    CustomerInformationResponse,
2459                >(payload, options)?)
2460            }
2461            Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
2462                DataTransferResponse,
2463            >(payload, options)?),
2464            Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
2465                DeleteCertificateResponse,
2466            >(payload, options)?),
2467            Action::GetBaseReport => Self::GetBaseReport(crate::decode::decode_payload::<
2468                GetBaseReportResponse,
2469            >(payload, options)?),
2470            Action::GetChargingProfiles => {
2471                Self::GetChargingProfiles(crate::decode::decode_payload::<
2472                    GetChargingProfilesResponse,
2473                >(payload, options)?)
2474            }
2475            Action::GetCompositeSchedule => {
2476                Self::GetCompositeSchedule(crate::decode::decode_payload::<
2477                    GetCompositeScheduleResponse,
2478                >(payload, options)?)
2479            }
2480            Action::GetDisplayMessages => Self::GetDisplayMessages(
2481                crate::decode::decode_payload::<GetDisplayMessagesResponse>(payload, options)?,
2482            ),
2483            Action::GetInstalledCertificateIds => {
2484                Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
2485                    GetInstalledCertificateIdsResponse,
2486                >(payload, options)?)
2487            }
2488            Action::GetLocalListVersion => {
2489                Self::GetLocalListVersion(crate::decode::decode_payload::<
2490                    GetLocalListVersionResponse,
2491                >(payload, options)?)
2492            }
2493            Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogResponse>(
2494                payload, options,
2495            )?),
2496            Action::GetMonitoringReport => {
2497                Self::GetMonitoringReport(crate::decode::decode_payload::<
2498                    GetMonitoringReportResponse,
2499                >(payload, options)?)
2500            }
2501            Action::GetReport => Self::GetReport(
2502                crate::decode::decode_payload::<GetReportResponse>(payload, options)?,
2503            ),
2504            Action::GetTransactionStatus => {
2505                Self::GetTransactionStatus(crate::decode::decode_payload::<
2506                    GetTransactionStatusResponse,
2507                >(payload, options)?)
2508            }
2509            Action::GetVariables => Self::GetVariables(crate::decode::decode_payload::<
2510                GetVariablesResponse,
2511            >(payload, options)?),
2512            Action::InstallCertificate => Self::InstallCertificate(
2513                crate::decode::decode_payload::<InstallCertificateResponse>(payload, options)?,
2514            ),
2515            Action::PublishFirmware => Self::PublishFirmware(crate::decode::decode_payload::<
2516                PublishFirmwareResponse,
2517            >(payload, options)?),
2518            Action::RequestStartTransaction => {
2519                Self::RequestStartTransaction(crate::decode::decode_payload::<
2520                    RequestStartTransactionResponse,
2521                >(payload, options)?)
2522            }
2523            Action::RequestStopTransaction => {
2524                Self::RequestStopTransaction(crate::decode::decode_payload::<
2525                    RequestStopTransactionResponse,
2526                >(payload, options)?)
2527            }
2528            Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
2529                ReserveNowResponse,
2530            >(payload, options)?),
2531            Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetResponse>(
2532                payload, options,
2533            )?),
2534            Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
2535                SendLocalListResponse,
2536            >(payload, options)?),
2537            Action::SetChargingProfile => Self::SetChargingProfile(
2538                crate::decode::decode_payload::<SetChargingProfileResponse>(payload, options)?,
2539            ),
2540            Action::SetDisplayMessage => Self::SetDisplayMessage(crate::decode::decode_payload::<
2541                SetDisplayMessageResponse,
2542            >(payload, options)?),
2543            Action::SetMonitoringBase => Self::SetMonitoringBase(crate::decode::decode_payload::<
2544                SetMonitoringBaseResponse,
2545            >(payload, options)?),
2546            Action::SetMonitoringLevel => Self::SetMonitoringLevel(
2547                crate::decode::decode_payload::<SetMonitoringLevelResponse>(payload, options)?,
2548            ),
2549            Action::SetNetworkProfile => Self::SetNetworkProfile(crate::decode::decode_payload::<
2550                SetNetworkProfileResponse,
2551            >(payload, options)?),
2552            Action::SetVariableMonitoring => {
2553                Self::SetVariableMonitoring(crate::decode::decode_payload::<
2554                    SetVariableMonitoringResponse,
2555                >(payload, options)?)
2556            }
2557            Action::SetVariables => Self::SetVariables(crate::decode::decode_payload::<
2558                SetVariablesResponse,
2559            >(payload, options)?),
2560            Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
2561                TriggerMessageResponse,
2562            >(payload, options)?),
2563            Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
2564                UnlockConnectorResponse,
2565            >(payload, options)?),
2566            Action::UnpublishFirmware => Self::UnpublishFirmware(crate::decode::decode_payload::<
2567                UnpublishFirmwareResponse,
2568            >(payload, options)?),
2569            Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
2570                UpdateFirmwareResponse,
2571            >(payload, options)?),
2572            other => return Err(DecodeError::unsupported_action(other.as_str())),
2573        })
2574    }
2575
2576    /// Serializes the payload object (without the OCPP-J frame).
2577    pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
2578        match self {
2579            Self::CancelReservation(p) => serde_json::to_string(p),
2580            Self::CertificateSigned(p) => serde_json::to_string(p),
2581            Self::ChangeAvailability(p) => serde_json::to_string(p),
2582            Self::ClearCache(p) => serde_json::to_string(p),
2583            Self::ClearChargingProfile(p) => serde_json::to_string(p),
2584            Self::ClearDisplayMessage(p) => serde_json::to_string(p),
2585            Self::ClearVariableMonitoring(p) => serde_json::to_string(p),
2586            Self::CostUpdated(p) => serde_json::to_string(p),
2587            Self::CustomerInformation(p) => serde_json::to_string(p),
2588            Self::DataTransfer(p) => serde_json::to_string(p),
2589            Self::DeleteCertificate(p) => serde_json::to_string(p),
2590            Self::GetBaseReport(p) => serde_json::to_string(p),
2591            Self::GetChargingProfiles(p) => serde_json::to_string(p),
2592            Self::GetCompositeSchedule(p) => serde_json::to_string(p),
2593            Self::GetDisplayMessages(p) => serde_json::to_string(p),
2594            Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
2595            Self::GetLocalListVersion(p) => serde_json::to_string(p),
2596            Self::GetLog(p) => serde_json::to_string(p),
2597            Self::GetMonitoringReport(p) => serde_json::to_string(p),
2598            Self::GetReport(p) => serde_json::to_string(p),
2599            Self::GetTransactionStatus(p) => serde_json::to_string(p),
2600            Self::GetVariables(p) => serde_json::to_string(p),
2601            Self::InstallCertificate(p) => serde_json::to_string(p),
2602            Self::PublishFirmware(p) => serde_json::to_string(p),
2603            Self::RequestStartTransaction(p) => serde_json::to_string(p),
2604            Self::RequestStopTransaction(p) => serde_json::to_string(p),
2605            Self::ReserveNow(p) => serde_json::to_string(p),
2606            Self::Reset(p) => serde_json::to_string(p),
2607            Self::SendLocalList(p) => serde_json::to_string(p),
2608            Self::SetChargingProfile(p) => serde_json::to_string(p),
2609            Self::SetDisplayMessage(p) => serde_json::to_string(p),
2610            Self::SetMonitoringBase(p) => serde_json::to_string(p),
2611            Self::SetMonitoringLevel(p) => serde_json::to_string(p),
2612            Self::SetNetworkProfile(p) => serde_json::to_string(p),
2613            Self::SetVariableMonitoring(p) => serde_json::to_string(p),
2614            Self::SetVariables(p) => serde_json::to_string(p),
2615            Self::TriggerMessage(p) => serde_json::to_string(p),
2616            Self::UnlockConnector(p) => serde_json::to_string(p),
2617            Self::UnpublishFirmware(p) => serde_json::to_string(p),
2618            Self::UpdateFirmware(p) => serde_json::to_string(p),
2619        }
2620    }
2621}
2622
2623impl Validate for CsmsResponse {
2624    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
2625        match self {
2626            Self::CancelReservation(p) => p.validate_at(path, out),
2627            Self::CertificateSigned(p) => p.validate_at(path, out),
2628            Self::ChangeAvailability(p) => p.validate_at(path, out),
2629            Self::ClearCache(p) => p.validate_at(path, out),
2630            Self::ClearChargingProfile(p) => p.validate_at(path, out),
2631            Self::ClearDisplayMessage(p) => p.validate_at(path, out),
2632            Self::ClearVariableMonitoring(p) => p.validate_at(path, out),
2633            Self::CostUpdated(p) => p.validate_at(path, out),
2634            Self::CustomerInformation(p) => p.validate_at(path, out),
2635            Self::DataTransfer(p) => p.validate_at(path, out),
2636            Self::DeleteCertificate(p) => p.validate_at(path, out),
2637            Self::GetBaseReport(p) => p.validate_at(path, out),
2638            Self::GetChargingProfiles(p) => p.validate_at(path, out),
2639            Self::GetCompositeSchedule(p) => p.validate_at(path, out),
2640            Self::GetDisplayMessages(p) => p.validate_at(path, out),
2641            Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
2642            Self::GetLocalListVersion(p) => p.validate_at(path, out),
2643            Self::GetLog(p) => p.validate_at(path, out),
2644            Self::GetMonitoringReport(p) => p.validate_at(path, out),
2645            Self::GetReport(p) => p.validate_at(path, out),
2646            Self::GetTransactionStatus(p) => p.validate_at(path, out),
2647            Self::GetVariables(p) => p.validate_at(path, out),
2648            Self::InstallCertificate(p) => p.validate_at(path, out),
2649            Self::PublishFirmware(p) => p.validate_at(path, out),
2650            Self::RequestStartTransaction(p) => p.validate_at(path, out),
2651            Self::RequestStopTransaction(p) => p.validate_at(path, out),
2652            Self::ReserveNow(p) => p.validate_at(path, out),
2653            Self::Reset(p) => p.validate_at(path, out),
2654            Self::SendLocalList(p) => p.validate_at(path, out),
2655            Self::SetChargingProfile(p) => p.validate_at(path, out),
2656            Self::SetDisplayMessage(p) => p.validate_at(path, out),
2657            Self::SetMonitoringBase(p) => p.validate_at(path, out),
2658            Self::SetMonitoringLevel(p) => p.validate_at(path, out),
2659            Self::SetNetworkProfile(p) => p.validate_at(path, out),
2660            Self::SetVariableMonitoring(p) => p.validate_at(path, out),
2661            Self::SetVariables(p) => p.validate_at(path, out),
2662            Self::TriggerMessage(p) => p.validate_at(path, out),
2663            Self::UnlockConnector(p) => p.validate_at(path, out),
2664            Self::UnpublishFirmware(p) => p.validate_at(path, out),
2665            Self::UpdateFirmware(p) => p.validate_at(path, out),
2666        }
2667    }
2668}
2669
2670impl serde::Serialize for CsmsResponse {
2671    fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
2672        match self {
2673            Self::CancelReservation(p) => p.serialize(ser),
2674            Self::CertificateSigned(p) => p.serialize(ser),
2675            Self::ChangeAvailability(p) => p.serialize(ser),
2676            Self::ClearCache(p) => p.serialize(ser),
2677            Self::ClearChargingProfile(p) => p.serialize(ser),
2678            Self::ClearDisplayMessage(p) => p.serialize(ser),
2679            Self::ClearVariableMonitoring(p) => p.serialize(ser),
2680            Self::CostUpdated(p) => p.serialize(ser),
2681            Self::CustomerInformation(p) => p.serialize(ser),
2682            Self::DataTransfer(p) => p.serialize(ser),
2683            Self::DeleteCertificate(p) => p.serialize(ser),
2684            Self::GetBaseReport(p) => p.serialize(ser),
2685            Self::GetChargingProfiles(p) => p.serialize(ser),
2686            Self::GetCompositeSchedule(p) => p.serialize(ser),
2687            Self::GetDisplayMessages(p) => p.serialize(ser),
2688            Self::GetInstalledCertificateIds(p) => p.serialize(ser),
2689            Self::GetLocalListVersion(p) => p.serialize(ser),
2690            Self::GetLog(p) => p.serialize(ser),
2691            Self::GetMonitoringReport(p) => p.serialize(ser),
2692            Self::GetReport(p) => p.serialize(ser),
2693            Self::GetTransactionStatus(p) => p.serialize(ser),
2694            Self::GetVariables(p) => p.serialize(ser),
2695            Self::InstallCertificate(p) => p.serialize(ser),
2696            Self::PublishFirmware(p) => p.serialize(ser),
2697            Self::RequestStartTransaction(p) => p.serialize(ser),
2698            Self::RequestStopTransaction(p) => p.serialize(ser),
2699            Self::ReserveNow(p) => p.serialize(ser),
2700            Self::Reset(p) => p.serialize(ser),
2701            Self::SendLocalList(p) => p.serialize(ser),
2702            Self::SetChargingProfile(p) => p.serialize(ser),
2703            Self::SetDisplayMessage(p) => p.serialize(ser),
2704            Self::SetMonitoringBase(p) => p.serialize(ser),
2705            Self::SetMonitoringLevel(p) => p.serialize(ser),
2706            Self::SetNetworkProfile(p) => p.serialize(ser),
2707            Self::SetVariableMonitoring(p) => p.serialize(ser),
2708            Self::SetVariables(p) => p.serialize(ser),
2709            Self::TriggerMessage(p) => p.serialize(ser),
2710            Self::UnlockConnector(p) => p.serialize(ser),
2711            Self::UnpublishFirmware(p) => p.serialize(ser),
2712            Self::UpdateFirmware(p) => p.serialize(ser),
2713        }
2714    }
2715}