Skip to main content

codetics_ocpp201/
actions.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Kevin Vavelin, Codetics (https://codetics.fr)
3
4//! OCPP 2.0.1 actions: message direction, request/response pairing and typed dispatch.
5
6// Call enums hold one decoded payload transiently; boxing every variant would only add allocations.
7#![allow(clippy::large_enum_variant)]
8
9use ocpp_core::validate::Violation;
10
11use crate::messages::*;
12
13impl ocpp_core::Request for AuthorizeRequest {
14    const ACTION: &'static str = "Authorize";
15    type Response = AuthorizeResponse;
16}
17
18impl ocpp_core::Request for BootNotificationRequest {
19    const ACTION: &'static str = "BootNotification";
20    type Response = BootNotificationResponse;
21}
22
23impl ocpp_core::Request for CancelReservationRequest {
24    const ACTION: &'static str = "CancelReservation";
25    type Response = CancelReservationResponse;
26}
27
28impl ocpp_core::Request for CertificateSignedRequest {
29    const ACTION: &'static str = "CertificateSigned";
30    type Response = CertificateSignedResponse;
31}
32
33impl ocpp_core::Request for ChangeAvailabilityRequest {
34    const ACTION: &'static str = "ChangeAvailability";
35    type Response = ChangeAvailabilityResponse;
36}
37
38impl ocpp_core::Request for ClearCacheRequest {
39    const ACTION: &'static str = "ClearCache";
40    type Response = ClearCacheResponse;
41}
42
43impl ocpp_core::Request for ClearChargingProfileRequest {
44    const ACTION: &'static str = "ClearChargingProfile";
45    type Response = ClearChargingProfileResponse;
46}
47
48impl ocpp_core::Request for ClearDisplayMessageRequest {
49    const ACTION: &'static str = "ClearDisplayMessage";
50    type Response = ClearDisplayMessageResponse;
51}
52
53impl ocpp_core::Request for ClearVariableMonitoringRequest {
54    const ACTION: &'static str = "ClearVariableMonitoring";
55    type Response = ClearVariableMonitoringResponse;
56}
57
58impl ocpp_core::Request for ClearedChargingLimitRequest {
59    const ACTION: &'static str = "ClearedChargingLimit";
60    type Response = ClearedChargingLimitResponse;
61}
62
63impl ocpp_core::Request for CostUpdatedRequest {
64    const ACTION: &'static str = "CostUpdated";
65    type Response = CostUpdatedResponse;
66}
67
68impl ocpp_core::Request for CustomerInformationRequest {
69    const ACTION: &'static str = "CustomerInformation";
70    type Response = CustomerInformationResponse;
71}
72
73impl ocpp_core::Request for DataTransferRequest {
74    const ACTION: &'static str = "DataTransfer";
75    type Response = DataTransferResponse;
76}
77
78impl ocpp_core::Request for DeleteCertificateRequest {
79    const ACTION: &'static str = "DeleteCertificate";
80    type Response = DeleteCertificateResponse;
81}
82
83impl ocpp_core::Request for FirmwareStatusNotificationRequest {
84    const ACTION: &'static str = "FirmwareStatusNotification";
85    type Response = FirmwareStatusNotificationResponse;
86}
87
88impl ocpp_core::Request for Get15118EVCertificateRequest {
89    const ACTION: &'static str = "Get15118EVCertificate";
90    type Response = Get15118EVCertificateResponse;
91}
92
93impl ocpp_core::Request for GetBaseReportRequest {
94    const ACTION: &'static str = "GetBaseReport";
95    type Response = GetBaseReportResponse;
96}
97
98impl ocpp_core::Request for GetCertificateStatusRequest {
99    const ACTION: &'static str = "GetCertificateStatus";
100    type Response = GetCertificateStatusResponse;
101}
102
103impl ocpp_core::Request for GetChargingProfilesRequest {
104    const ACTION: &'static str = "GetChargingProfiles";
105    type Response = GetChargingProfilesResponse;
106}
107
108impl ocpp_core::Request for GetCompositeScheduleRequest {
109    const ACTION: &'static str = "GetCompositeSchedule";
110    type Response = GetCompositeScheduleResponse;
111}
112
113impl ocpp_core::Request for GetDisplayMessagesRequest {
114    const ACTION: &'static str = "GetDisplayMessages";
115    type Response = GetDisplayMessagesResponse;
116}
117
118impl ocpp_core::Request for GetInstalledCertificateIdsRequest {
119    const ACTION: &'static str = "GetInstalledCertificateIds";
120    type Response = GetInstalledCertificateIdsResponse;
121}
122
123impl ocpp_core::Request for GetLocalListVersionRequest {
124    const ACTION: &'static str = "GetLocalListVersion";
125    type Response = GetLocalListVersionResponse;
126}
127
128impl ocpp_core::Request for GetLogRequest {
129    const ACTION: &'static str = "GetLog";
130    type Response = GetLogResponse;
131}
132
133impl ocpp_core::Request for GetMonitoringReportRequest {
134    const ACTION: &'static str = "GetMonitoringReport";
135    type Response = GetMonitoringReportResponse;
136}
137
138impl ocpp_core::Request for GetReportRequest {
139    const ACTION: &'static str = "GetReport";
140    type Response = GetReportResponse;
141}
142
143impl ocpp_core::Request for GetTransactionStatusRequest {
144    const ACTION: &'static str = "GetTransactionStatus";
145    type Response = GetTransactionStatusResponse;
146}
147
148impl ocpp_core::Request for GetVariablesRequest {
149    const ACTION: &'static str = "GetVariables";
150    type Response = GetVariablesResponse;
151}
152
153impl ocpp_core::Request for HeartbeatRequest {
154    const ACTION: &'static str = "Heartbeat";
155    type Response = HeartbeatResponse;
156}
157
158impl ocpp_core::Request for InstallCertificateRequest {
159    const ACTION: &'static str = "InstallCertificate";
160    type Response = InstallCertificateResponse;
161}
162
163impl ocpp_core::Request for LogStatusNotificationRequest {
164    const ACTION: &'static str = "LogStatusNotification";
165    type Response = LogStatusNotificationResponse;
166}
167
168impl ocpp_core::Request for MeterValuesRequest {
169    const ACTION: &'static str = "MeterValues";
170    type Response = MeterValuesResponse;
171}
172
173impl ocpp_core::Request for NotifyChargingLimitRequest {
174    const ACTION: &'static str = "NotifyChargingLimit";
175    type Response = NotifyChargingLimitResponse;
176}
177
178impl ocpp_core::Request for NotifyCustomerInformationRequest {
179    const ACTION: &'static str = "NotifyCustomerInformation";
180    type Response = NotifyCustomerInformationResponse;
181}
182
183impl ocpp_core::Request for NotifyDisplayMessagesRequest {
184    const ACTION: &'static str = "NotifyDisplayMessages";
185    type Response = NotifyDisplayMessagesResponse;
186}
187
188impl ocpp_core::Request for NotifyEVChargingNeedsRequest {
189    const ACTION: &'static str = "NotifyEVChargingNeeds";
190    type Response = NotifyEVChargingNeedsResponse;
191}
192
193impl ocpp_core::Request for NotifyEVChargingScheduleRequest {
194    const ACTION: &'static str = "NotifyEVChargingSchedule";
195    type Response = NotifyEVChargingScheduleResponse;
196}
197
198impl ocpp_core::Request for NotifyEventRequest {
199    const ACTION: &'static str = "NotifyEvent";
200    type Response = NotifyEventResponse;
201}
202
203impl ocpp_core::Request for NotifyMonitoringReportRequest {
204    const ACTION: &'static str = "NotifyMonitoringReport";
205    type Response = NotifyMonitoringReportResponse;
206}
207
208impl ocpp_core::Request for NotifyReportRequest {
209    const ACTION: &'static str = "NotifyReport";
210    type Response = NotifyReportResponse;
211}
212
213impl ocpp_core::Request for PublishFirmwareRequest {
214    const ACTION: &'static str = "PublishFirmware";
215    type Response = PublishFirmwareResponse;
216}
217
218impl ocpp_core::Request for PublishFirmwareStatusNotificationRequest {
219    const ACTION: &'static str = "PublishFirmwareStatusNotification";
220    type Response = PublishFirmwareStatusNotificationResponse;
221}
222
223impl ocpp_core::Request for ReportChargingProfilesRequest {
224    const ACTION: &'static str = "ReportChargingProfiles";
225    type Response = ReportChargingProfilesResponse;
226}
227
228impl ocpp_core::Request for RequestStartTransactionRequest {
229    const ACTION: &'static str = "RequestStartTransaction";
230    type Response = RequestStartTransactionResponse;
231}
232
233impl ocpp_core::Request for RequestStopTransactionRequest {
234    const ACTION: &'static str = "RequestStopTransaction";
235    type Response = RequestStopTransactionResponse;
236}
237
238impl ocpp_core::Request for ReservationStatusUpdateRequest {
239    const ACTION: &'static str = "ReservationStatusUpdate";
240    type Response = ReservationStatusUpdateResponse;
241}
242
243impl ocpp_core::Request for ReserveNowRequest {
244    const ACTION: &'static str = "ReserveNow";
245    type Response = ReserveNowResponse;
246}
247
248impl ocpp_core::Request for ResetRequest {
249    const ACTION: &'static str = "Reset";
250    type Response = ResetResponse;
251}
252
253impl ocpp_core::Request for SecurityEventNotificationRequest {
254    const ACTION: &'static str = "SecurityEventNotification";
255    type Response = SecurityEventNotificationResponse;
256}
257
258impl ocpp_core::Request for SendLocalListRequest {
259    const ACTION: &'static str = "SendLocalList";
260    type Response = SendLocalListResponse;
261}
262
263impl ocpp_core::Request for SetChargingProfileRequest {
264    const ACTION: &'static str = "SetChargingProfile";
265    type Response = SetChargingProfileResponse;
266}
267
268impl ocpp_core::Request for SetDisplayMessageRequest {
269    const ACTION: &'static str = "SetDisplayMessage";
270    type Response = SetDisplayMessageResponse;
271}
272
273impl ocpp_core::Request for SetMonitoringBaseRequest {
274    const ACTION: &'static str = "SetMonitoringBase";
275    type Response = SetMonitoringBaseResponse;
276}
277
278impl ocpp_core::Request for SetMonitoringLevelRequest {
279    const ACTION: &'static str = "SetMonitoringLevel";
280    type Response = SetMonitoringLevelResponse;
281}
282
283impl ocpp_core::Request for SetNetworkProfileRequest {
284    const ACTION: &'static str = "SetNetworkProfile";
285    type Response = SetNetworkProfileResponse;
286}
287
288impl ocpp_core::Request for SetVariableMonitoringRequest {
289    const ACTION: &'static str = "SetVariableMonitoring";
290    type Response = SetVariableMonitoringResponse;
291}
292
293impl ocpp_core::Request for SetVariablesRequest {
294    const ACTION: &'static str = "SetVariables";
295    type Response = SetVariablesResponse;
296}
297
298impl ocpp_core::Request for SignCertificateRequest {
299    const ACTION: &'static str = "SignCertificate";
300    type Response = SignCertificateResponse;
301}
302
303impl ocpp_core::Request for StatusNotificationRequest {
304    const ACTION: &'static str = "StatusNotification";
305    type Response = StatusNotificationResponse;
306}
307
308impl ocpp_core::Request for TransactionEventRequest {
309    const ACTION: &'static str = "TransactionEvent";
310    type Response = TransactionEventResponse;
311}
312
313impl ocpp_core::Request for TriggerMessageRequest {
314    const ACTION: &'static str = "TriggerMessage";
315    type Response = TriggerMessageResponse;
316}
317
318impl ocpp_core::Request for UnlockConnectorRequest {
319    const ACTION: &'static str = "UnlockConnector";
320    type Response = UnlockConnectorResponse;
321}
322
323impl ocpp_core::Request for UnpublishFirmwareRequest {
324    const ACTION: &'static str = "UnpublishFirmware";
325    type Response = UnpublishFirmwareResponse;
326}
327
328impl ocpp_core::Request for UpdateFirmwareRequest {
329    const ACTION: &'static str = "UpdateFirmware";
330    type Response = UpdateFirmwareResponse;
331}
332
333/// Which side initiates a message.
334#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
335pub enum Direction {
336    /// Charging Station → CSMS.
337    StationToCsms,
338    /// CSMS → Charging Station.
339    CsmsToStation,
340    /// Either side.
341    Both,
342}
343
344/// All actions of this OCPP version.
345#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
346pub enum Action {
347    Authorize,
348    BootNotification,
349    CancelReservation,
350    CertificateSigned,
351    ChangeAvailability,
352    ClearCache,
353    ClearChargingProfile,
354    ClearDisplayMessage,
355    ClearVariableMonitoring,
356    ClearedChargingLimit,
357    CostUpdated,
358    CustomerInformation,
359    DataTransfer,
360    DeleteCertificate,
361    FirmwareStatusNotification,
362    Get15118EVCertificate,
363    GetBaseReport,
364    GetCertificateStatus,
365    GetChargingProfiles,
366    GetCompositeSchedule,
367    GetDisplayMessages,
368    GetInstalledCertificateIds,
369    GetLocalListVersion,
370    GetLog,
371    GetMonitoringReport,
372    GetReport,
373    GetTransactionStatus,
374    GetVariables,
375    Heartbeat,
376    InstallCertificate,
377    LogStatusNotification,
378    MeterValues,
379    NotifyChargingLimit,
380    NotifyCustomerInformation,
381    NotifyDisplayMessages,
382    NotifyEVChargingNeeds,
383    NotifyEVChargingSchedule,
384    NotifyEvent,
385    NotifyMonitoringReport,
386    NotifyReport,
387    PublishFirmware,
388    PublishFirmwareStatusNotification,
389    ReportChargingProfiles,
390    RequestStartTransaction,
391    RequestStopTransaction,
392    ReservationStatusUpdate,
393    ReserveNow,
394    Reset,
395    SecurityEventNotification,
396    SendLocalList,
397    SetChargingProfile,
398    SetDisplayMessage,
399    SetMonitoringBase,
400    SetMonitoringLevel,
401    SetNetworkProfile,
402    SetVariableMonitoring,
403    SetVariables,
404    SignCertificate,
405    StatusNotification,
406    TransactionEvent,
407    TriggerMessage,
408    UnlockConnector,
409    UnpublishFirmware,
410    UpdateFirmware,
411}
412
413impl Action {
414    pub const ALL: &'static [Action] = &[
415        Action::Authorize,
416        Action::BootNotification,
417        Action::CancelReservation,
418        Action::CertificateSigned,
419        Action::ChangeAvailability,
420        Action::ClearCache,
421        Action::ClearChargingProfile,
422        Action::ClearDisplayMessage,
423        Action::ClearVariableMonitoring,
424        Action::ClearedChargingLimit,
425        Action::CostUpdated,
426        Action::CustomerInformation,
427        Action::DataTransfer,
428        Action::DeleteCertificate,
429        Action::FirmwareStatusNotification,
430        Action::Get15118EVCertificate,
431        Action::GetBaseReport,
432        Action::GetCertificateStatus,
433        Action::GetChargingProfiles,
434        Action::GetCompositeSchedule,
435        Action::GetDisplayMessages,
436        Action::GetInstalledCertificateIds,
437        Action::GetLocalListVersion,
438        Action::GetLog,
439        Action::GetMonitoringReport,
440        Action::GetReport,
441        Action::GetTransactionStatus,
442        Action::GetVariables,
443        Action::Heartbeat,
444        Action::InstallCertificate,
445        Action::LogStatusNotification,
446        Action::MeterValues,
447        Action::NotifyChargingLimit,
448        Action::NotifyCustomerInformation,
449        Action::NotifyDisplayMessages,
450        Action::NotifyEVChargingNeeds,
451        Action::NotifyEVChargingSchedule,
452        Action::NotifyEvent,
453        Action::NotifyMonitoringReport,
454        Action::NotifyReport,
455        Action::PublishFirmware,
456        Action::PublishFirmwareStatusNotification,
457        Action::ReportChargingProfiles,
458        Action::RequestStartTransaction,
459        Action::RequestStopTransaction,
460        Action::ReservationStatusUpdate,
461        Action::ReserveNow,
462        Action::Reset,
463        Action::SecurityEventNotification,
464        Action::SendLocalList,
465        Action::SetChargingProfile,
466        Action::SetDisplayMessage,
467        Action::SetMonitoringBase,
468        Action::SetMonitoringLevel,
469        Action::SetNetworkProfile,
470        Action::SetVariableMonitoring,
471        Action::SetVariables,
472        Action::SignCertificate,
473        Action::StatusNotification,
474        Action::TransactionEvent,
475        Action::TriggerMessage,
476        Action::UnlockConnector,
477        Action::UnpublishFirmware,
478        Action::UpdateFirmware,
479    ];
480
481    pub const fn as_str(&self) -> &'static str {
482        match self {
483            Action::Authorize => "Authorize",
484            Action::BootNotification => "BootNotification",
485            Action::CancelReservation => "CancelReservation",
486            Action::CertificateSigned => "CertificateSigned",
487            Action::ChangeAvailability => "ChangeAvailability",
488            Action::ClearCache => "ClearCache",
489            Action::ClearChargingProfile => "ClearChargingProfile",
490            Action::ClearDisplayMessage => "ClearDisplayMessage",
491            Action::ClearVariableMonitoring => "ClearVariableMonitoring",
492            Action::ClearedChargingLimit => "ClearedChargingLimit",
493            Action::CostUpdated => "CostUpdated",
494            Action::CustomerInformation => "CustomerInformation",
495            Action::DataTransfer => "DataTransfer",
496            Action::DeleteCertificate => "DeleteCertificate",
497            Action::FirmwareStatusNotification => "FirmwareStatusNotification",
498            Action::Get15118EVCertificate => "Get15118EVCertificate",
499            Action::GetBaseReport => "GetBaseReport",
500            Action::GetCertificateStatus => "GetCertificateStatus",
501            Action::GetChargingProfiles => "GetChargingProfiles",
502            Action::GetCompositeSchedule => "GetCompositeSchedule",
503            Action::GetDisplayMessages => "GetDisplayMessages",
504            Action::GetInstalledCertificateIds => "GetInstalledCertificateIds",
505            Action::GetLocalListVersion => "GetLocalListVersion",
506            Action::GetLog => "GetLog",
507            Action::GetMonitoringReport => "GetMonitoringReport",
508            Action::GetReport => "GetReport",
509            Action::GetTransactionStatus => "GetTransactionStatus",
510            Action::GetVariables => "GetVariables",
511            Action::Heartbeat => "Heartbeat",
512            Action::InstallCertificate => "InstallCertificate",
513            Action::LogStatusNotification => "LogStatusNotification",
514            Action::MeterValues => "MeterValues",
515            Action::NotifyChargingLimit => "NotifyChargingLimit",
516            Action::NotifyCustomerInformation => "NotifyCustomerInformation",
517            Action::NotifyDisplayMessages => "NotifyDisplayMessages",
518            Action::NotifyEVChargingNeeds => "NotifyEVChargingNeeds",
519            Action::NotifyEVChargingSchedule => "NotifyEVChargingSchedule",
520            Action::NotifyEvent => "NotifyEvent",
521            Action::NotifyMonitoringReport => "NotifyMonitoringReport",
522            Action::NotifyReport => "NotifyReport",
523            Action::PublishFirmware => "PublishFirmware",
524            Action::PublishFirmwareStatusNotification => "PublishFirmwareStatusNotification",
525            Action::ReportChargingProfiles => "ReportChargingProfiles",
526            Action::RequestStartTransaction => "RequestStartTransaction",
527            Action::RequestStopTransaction => "RequestStopTransaction",
528            Action::ReservationStatusUpdate => "ReservationStatusUpdate",
529            Action::ReserveNow => "ReserveNow",
530            Action::Reset => "Reset",
531            Action::SecurityEventNotification => "SecurityEventNotification",
532            Action::SendLocalList => "SendLocalList",
533            Action::SetChargingProfile => "SetChargingProfile",
534            Action::SetDisplayMessage => "SetDisplayMessage",
535            Action::SetMonitoringBase => "SetMonitoringBase",
536            Action::SetMonitoringLevel => "SetMonitoringLevel",
537            Action::SetNetworkProfile => "SetNetworkProfile",
538            Action::SetVariableMonitoring => "SetVariableMonitoring",
539            Action::SetVariables => "SetVariables",
540            Action::SignCertificate => "SignCertificate",
541            Action::StatusNotification => "StatusNotification",
542            Action::TransactionEvent => "TransactionEvent",
543            Action::TriggerMessage => "TriggerMessage",
544            Action::UnlockConnector => "UnlockConnector",
545            Action::UnpublishFirmware => "UnpublishFirmware",
546            Action::UpdateFirmware => "UpdateFirmware",
547        }
548    }
549
550    pub fn from_name(s: &str) -> Option<Action> {
551        match s {
552            "Authorize" => Some(Action::Authorize),
553            "BootNotification" => Some(Action::BootNotification),
554            "CancelReservation" => Some(Action::CancelReservation),
555            "CertificateSigned" => Some(Action::CertificateSigned),
556            "ChangeAvailability" => Some(Action::ChangeAvailability),
557            "ClearCache" => Some(Action::ClearCache),
558            "ClearChargingProfile" => Some(Action::ClearChargingProfile),
559            "ClearDisplayMessage" => Some(Action::ClearDisplayMessage),
560            "ClearVariableMonitoring" => Some(Action::ClearVariableMonitoring),
561            "ClearedChargingLimit" => Some(Action::ClearedChargingLimit),
562            "CostUpdated" => Some(Action::CostUpdated),
563            "CustomerInformation" => Some(Action::CustomerInformation),
564            "DataTransfer" => Some(Action::DataTransfer),
565            "DeleteCertificate" => Some(Action::DeleteCertificate),
566            "FirmwareStatusNotification" => Some(Action::FirmwareStatusNotification),
567            "Get15118EVCertificate" => Some(Action::Get15118EVCertificate),
568            "GetBaseReport" => Some(Action::GetBaseReport),
569            "GetCertificateStatus" => Some(Action::GetCertificateStatus),
570            "GetChargingProfiles" => Some(Action::GetChargingProfiles),
571            "GetCompositeSchedule" => Some(Action::GetCompositeSchedule),
572            "GetDisplayMessages" => Some(Action::GetDisplayMessages),
573            "GetInstalledCertificateIds" => Some(Action::GetInstalledCertificateIds),
574            "GetLocalListVersion" => Some(Action::GetLocalListVersion),
575            "GetLog" => Some(Action::GetLog),
576            "GetMonitoringReport" => Some(Action::GetMonitoringReport),
577            "GetReport" => Some(Action::GetReport),
578            "GetTransactionStatus" => Some(Action::GetTransactionStatus),
579            "GetVariables" => Some(Action::GetVariables),
580            "Heartbeat" => Some(Action::Heartbeat),
581            "InstallCertificate" => Some(Action::InstallCertificate),
582            "LogStatusNotification" => Some(Action::LogStatusNotification),
583            "MeterValues" => Some(Action::MeterValues),
584            "NotifyChargingLimit" => Some(Action::NotifyChargingLimit),
585            "NotifyCustomerInformation" => Some(Action::NotifyCustomerInformation),
586            "NotifyDisplayMessages" => Some(Action::NotifyDisplayMessages),
587            "NotifyEVChargingNeeds" => Some(Action::NotifyEVChargingNeeds),
588            "NotifyEVChargingSchedule" => Some(Action::NotifyEVChargingSchedule),
589            "NotifyEvent" => Some(Action::NotifyEvent),
590            "NotifyMonitoringReport" => Some(Action::NotifyMonitoringReport),
591            "NotifyReport" => Some(Action::NotifyReport),
592            "PublishFirmware" => Some(Action::PublishFirmware),
593            "PublishFirmwareStatusNotification" => Some(Action::PublishFirmwareStatusNotification),
594            "ReportChargingProfiles" => Some(Action::ReportChargingProfiles),
595            "RequestStartTransaction" => Some(Action::RequestStartTransaction),
596            "RequestStopTransaction" => Some(Action::RequestStopTransaction),
597            "ReservationStatusUpdate" => Some(Action::ReservationStatusUpdate),
598            "ReserveNow" => Some(Action::ReserveNow),
599            "Reset" => Some(Action::Reset),
600            "SecurityEventNotification" => Some(Action::SecurityEventNotification),
601            "SendLocalList" => Some(Action::SendLocalList),
602            "SetChargingProfile" => Some(Action::SetChargingProfile),
603            "SetDisplayMessage" => Some(Action::SetDisplayMessage),
604            "SetMonitoringBase" => Some(Action::SetMonitoringBase),
605            "SetMonitoringLevel" => Some(Action::SetMonitoringLevel),
606            "SetNetworkProfile" => Some(Action::SetNetworkProfile),
607            "SetVariableMonitoring" => Some(Action::SetVariableMonitoring),
608            "SetVariables" => Some(Action::SetVariables),
609            "SignCertificate" => Some(Action::SignCertificate),
610            "StatusNotification" => Some(Action::StatusNotification),
611            "TransactionEvent" => Some(Action::TransactionEvent),
612            "TriggerMessage" => Some(Action::TriggerMessage),
613            "UnlockConnector" => Some(Action::UnlockConnector),
614            "UnpublishFirmware" => Some(Action::UnpublishFirmware),
615            "UpdateFirmware" => Some(Action::UpdateFirmware),
616            _ => None,
617        }
618    }
619
620    pub const fn direction(&self) -> Direction {
621        match self {
622            Action::Authorize => Direction::StationToCsms,
623            Action::BootNotification => Direction::StationToCsms,
624            Action::CancelReservation => Direction::CsmsToStation,
625            Action::CertificateSigned => Direction::CsmsToStation,
626            Action::ChangeAvailability => Direction::CsmsToStation,
627            Action::ClearCache => Direction::CsmsToStation,
628            Action::ClearChargingProfile => Direction::CsmsToStation,
629            Action::ClearDisplayMessage => Direction::CsmsToStation,
630            Action::ClearVariableMonitoring => Direction::CsmsToStation,
631            Action::ClearedChargingLimit => Direction::StationToCsms,
632            Action::CostUpdated => Direction::CsmsToStation,
633            Action::CustomerInformation => Direction::CsmsToStation,
634            Action::DataTransfer => Direction::Both,
635            Action::DeleteCertificate => Direction::CsmsToStation,
636            Action::FirmwareStatusNotification => Direction::StationToCsms,
637            Action::Get15118EVCertificate => Direction::StationToCsms,
638            Action::GetBaseReport => Direction::CsmsToStation,
639            Action::GetCertificateStatus => Direction::StationToCsms,
640            Action::GetChargingProfiles => Direction::CsmsToStation,
641            Action::GetCompositeSchedule => Direction::CsmsToStation,
642            Action::GetDisplayMessages => Direction::CsmsToStation,
643            Action::GetInstalledCertificateIds => Direction::CsmsToStation,
644            Action::GetLocalListVersion => Direction::CsmsToStation,
645            Action::GetLog => Direction::CsmsToStation,
646            Action::GetMonitoringReport => Direction::CsmsToStation,
647            Action::GetReport => Direction::CsmsToStation,
648            Action::GetTransactionStatus => Direction::CsmsToStation,
649            Action::GetVariables => Direction::CsmsToStation,
650            Action::Heartbeat => Direction::StationToCsms,
651            Action::InstallCertificate => Direction::CsmsToStation,
652            Action::LogStatusNotification => Direction::StationToCsms,
653            Action::MeterValues => Direction::StationToCsms,
654            Action::NotifyChargingLimit => Direction::StationToCsms,
655            Action::NotifyCustomerInformation => Direction::StationToCsms,
656            Action::NotifyDisplayMessages => Direction::StationToCsms,
657            Action::NotifyEVChargingNeeds => Direction::StationToCsms,
658            Action::NotifyEVChargingSchedule => Direction::StationToCsms,
659            Action::NotifyEvent => Direction::StationToCsms,
660            Action::NotifyMonitoringReport => Direction::StationToCsms,
661            Action::NotifyReport => Direction::StationToCsms,
662            Action::PublishFirmware => Direction::CsmsToStation,
663            Action::PublishFirmwareStatusNotification => Direction::StationToCsms,
664            Action::ReportChargingProfiles => Direction::StationToCsms,
665            Action::RequestStartTransaction => Direction::CsmsToStation,
666            Action::RequestStopTransaction => Direction::CsmsToStation,
667            Action::ReservationStatusUpdate => Direction::StationToCsms,
668            Action::ReserveNow => Direction::CsmsToStation,
669            Action::Reset => Direction::CsmsToStation,
670            Action::SecurityEventNotification => Direction::StationToCsms,
671            Action::SendLocalList => Direction::CsmsToStation,
672            Action::SetChargingProfile => Direction::CsmsToStation,
673            Action::SetDisplayMessage => Direction::CsmsToStation,
674            Action::SetMonitoringBase => Direction::CsmsToStation,
675            Action::SetMonitoringLevel => Direction::CsmsToStation,
676            Action::SetNetworkProfile => Direction::CsmsToStation,
677            Action::SetVariableMonitoring => Direction::CsmsToStation,
678            Action::SetVariables => Direction::CsmsToStation,
679            Action::SignCertificate => Direction::StationToCsms,
680            Action::StatusNotification => Direction::StationToCsms,
681            Action::TransactionEvent => Direction::StationToCsms,
682            Action::TriggerMessage => Direction::CsmsToStation,
683            Action::UnlockConnector => Direction::CsmsToStation,
684            Action::UnpublishFirmware => Direction::CsmsToStation,
685            Action::UpdateFirmware => Direction::CsmsToStation,
686        }
687    }
688
689    /// `true` for unconfirmed SEND messages (OCPP 2.1), which have no response.
690    pub const fn is_send(&self) -> bool {
691        false
692    }
693}
694
695impl std::fmt::Display for Action {
696    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
697        f.write_str(self.as_str())
698    }
699}
700
701/// Why an inbound message could not be decoded.
702#[derive(Debug, Clone, PartialEq)]
703pub enum DecodeError {
704    /// The action is not part of this OCPP version.
705    UnknownAction(String),
706    /// The action exists but is not sent in this direction.
707    WrongDirection(Action),
708    /// The payload violates the message definition.
709    Invalid(Violation),
710}
711
712impl std::fmt::Display for DecodeError {
713    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
714        match self {
715            DecodeError::UnknownAction(a) => write!(f, "unknown action '{a}'"),
716            DecodeError::WrongDirection(a) => {
717                write!(f, "action '{a}' is not accepted in this direction")
718            }
719            DecodeError::Invalid(v) => write!(f, "{v}"),
720        }
721    }
722}
723
724impl std::error::Error for DecodeError {}
725
726/// Requests a Charging Station may send to the CSMS.
727#[derive(Debug, Clone, PartialEq)]
728pub enum StationCall {
729    Authorize(AuthorizeRequest),
730    BootNotification(BootNotificationRequest),
731    ClearedChargingLimit(ClearedChargingLimitRequest),
732    DataTransfer(DataTransferRequest),
733    FirmwareStatusNotification(FirmwareStatusNotificationRequest),
734    Get15118EVCertificate(Get15118EVCertificateRequest),
735    GetCertificateStatus(GetCertificateStatusRequest),
736    Heartbeat(HeartbeatRequest),
737    LogStatusNotification(LogStatusNotificationRequest),
738    MeterValues(MeterValuesRequest),
739    NotifyChargingLimit(NotifyChargingLimitRequest),
740    NotifyCustomerInformation(NotifyCustomerInformationRequest),
741    NotifyDisplayMessages(NotifyDisplayMessagesRequest),
742    NotifyEVChargingNeeds(NotifyEVChargingNeedsRequest),
743    NotifyEVChargingSchedule(NotifyEVChargingScheduleRequest),
744    NotifyEvent(NotifyEventRequest),
745    NotifyMonitoringReport(NotifyMonitoringReportRequest),
746    NotifyReport(NotifyReportRequest),
747    PublishFirmwareStatusNotification(PublishFirmwareStatusNotificationRequest),
748    ReportChargingProfiles(ReportChargingProfilesRequest),
749    ReservationStatusUpdate(ReservationStatusUpdateRequest),
750    SecurityEventNotification(SecurityEventNotificationRequest),
751    SignCertificate(SignCertificateRequest),
752    StatusNotification(StatusNotificationRequest),
753    TransactionEvent(TransactionEventRequest),
754}
755
756impl StationCall {
757    pub const fn action(&self) -> Action {
758        match self {
759            StationCall::Authorize(_) => Action::Authorize,
760            StationCall::BootNotification(_) => Action::BootNotification,
761            StationCall::ClearedChargingLimit(_) => Action::ClearedChargingLimit,
762            StationCall::DataTransfer(_) => Action::DataTransfer,
763            StationCall::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
764            StationCall::Get15118EVCertificate(_) => Action::Get15118EVCertificate,
765            StationCall::GetCertificateStatus(_) => Action::GetCertificateStatus,
766            StationCall::Heartbeat(_) => Action::Heartbeat,
767            StationCall::LogStatusNotification(_) => Action::LogStatusNotification,
768            StationCall::MeterValues(_) => Action::MeterValues,
769            StationCall::NotifyChargingLimit(_) => Action::NotifyChargingLimit,
770            StationCall::NotifyCustomerInformation(_) => Action::NotifyCustomerInformation,
771            StationCall::NotifyDisplayMessages(_) => Action::NotifyDisplayMessages,
772            StationCall::NotifyEVChargingNeeds(_) => Action::NotifyEVChargingNeeds,
773            StationCall::NotifyEVChargingSchedule(_) => Action::NotifyEVChargingSchedule,
774            StationCall::NotifyEvent(_) => Action::NotifyEvent,
775            StationCall::NotifyMonitoringReport(_) => Action::NotifyMonitoringReport,
776            StationCall::NotifyReport(_) => Action::NotifyReport,
777            StationCall::PublishFirmwareStatusNotification(_) => {
778                Action::PublishFirmwareStatusNotification
779            }
780            StationCall::ReportChargingProfiles(_) => Action::ReportChargingProfiles,
781            StationCall::ReservationStatusUpdate(_) => Action::ReservationStatusUpdate,
782            StationCall::SecurityEventNotification(_) => Action::SecurityEventNotification,
783            StationCall::SignCertificate(_) => Action::SignCertificate,
784            StationCall::StatusNotification(_) => Action::StatusNotification,
785            StationCall::TransactionEvent(_) => Action::TransactionEvent,
786        }
787    }
788
789    /// Decodes and validates the payload of a CALL.
790    pub fn decode(action: &str, payload: &str) -> Result<Self, DecodeError> {
791        let a = Action::from_name(action)
792            .ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
793        match a {
794            Action::Authorize => ocpp_core::decode_payload(payload)
795                .map(StationCall::Authorize)
796                .map_err(DecodeError::Invalid),
797            Action::BootNotification => ocpp_core::decode_payload(payload)
798                .map(StationCall::BootNotification)
799                .map_err(DecodeError::Invalid),
800            Action::ClearedChargingLimit => ocpp_core::decode_payload(payload)
801                .map(StationCall::ClearedChargingLimit)
802                .map_err(DecodeError::Invalid),
803            Action::DataTransfer => ocpp_core::decode_payload(payload)
804                .map(StationCall::DataTransfer)
805                .map_err(DecodeError::Invalid),
806            Action::FirmwareStatusNotification => ocpp_core::decode_payload(payload)
807                .map(StationCall::FirmwareStatusNotification)
808                .map_err(DecodeError::Invalid),
809            Action::Get15118EVCertificate => ocpp_core::decode_payload(payload)
810                .map(StationCall::Get15118EVCertificate)
811                .map_err(DecodeError::Invalid),
812            Action::GetCertificateStatus => ocpp_core::decode_payload(payload)
813                .map(StationCall::GetCertificateStatus)
814                .map_err(DecodeError::Invalid),
815            Action::Heartbeat => ocpp_core::decode_payload(payload)
816                .map(StationCall::Heartbeat)
817                .map_err(DecodeError::Invalid),
818            Action::LogStatusNotification => ocpp_core::decode_payload(payload)
819                .map(StationCall::LogStatusNotification)
820                .map_err(DecodeError::Invalid),
821            Action::MeterValues => ocpp_core::decode_payload(payload)
822                .map(StationCall::MeterValues)
823                .map_err(DecodeError::Invalid),
824            Action::NotifyChargingLimit => ocpp_core::decode_payload(payload)
825                .map(StationCall::NotifyChargingLimit)
826                .map_err(DecodeError::Invalid),
827            Action::NotifyCustomerInformation => ocpp_core::decode_payload(payload)
828                .map(StationCall::NotifyCustomerInformation)
829                .map_err(DecodeError::Invalid),
830            Action::NotifyDisplayMessages => ocpp_core::decode_payload(payload)
831                .map(StationCall::NotifyDisplayMessages)
832                .map_err(DecodeError::Invalid),
833            Action::NotifyEVChargingNeeds => ocpp_core::decode_payload(payload)
834                .map(StationCall::NotifyEVChargingNeeds)
835                .map_err(DecodeError::Invalid),
836            Action::NotifyEVChargingSchedule => ocpp_core::decode_payload(payload)
837                .map(StationCall::NotifyEVChargingSchedule)
838                .map_err(DecodeError::Invalid),
839            Action::NotifyEvent => ocpp_core::decode_payload(payload)
840                .map(StationCall::NotifyEvent)
841                .map_err(DecodeError::Invalid),
842            Action::NotifyMonitoringReport => ocpp_core::decode_payload(payload)
843                .map(StationCall::NotifyMonitoringReport)
844                .map_err(DecodeError::Invalid),
845            Action::NotifyReport => ocpp_core::decode_payload(payload)
846                .map(StationCall::NotifyReport)
847                .map_err(DecodeError::Invalid),
848            Action::PublishFirmwareStatusNotification => ocpp_core::decode_payload(payload)
849                .map(StationCall::PublishFirmwareStatusNotification)
850                .map_err(DecodeError::Invalid),
851            Action::ReportChargingProfiles => ocpp_core::decode_payload(payload)
852                .map(StationCall::ReportChargingProfiles)
853                .map_err(DecodeError::Invalid),
854            Action::ReservationStatusUpdate => ocpp_core::decode_payload(payload)
855                .map(StationCall::ReservationStatusUpdate)
856                .map_err(DecodeError::Invalid),
857            Action::SecurityEventNotification => ocpp_core::decode_payload(payload)
858                .map(StationCall::SecurityEventNotification)
859                .map_err(DecodeError::Invalid),
860            Action::SignCertificate => ocpp_core::decode_payload(payload)
861                .map(StationCall::SignCertificate)
862                .map_err(DecodeError::Invalid),
863            Action::StatusNotification => ocpp_core::decode_payload(payload)
864                .map(StationCall::StatusNotification)
865                .map_err(DecodeError::Invalid),
866            Action::TransactionEvent => ocpp_core::decode_payload(payload)
867                .map(StationCall::TransactionEvent)
868                .map_err(DecodeError::Invalid),
869            #[allow(unreachable_patterns)]
870            other => Err(DecodeError::WrongDirection(other)),
871        }
872    }
873
874    /// Decodes and validates a request given as a JSON value (e.g. from the HTTP API).
875    pub fn from_value(action: &str, payload: serde_json::Value) -> Result<Self, DecodeError> {
876        let a = Action::from_name(action)
877            .ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
878        match a {
879            Action::Authorize => ocpp_core::decode_value(payload)
880                .map(StationCall::Authorize)
881                .map_err(DecodeError::Invalid),
882            Action::BootNotification => ocpp_core::decode_value(payload)
883                .map(StationCall::BootNotification)
884                .map_err(DecodeError::Invalid),
885            Action::ClearedChargingLimit => ocpp_core::decode_value(payload)
886                .map(StationCall::ClearedChargingLimit)
887                .map_err(DecodeError::Invalid),
888            Action::DataTransfer => ocpp_core::decode_value(payload)
889                .map(StationCall::DataTransfer)
890                .map_err(DecodeError::Invalid),
891            Action::FirmwareStatusNotification => ocpp_core::decode_value(payload)
892                .map(StationCall::FirmwareStatusNotification)
893                .map_err(DecodeError::Invalid),
894            Action::Get15118EVCertificate => ocpp_core::decode_value(payload)
895                .map(StationCall::Get15118EVCertificate)
896                .map_err(DecodeError::Invalid),
897            Action::GetCertificateStatus => ocpp_core::decode_value(payload)
898                .map(StationCall::GetCertificateStatus)
899                .map_err(DecodeError::Invalid),
900            Action::Heartbeat => ocpp_core::decode_value(payload)
901                .map(StationCall::Heartbeat)
902                .map_err(DecodeError::Invalid),
903            Action::LogStatusNotification => ocpp_core::decode_value(payload)
904                .map(StationCall::LogStatusNotification)
905                .map_err(DecodeError::Invalid),
906            Action::MeterValues => ocpp_core::decode_value(payload)
907                .map(StationCall::MeterValues)
908                .map_err(DecodeError::Invalid),
909            Action::NotifyChargingLimit => ocpp_core::decode_value(payload)
910                .map(StationCall::NotifyChargingLimit)
911                .map_err(DecodeError::Invalid),
912            Action::NotifyCustomerInformation => ocpp_core::decode_value(payload)
913                .map(StationCall::NotifyCustomerInformation)
914                .map_err(DecodeError::Invalid),
915            Action::NotifyDisplayMessages => ocpp_core::decode_value(payload)
916                .map(StationCall::NotifyDisplayMessages)
917                .map_err(DecodeError::Invalid),
918            Action::NotifyEVChargingNeeds => ocpp_core::decode_value(payload)
919                .map(StationCall::NotifyEVChargingNeeds)
920                .map_err(DecodeError::Invalid),
921            Action::NotifyEVChargingSchedule => ocpp_core::decode_value(payload)
922                .map(StationCall::NotifyEVChargingSchedule)
923                .map_err(DecodeError::Invalid),
924            Action::NotifyEvent => ocpp_core::decode_value(payload)
925                .map(StationCall::NotifyEvent)
926                .map_err(DecodeError::Invalid),
927            Action::NotifyMonitoringReport => ocpp_core::decode_value(payload)
928                .map(StationCall::NotifyMonitoringReport)
929                .map_err(DecodeError::Invalid),
930            Action::NotifyReport => ocpp_core::decode_value(payload)
931                .map(StationCall::NotifyReport)
932                .map_err(DecodeError::Invalid),
933            Action::PublishFirmwareStatusNotification => ocpp_core::decode_value(payload)
934                .map(StationCall::PublishFirmwareStatusNotification)
935                .map_err(DecodeError::Invalid),
936            Action::ReportChargingProfiles => ocpp_core::decode_value(payload)
937                .map(StationCall::ReportChargingProfiles)
938                .map_err(DecodeError::Invalid),
939            Action::ReservationStatusUpdate => ocpp_core::decode_value(payload)
940                .map(StationCall::ReservationStatusUpdate)
941                .map_err(DecodeError::Invalid),
942            Action::SecurityEventNotification => ocpp_core::decode_value(payload)
943                .map(StationCall::SecurityEventNotification)
944                .map_err(DecodeError::Invalid),
945            Action::SignCertificate => ocpp_core::decode_value(payload)
946                .map(StationCall::SignCertificate)
947                .map_err(DecodeError::Invalid),
948            Action::StatusNotification => ocpp_core::decode_value(payload)
949                .map(StationCall::StatusNotification)
950                .map_err(DecodeError::Invalid),
951            Action::TransactionEvent => ocpp_core::decode_value(payload)
952                .map(StationCall::TransactionEvent)
953                .map_err(DecodeError::Invalid),
954            #[allow(unreachable_patterns)]
955            other => Err(DecodeError::WrongDirection(other)),
956        }
957    }
958
959    /// Serializes the request payload.
960    pub fn to_payload(&self) -> serde_json::Value {
961        match self {
962            StationCall::Authorize(r) => serde_json::to_value(r).expect("serializable"),
963            StationCall::BootNotification(r) => serde_json::to_value(r).expect("serializable"),
964            StationCall::ClearedChargingLimit(r) => serde_json::to_value(r).expect("serializable"),
965            StationCall::DataTransfer(r) => serde_json::to_value(r).expect("serializable"),
966            StationCall::FirmwareStatusNotification(r) => {
967                serde_json::to_value(r).expect("serializable")
968            }
969            StationCall::Get15118EVCertificate(r) => serde_json::to_value(r).expect("serializable"),
970            StationCall::GetCertificateStatus(r) => serde_json::to_value(r).expect("serializable"),
971            StationCall::Heartbeat(r) => serde_json::to_value(r).expect("serializable"),
972            StationCall::LogStatusNotification(r) => serde_json::to_value(r).expect("serializable"),
973            StationCall::MeterValues(r) => serde_json::to_value(r).expect("serializable"),
974            StationCall::NotifyChargingLimit(r) => serde_json::to_value(r).expect("serializable"),
975            StationCall::NotifyCustomerInformation(r) => {
976                serde_json::to_value(r).expect("serializable")
977            }
978            StationCall::NotifyDisplayMessages(r) => serde_json::to_value(r).expect("serializable"),
979            StationCall::NotifyEVChargingNeeds(r) => serde_json::to_value(r).expect("serializable"),
980            StationCall::NotifyEVChargingSchedule(r) => {
981                serde_json::to_value(r).expect("serializable")
982            }
983            StationCall::NotifyEvent(r) => serde_json::to_value(r).expect("serializable"),
984            StationCall::NotifyMonitoringReport(r) => {
985                serde_json::to_value(r).expect("serializable")
986            }
987            StationCall::NotifyReport(r) => serde_json::to_value(r).expect("serializable"),
988            StationCall::PublishFirmwareStatusNotification(r) => {
989                serde_json::to_value(r).expect("serializable")
990            }
991            StationCall::ReportChargingProfiles(r) => {
992                serde_json::to_value(r).expect("serializable")
993            }
994            StationCall::ReservationStatusUpdate(r) => {
995                serde_json::to_value(r).expect("serializable")
996            }
997            StationCall::SecurityEventNotification(r) => {
998                serde_json::to_value(r).expect("serializable")
999            }
1000            StationCall::SignCertificate(r) => serde_json::to_value(r).expect("serializable"),
1001            StationCall::StatusNotification(r) => serde_json::to_value(r).expect("serializable"),
1002            StationCall::TransactionEvent(r) => serde_json::to_value(r).expect("serializable"),
1003        }
1004    }
1005}
1006
1007/// Requests the CSMS may send to a Charging Station.
1008#[derive(Debug, Clone, PartialEq)]
1009pub enum CsmsCall {
1010    CancelReservation(CancelReservationRequest),
1011    CertificateSigned(CertificateSignedRequest),
1012    ChangeAvailability(ChangeAvailabilityRequest),
1013    ClearCache(ClearCacheRequest),
1014    ClearChargingProfile(ClearChargingProfileRequest),
1015    ClearDisplayMessage(ClearDisplayMessageRequest),
1016    ClearVariableMonitoring(ClearVariableMonitoringRequest),
1017    CostUpdated(CostUpdatedRequest),
1018    CustomerInformation(CustomerInformationRequest),
1019    DataTransfer(DataTransferRequest),
1020    DeleteCertificate(DeleteCertificateRequest),
1021    GetBaseReport(GetBaseReportRequest),
1022    GetChargingProfiles(GetChargingProfilesRequest),
1023    GetCompositeSchedule(GetCompositeScheduleRequest),
1024    GetDisplayMessages(GetDisplayMessagesRequest),
1025    GetInstalledCertificateIds(GetInstalledCertificateIdsRequest),
1026    GetLocalListVersion(GetLocalListVersionRequest),
1027    GetLog(GetLogRequest),
1028    GetMonitoringReport(GetMonitoringReportRequest),
1029    GetReport(GetReportRequest),
1030    GetTransactionStatus(GetTransactionStatusRequest),
1031    GetVariables(GetVariablesRequest),
1032    InstallCertificate(InstallCertificateRequest),
1033    PublishFirmware(PublishFirmwareRequest),
1034    RequestStartTransaction(RequestStartTransactionRequest),
1035    RequestStopTransaction(RequestStopTransactionRequest),
1036    ReserveNow(ReserveNowRequest),
1037    Reset(ResetRequest),
1038    SendLocalList(SendLocalListRequest),
1039    SetChargingProfile(SetChargingProfileRequest),
1040    SetDisplayMessage(SetDisplayMessageRequest),
1041    SetMonitoringBase(SetMonitoringBaseRequest),
1042    SetMonitoringLevel(SetMonitoringLevelRequest),
1043    SetNetworkProfile(SetNetworkProfileRequest),
1044    SetVariableMonitoring(SetVariableMonitoringRequest),
1045    SetVariables(SetVariablesRequest),
1046    TriggerMessage(TriggerMessageRequest),
1047    UnlockConnector(UnlockConnectorRequest),
1048    UnpublishFirmware(UnpublishFirmwareRequest),
1049    UpdateFirmware(UpdateFirmwareRequest),
1050}
1051
1052impl CsmsCall {
1053    pub const fn action(&self) -> Action {
1054        match self {
1055            CsmsCall::CancelReservation(_) => Action::CancelReservation,
1056            CsmsCall::CertificateSigned(_) => Action::CertificateSigned,
1057            CsmsCall::ChangeAvailability(_) => Action::ChangeAvailability,
1058            CsmsCall::ClearCache(_) => Action::ClearCache,
1059            CsmsCall::ClearChargingProfile(_) => Action::ClearChargingProfile,
1060            CsmsCall::ClearDisplayMessage(_) => Action::ClearDisplayMessage,
1061            CsmsCall::ClearVariableMonitoring(_) => Action::ClearVariableMonitoring,
1062            CsmsCall::CostUpdated(_) => Action::CostUpdated,
1063            CsmsCall::CustomerInformation(_) => Action::CustomerInformation,
1064            CsmsCall::DataTransfer(_) => Action::DataTransfer,
1065            CsmsCall::DeleteCertificate(_) => Action::DeleteCertificate,
1066            CsmsCall::GetBaseReport(_) => Action::GetBaseReport,
1067            CsmsCall::GetChargingProfiles(_) => Action::GetChargingProfiles,
1068            CsmsCall::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
1069            CsmsCall::GetDisplayMessages(_) => Action::GetDisplayMessages,
1070            CsmsCall::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
1071            CsmsCall::GetLocalListVersion(_) => Action::GetLocalListVersion,
1072            CsmsCall::GetLog(_) => Action::GetLog,
1073            CsmsCall::GetMonitoringReport(_) => Action::GetMonitoringReport,
1074            CsmsCall::GetReport(_) => Action::GetReport,
1075            CsmsCall::GetTransactionStatus(_) => Action::GetTransactionStatus,
1076            CsmsCall::GetVariables(_) => Action::GetVariables,
1077            CsmsCall::InstallCertificate(_) => Action::InstallCertificate,
1078            CsmsCall::PublishFirmware(_) => Action::PublishFirmware,
1079            CsmsCall::RequestStartTransaction(_) => Action::RequestStartTransaction,
1080            CsmsCall::RequestStopTransaction(_) => Action::RequestStopTransaction,
1081            CsmsCall::ReserveNow(_) => Action::ReserveNow,
1082            CsmsCall::Reset(_) => Action::Reset,
1083            CsmsCall::SendLocalList(_) => Action::SendLocalList,
1084            CsmsCall::SetChargingProfile(_) => Action::SetChargingProfile,
1085            CsmsCall::SetDisplayMessage(_) => Action::SetDisplayMessage,
1086            CsmsCall::SetMonitoringBase(_) => Action::SetMonitoringBase,
1087            CsmsCall::SetMonitoringLevel(_) => Action::SetMonitoringLevel,
1088            CsmsCall::SetNetworkProfile(_) => Action::SetNetworkProfile,
1089            CsmsCall::SetVariableMonitoring(_) => Action::SetVariableMonitoring,
1090            CsmsCall::SetVariables(_) => Action::SetVariables,
1091            CsmsCall::TriggerMessage(_) => Action::TriggerMessage,
1092            CsmsCall::UnlockConnector(_) => Action::UnlockConnector,
1093            CsmsCall::UnpublishFirmware(_) => Action::UnpublishFirmware,
1094            CsmsCall::UpdateFirmware(_) => Action::UpdateFirmware,
1095        }
1096    }
1097
1098    /// Decodes and validates the payload of a CALL.
1099    pub fn decode(action: &str, payload: &str) -> Result<Self, DecodeError> {
1100        let a = Action::from_name(action)
1101            .ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
1102        match a {
1103            Action::CancelReservation => ocpp_core::decode_payload(payload)
1104                .map(CsmsCall::CancelReservation)
1105                .map_err(DecodeError::Invalid),
1106            Action::CertificateSigned => ocpp_core::decode_payload(payload)
1107                .map(CsmsCall::CertificateSigned)
1108                .map_err(DecodeError::Invalid),
1109            Action::ChangeAvailability => ocpp_core::decode_payload(payload)
1110                .map(CsmsCall::ChangeAvailability)
1111                .map_err(DecodeError::Invalid),
1112            Action::ClearCache => ocpp_core::decode_payload(payload)
1113                .map(CsmsCall::ClearCache)
1114                .map_err(DecodeError::Invalid),
1115            Action::ClearChargingProfile => ocpp_core::decode_payload(payload)
1116                .map(CsmsCall::ClearChargingProfile)
1117                .map_err(DecodeError::Invalid),
1118            Action::ClearDisplayMessage => ocpp_core::decode_payload(payload)
1119                .map(CsmsCall::ClearDisplayMessage)
1120                .map_err(DecodeError::Invalid),
1121            Action::ClearVariableMonitoring => ocpp_core::decode_payload(payload)
1122                .map(CsmsCall::ClearVariableMonitoring)
1123                .map_err(DecodeError::Invalid),
1124            Action::CostUpdated => ocpp_core::decode_payload(payload)
1125                .map(CsmsCall::CostUpdated)
1126                .map_err(DecodeError::Invalid),
1127            Action::CustomerInformation => ocpp_core::decode_payload(payload)
1128                .map(CsmsCall::CustomerInformation)
1129                .map_err(DecodeError::Invalid),
1130            Action::DataTransfer => ocpp_core::decode_payload(payload)
1131                .map(CsmsCall::DataTransfer)
1132                .map_err(DecodeError::Invalid),
1133            Action::DeleteCertificate => ocpp_core::decode_payload(payload)
1134                .map(CsmsCall::DeleteCertificate)
1135                .map_err(DecodeError::Invalid),
1136            Action::GetBaseReport => ocpp_core::decode_payload(payload)
1137                .map(CsmsCall::GetBaseReport)
1138                .map_err(DecodeError::Invalid),
1139            Action::GetChargingProfiles => ocpp_core::decode_payload(payload)
1140                .map(CsmsCall::GetChargingProfiles)
1141                .map_err(DecodeError::Invalid),
1142            Action::GetCompositeSchedule => ocpp_core::decode_payload(payload)
1143                .map(CsmsCall::GetCompositeSchedule)
1144                .map_err(DecodeError::Invalid),
1145            Action::GetDisplayMessages => ocpp_core::decode_payload(payload)
1146                .map(CsmsCall::GetDisplayMessages)
1147                .map_err(DecodeError::Invalid),
1148            Action::GetInstalledCertificateIds => ocpp_core::decode_payload(payload)
1149                .map(CsmsCall::GetInstalledCertificateIds)
1150                .map_err(DecodeError::Invalid),
1151            Action::GetLocalListVersion => ocpp_core::decode_payload(payload)
1152                .map(CsmsCall::GetLocalListVersion)
1153                .map_err(DecodeError::Invalid),
1154            Action::GetLog => ocpp_core::decode_payload(payload)
1155                .map(CsmsCall::GetLog)
1156                .map_err(DecodeError::Invalid),
1157            Action::GetMonitoringReport => ocpp_core::decode_payload(payload)
1158                .map(CsmsCall::GetMonitoringReport)
1159                .map_err(DecodeError::Invalid),
1160            Action::GetReport => ocpp_core::decode_payload(payload)
1161                .map(CsmsCall::GetReport)
1162                .map_err(DecodeError::Invalid),
1163            Action::GetTransactionStatus => ocpp_core::decode_payload(payload)
1164                .map(CsmsCall::GetTransactionStatus)
1165                .map_err(DecodeError::Invalid),
1166            Action::GetVariables => ocpp_core::decode_payload(payload)
1167                .map(CsmsCall::GetVariables)
1168                .map_err(DecodeError::Invalid),
1169            Action::InstallCertificate => ocpp_core::decode_payload(payload)
1170                .map(CsmsCall::InstallCertificate)
1171                .map_err(DecodeError::Invalid),
1172            Action::PublishFirmware => ocpp_core::decode_payload(payload)
1173                .map(CsmsCall::PublishFirmware)
1174                .map_err(DecodeError::Invalid),
1175            Action::RequestStartTransaction => ocpp_core::decode_payload(payload)
1176                .map(CsmsCall::RequestStartTransaction)
1177                .map_err(DecodeError::Invalid),
1178            Action::RequestStopTransaction => ocpp_core::decode_payload(payload)
1179                .map(CsmsCall::RequestStopTransaction)
1180                .map_err(DecodeError::Invalid),
1181            Action::ReserveNow => ocpp_core::decode_payload(payload)
1182                .map(CsmsCall::ReserveNow)
1183                .map_err(DecodeError::Invalid),
1184            Action::Reset => ocpp_core::decode_payload(payload)
1185                .map(CsmsCall::Reset)
1186                .map_err(DecodeError::Invalid),
1187            Action::SendLocalList => ocpp_core::decode_payload(payload)
1188                .map(CsmsCall::SendLocalList)
1189                .map_err(DecodeError::Invalid),
1190            Action::SetChargingProfile => ocpp_core::decode_payload(payload)
1191                .map(CsmsCall::SetChargingProfile)
1192                .map_err(DecodeError::Invalid),
1193            Action::SetDisplayMessage => ocpp_core::decode_payload(payload)
1194                .map(CsmsCall::SetDisplayMessage)
1195                .map_err(DecodeError::Invalid),
1196            Action::SetMonitoringBase => ocpp_core::decode_payload(payload)
1197                .map(CsmsCall::SetMonitoringBase)
1198                .map_err(DecodeError::Invalid),
1199            Action::SetMonitoringLevel => ocpp_core::decode_payload(payload)
1200                .map(CsmsCall::SetMonitoringLevel)
1201                .map_err(DecodeError::Invalid),
1202            Action::SetNetworkProfile => ocpp_core::decode_payload(payload)
1203                .map(CsmsCall::SetNetworkProfile)
1204                .map_err(DecodeError::Invalid),
1205            Action::SetVariableMonitoring => ocpp_core::decode_payload(payload)
1206                .map(CsmsCall::SetVariableMonitoring)
1207                .map_err(DecodeError::Invalid),
1208            Action::SetVariables => ocpp_core::decode_payload(payload)
1209                .map(CsmsCall::SetVariables)
1210                .map_err(DecodeError::Invalid),
1211            Action::TriggerMessage => ocpp_core::decode_payload(payload)
1212                .map(CsmsCall::TriggerMessage)
1213                .map_err(DecodeError::Invalid),
1214            Action::UnlockConnector => ocpp_core::decode_payload(payload)
1215                .map(CsmsCall::UnlockConnector)
1216                .map_err(DecodeError::Invalid),
1217            Action::UnpublishFirmware => ocpp_core::decode_payload(payload)
1218                .map(CsmsCall::UnpublishFirmware)
1219                .map_err(DecodeError::Invalid),
1220            Action::UpdateFirmware => ocpp_core::decode_payload(payload)
1221                .map(CsmsCall::UpdateFirmware)
1222                .map_err(DecodeError::Invalid),
1223            #[allow(unreachable_patterns)]
1224            other => Err(DecodeError::WrongDirection(other)),
1225        }
1226    }
1227
1228    /// Decodes and validates a request given as a JSON value (e.g. from the HTTP API).
1229    pub fn from_value(action: &str, payload: serde_json::Value) -> Result<Self, DecodeError> {
1230        let a = Action::from_name(action)
1231            .ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
1232        match a {
1233            Action::CancelReservation => ocpp_core::decode_value(payload)
1234                .map(CsmsCall::CancelReservation)
1235                .map_err(DecodeError::Invalid),
1236            Action::CertificateSigned => ocpp_core::decode_value(payload)
1237                .map(CsmsCall::CertificateSigned)
1238                .map_err(DecodeError::Invalid),
1239            Action::ChangeAvailability => ocpp_core::decode_value(payload)
1240                .map(CsmsCall::ChangeAvailability)
1241                .map_err(DecodeError::Invalid),
1242            Action::ClearCache => ocpp_core::decode_value(payload)
1243                .map(CsmsCall::ClearCache)
1244                .map_err(DecodeError::Invalid),
1245            Action::ClearChargingProfile => ocpp_core::decode_value(payload)
1246                .map(CsmsCall::ClearChargingProfile)
1247                .map_err(DecodeError::Invalid),
1248            Action::ClearDisplayMessage => ocpp_core::decode_value(payload)
1249                .map(CsmsCall::ClearDisplayMessage)
1250                .map_err(DecodeError::Invalid),
1251            Action::ClearVariableMonitoring => ocpp_core::decode_value(payload)
1252                .map(CsmsCall::ClearVariableMonitoring)
1253                .map_err(DecodeError::Invalid),
1254            Action::CostUpdated => ocpp_core::decode_value(payload)
1255                .map(CsmsCall::CostUpdated)
1256                .map_err(DecodeError::Invalid),
1257            Action::CustomerInformation => ocpp_core::decode_value(payload)
1258                .map(CsmsCall::CustomerInformation)
1259                .map_err(DecodeError::Invalid),
1260            Action::DataTransfer => ocpp_core::decode_value(payload)
1261                .map(CsmsCall::DataTransfer)
1262                .map_err(DecodeError::Invalid),
1263            Action::DeleteCertificate => ocpp_core::decode_value(payload)
1264                .map(CsmsCall::DeleteCertificate)
1265                .map_err(DecodeError::Invalid),
1266            Action::GetBaseReport => ocpp_core::decode_value(payload)
1267                .map(CsmsCall::GetBaseReport)
1268                .map_err(DecodeError::Invalid),
1269            Action::GetChargingProfiles => ocpp_core::decode_value(payload)
1270                .map(CsmsCall::GetChargingProfiles)
1271                .map_err(DecodeError::Invalid),
1272            Action::GetCompositeSchedule => ocpp_core::decode_value(payload)
1273                .map(CsmsCall::GetCompositeSchedule)
1274                .map_err(DecodeError::Invalid),
1275            Action::GetDisplayMessages => ocpp_core::decode_value(payload)
1276                .map(CsmsCall::GetDisplayMessages)
1277                .map_err(DecodeError::Invalid),
1278            Action::GetInstalledCertificateIds => ocpp_core::decode_value(payload)
1279                .map(CsmsCall::GetInstalledCertificateIds)
1280                .map_err(DecodeError::Invalid),
1281            Action::GetLocalListVersion => ocpp_core::decode_value(payload)
1282                .map(CsmsCall::GetLocalListVersion)
1283                .map_err(DecodeError::Invalid),
1284            Action::GetLog => ocpp_core::decode_value(payload)
1285                .map(CsmsCall::GetLog)
1286                .map_err(DecodeError::Invalid),
1287            Action::GetMonitoringReport => ocpp_core::decode_value(payload)
1288                .map(CsmsCall::GetMonitoringReport)
1289                .map_err(DecodeError::Invalid),
1290            Action::GetReport => ocpp_core::decode_value(payload)
1291                .map(CsmsCall::GetReport)
1292                .map_err(DecodeError::Invalid),
1293            Action::GetTransactionStatus => ocpp_core::decode_value(payload)
1294                .map(CsmsCall::GetTransactionStatus)
1295                .map_err(DecodeError::Invalid),
1296            Action::GetVariables => ocpp_core::decode_value(payload)
1297                .map(CsmsCall::GetVariables)
1298                .map_err(DecodeError::Invalid),
1299            Action::InstallCertificate => ocpp_core::decode_value(payload)
1300                .map(CsmsCall::InstallCertificate)
1301                .map_err(DecodeError::Invalid),
1302            Action::PublishFirmware => ocpp_core::decode_value(payload)
1303                .map(CsmsCall::PublishFirmware)
1304                .map_err(DecodeError::Invalid),
1305            Action::RequestStartTransaction => ocpp_core::decode_value(payload)
1306                .map(CsmsCall::RequestStartTransaction)
1307                .map_err(DecodeError::Invalid),
1308            Action::RequestStopTransaction => ocpp_core::decode_value(payload)
1309                .map(CsmsCall::RequestStopTransaction)
1310                .map_err(DecodeError::Invalid),
1311            Action::ReserveNow => ocpp_core::decode_value(payload)
1312                .map(CsmsCall::ReserveNow)
1313                .map_err(DecodeError::Invalid),
1314            Action::Reset => ocpp_core::decode_value(payload)
1315                .map(CsmsCall::Reset)
1316                .map_err(DecodeError::Invalid),
1317            Action::SendLocalList => ocpp_core::decode_value(payload)
1318                .map(CsmsCall::SendLocalList)
1319                .map_err(DecodeError::Invalid),
1320            Action::SetChargingProfile => ocpp_core::decode_value(payload)
1321                .map(CsmsCall::SetChargingProfile)
1322                .map_err(DecodeError::Invalid),
1323            Action::SetDisplayMessage => ocpp_core::decode_value(payload)
1324                .map(CsmsCall::SetDisplayMessage)
1325                .map_err(DecodeError::Invalid),
1326            Action::SetMonitoringBase => ocpp_core::decode_value(payload)
1327                .map(CsmsCall::SetMonitoringBase)
1328                .map_err(DecodeError::Invalid),
1329            Action::SetMonitoringLevel => ocpp_core::decode_value(payload)
1330                .map(CsmsCall::SetMonitoringLevel)
1331                .map_err(DecodeError::Invalid),
1332            Action::SetNetworkProfile => ocpp_core::decode_value(payload)
1333                .map(CsmsCall::SetNetworkProfile)
1334                .map_err(DecodeError::Invalid),
1335            Action::SetVariableMonitoring => ocpp_core::decode_value(payload)
1336                .map(CsmsCall::SetVariableMonitoring)
1337                .map_err(DecodeError::Invalid),
1338            Action::SetVariables => ocpp_core::decode_value(payload)
1339                .map(CsmsCall::SetVariables)
1340                .map_err(DecodeError::Invalid),
1341            Action::TriggerMessage => ocpp_core::decode_value(payload)
1342                .map(CsmsCall::TriggerMessage)
1343                .map_err(DecodeError::Invalid),
1344            Action::UnlockConnector => ocpp_core::decode_value(payload)
1345                .map(CsmsCall::UnlockConnector)
1346                .map_err(DecodeError::Invalid),
1347            Action::UnpublishFirmware => ocpp_core::decode_value(payload)
1348                .map(CsmsCall::UnpublishFirmware)
1349                .map_err(DecodeError::Invalid),
1350            Action::UpdateFirmware => ocpp_core::decode_value(payload)
1351                .map(CsmsCall::UpdateFirmware)
1352                .map_err(DecodeError::Invalid),
1353            #[allow(unreachable_patterns)]
1354            other => Err(DecodeError::WrongDirection(other)),
1355        }
1356    }
1357
1358    /// Serializes the request payload.
1359    pub fn to_payload(&self) -> serde_json::Value {
1360        match self {
1361            CsmsCall::CancelReservation(r) => serde_json::to_value(r).expect("serializable"),
1362            CsmsCall::CertificateSigned(r) => serde_json::to_value(r).expect("serializable"),
1363            CsmsCall::ChangeAvailability(r) => serde_json::to_value(r).expect("serializable"),
1364            CsmsCall::ClearCache(r) => serde_json::to_value(r).expect("serializable"),
1365            CsmsCall::ClearChargingProfile(r) => serde_json::to_value(r).expect("serializable"),
1366            CsmsCall::ClearDisplayMessage(r) => serde_json::to_value(r).expect("serializable"),
1367            CsmsCall::ClearVariableMonitoring(r) => serde_json::to_value(r).expect("serializable"),
1368            CsmsCall::CostUpdated(r) => serde_json::to_value(r).expect("serializable"),
1369            CsmsCall::CustomerInformation(r) => serde_json::to_value(r).expect("serializable"),
1370            CsmsCall::DataTransfer(r) => serde_json::to_value(r).expect("serializable"),
1371            CsmsCall::DeleteCertificate(r) => serde_json::to_value(r).expect("serializable"),
1372            CsmsCall::GetBaseReport(r) => serde_json::to_value(r).expect("serializable"),
1373            CsmsCall::GetChargingProfiles(r) => serde_json::to_value(r).expect("serializable"),
1374            CsmsCall::GetCompositeSchedule(r) => serde_json::to_value(r).expect("serializable"),
1375            CsmsCall::GetDisplayMessages(r) => serde_json::to_value(r).expect("serializable"),
1376            CsmsCall::GetInstalledCertificateIds(r) => {
1377                serde_json::to_value(r).expect("serializable")
1378            }
1379            CsmsCall::GetLocalListVersion(r) => serde_json::to_value(r).expect("serializable"),
1380            CsmsCall::GetLog(r) => serde_json::to_value(r).expect("serializable"),
1381            CsmsCall::GetMonitoringReport(r) => serde_json::to_value(r).expect("serializable"),
1382            CsmsCall::GetReport(r) => serde_json::to_value(r).expect("serializable"),
1383            CsmsCall::GetTransactionStatus(r) => serde_json::to_value(r).expect("serializable"),
1384            CsmsCall::GetVariables(r) => serde_json::to_value(r).expect("serializable"),
1385            CsmsCall::InstallCertificate(r) => serde_json::to_value(r).expect("serializable"),
1386            CsmsCall::PublishFirmware(r) => serde_json::to_value(r).expect("serializable"),
1387            CsmsCall::RequestStartTransaction(r) => serde_json::to_value(r).expect("serializable"),
1388            CsmsCall::RequestStopTransaction(r) => serde_json::to_value(r).expect("serializable"),
1389            CsmsCall::ReserveNow(r) => serde_json::to_value(r).expect("serializable"),
1390            CsmsCall::Reset(r) => serde_json::to_value(r).expect("serializable"),
1391            CsmsCall::SendLocalList(r) => serde_json::to_value(r).expect("serializable"),
1392            CsmsCall::SetChargingProfile(r) => serde_json::to_value(r).expect("serializable"),
1393            CsmsCall::SetDisplayMessage(r) => serde_json::to_value(r).expect("serializable"),
1394            CsmsCall::SetMonitoringBase(r) => serde_json::to_value(r).expect("serializable"),
1395            CsmsCall::SetMonitoringLevel(r) => serde_json::to_value(r).expect("serializable"),
1396            CsmsCall::SetNetworkProfile(r) => serde_json::to_value(r).expect("serializable"),
1397            CsmsCall::SetVariableMonitoring(r) => serde_json::to_value(r).expect("serializable"),
1398            CsmsCall::SetVariables(r) => serde_json::to_value(r).expect("serializable"),
1399            CsmsCall::TriggerMessage(r) => serde_json::to_value(r).expect("serializable"),
1400            CsmsCall::UnlockConnector(r) => serde_json::to_value(r).expect("serializable"),
1401            CsmsCall::UnpublishFirmware(r) => serde_json::to_value(r).expect("serializable"),
1402            CsmsCall::UpdateFirmware(r) => serde_json::to_value(r).expect("serializable"),
1403        }
1404    }
1405}
1406
1407/// Decodes and validates the CALLRESULT payload for `action`, returning it as JSON.
1408pub fn validate_response(action: Action, payload: &str) -> Result<serde_json::Value, Violation> {
1409    match action {
1410        Action::Authorize => ocpp_core::decode_payload::<AuthorizeResponse>(payload)
1411            .map(|r| serde_json::to_value(r).expect("serializable")),
1412        Action::BootNotification => ocpp_core::decode_payload::<BootNotificationResponse>(payload)
1413            .map(|r| serde_json::to_value(r).expect("serializable")),
1414        Action::CancelReservation => {
1415            ocpp_core::decode_payload::<CancelReservationResponse>(payload)
1416                .map(|r| serde_json::to_value(r).expect("serializable"))
1417        }
1418        Action::CertificateSigned => {
1419            ocpp_core::decode_payload::<CertificateSignedResponse>(payload)
1420                .map(|r| serde_json::to_value(r).expect("serializable"))
1421        }
1422        Action::ChangeAvailability => {
1423            ocpp_core::decode_payload::<ChangeAvailabilityResponse>(payload)
1424                .map(|r| serde_json::to_value(r).expect("serializable"))
1425        }
1426        Action::ClearCache => ocpp_core::decode_payload::<ClearCacheResponse>(payload)
1427            .map(|r| serde_json::to_value(r).expect("serializable")),
1428        Action::ClearChargingProfile => {
1429            ocpp_core::decode_payload::<ClearChargingProfileResponse>(payload)
1430                .map(|r| serde_json::to_value(r).expect("serializable"))
1431        }
1432        Action::ClearDisplayMessage => {
1433            ocpp_core::decode_payload::<ClearDisplayMessageResponse>(payload)
1434                .map(|r| serde_json::to_value(r).expect("serializable"))
1435        }
1436        Action::ClearVariableMonitoring => {
1437            ocpp_core::decode_payload::<ClearVariableMonitoringResponse>(payload)
1438                .map(|r| serde_json::to_value(r).expect("serializable"))
1439        }
1440        Action::ClearedChargingLimit => {
1441            ocpp_core::decode_payload::<ClearedChargingLimitResponse>(payload)
1442                .map(|r| serde_json::to_value(r).expect("serializable"))
1443        }
1444        Action::CostUpdated => ocpp_core::decode_payload::<CostUpdatedResponse>(payload)
1445            .map(|r| serde_json::to_value(r).expect("serializable")),
1446        Action::CustomerInformation => {
1447            ocpp_core::decode_payload::<CustomerInformationResponse>(payload)
1448                .map(|r| serde_json::to_value(r).expect("serializable"))
1449        }
1450        Action::DataTransfer => ocpp_core::decode_payload::<DataTransferResponse>(payload)
1451            .map(|r| serde_json::to_value(r).expect("serializable")),
1452        Action::DeleteCertificate => {
1453            ocpp_core::decode_payload::<DeleteCertificateResponse>(payload)
1454                .map(|r| serde_json::to_value(r).expect("serializable"))
1455        }
1456        Action::FirmwareStatusNotification => {
1457            ocpp_core::decode_payload::<FirmwareStatusNotificationResponse>(payload)
1458                .map(|r| serde_json::to_value(r).expect("serializable"))
1459        }
1460        Action::Get15118EVCertificate => {
1461            ocpp_core::decode_payload::<Get15118EVCertificateResponse>(payload)
1462                .map(|r| serde_json::to_value(r).expect("serializable"))
1463        }
1464        Action::GetBaseReport => ocpp_core::decode_payload::<GetBaseReportResponse>(payload)
1465            .map(|r| serde_json::to_value(r).expect("serializable")),
1466        Action::GetCertificateStatus => {
1467            ocpp_core::decode_payload::<GetCertificateStatusResponse>(payload)
1468                .map(|r| serde_json::to_value(r).expect("serializable"))
1469        }
1470        Action::GetChargingProfiles => {
1471            ocpp_core::decode_payload::<GetChargingProfilesResponse>(payload)
1472                .map(|r| serde_json::to_value(r).expect("serializable"))
1473        }
1474        Action::GetCompositeSchedule => {
1475            ocpp_core::decode_payload::<GetCompositeScheduleResponse>(payload)
1476                .map(|r| serde_json::to_value(r).expect("serializable"))
1477        }
1478        Action::GetDisplayMessages => {
1479            ocpp_core::decode_payload::<GetDisplayMessagesResponse>(payload)
1480                .map(|r| serde_json::to_value(r).expect("serializable"))
1481        }
1482        Action::GetInstalledCertificateIds => {
1483            ocpp_core::decode_payload::<GetInstalledCertificateIdsResponse>(payload)
1484                .map(|r| serde_json::to_value(r).expect("serializable"))
1485        }
1486        Action::GetLocalListVersion => {
1487            ocpp_core::decode_payload::<GetLocalListVersionResponse>(payload)
1488                .map(|r| serde_json::to_value(r).expect("serializable"))
1489        }
1490        Action::GetLog => ocpp_core::decode_payload::<GetLogResponse>(payload)
1491            .map(|r| serde_json::to_value(r).expect("serializable")),
1492        Action::GetMonitoringReport => {
1493            ocpp_core::decode_payload::<GetMonitoringReportResponse>(payload)
1494                .map(|r| serde_json::to_value(r).expect("serializable"))
1495        }
1496        Action::GetReport => ocpp_core::decode_payload::<GetReportResponse>(payload)
1497            .map(|r| serde_json::to_value(r).expect("serializable")),
1498        Action::GetTransactionStatus => {
1499            ocpp_core::decode_payload::<GetTransactionStatusResponse>(payload)
1500                .map(|r| serde_json::to_value(r).expect("serializable"))
1501        }
1502        Action::GetVariables => ocpp_core::decode_payload::<GetVariablesResponse>(payload)
1503            .map(|r| serde_json::to_value(r).expect("serializable")),
1504        Action::Heartbeat => ocpp_core::decode_payload::<HeartbeatResponse>(payload)
1505            .map(|r| serde_json::to_value(r).expect("serializable")),
1506        Action::InstallCertificate => {
1507            ocpp_core::decode_payload::<InstallCertificateResponse>(payload)
1508                .map(|r| serde_json::to_value(r).expect("serializable"))
1509        }
1510        Action::LogStatusNotification => {
1511            ocpp_core::decode_payload::<LogStatusNotificationResponse>(payload)
1512                .map(|r| serde_json::to_value(r).expect("serializable"))
1513        }
1514        Action::MeterValues => ocpp_core::decode_payload::<MeterValuesResponse>(payload)
1515            .map(|r| serde_json::to_value(r).expect("serializable")),
1516        Action::NotifyChargingLimit => {
1517            ocpp_core::decode_payload::<NotifyChargingLimitResponse>(payload)
1518                .map(|r| serde_json::to_value(r).expect("serializable"))
1519        }
1520        Action::NotifyCustomerInformation => {
1521            ocpp_core::decode_payload::<NotifyCustomerInformationResponse>(payload)
1522                .map(|r| serde_json::to_value(r).expect("serializable"))
1523        }
1524        Action::NotifyDisplayMessages => {
1525            ocpp_core::decode_payload::<NotifyDisplayMessagesResponse>(payload)
1526                .map(|r| serde_json::to_value(r).expect("serializable"))
1527        }
1528        Action::NotifyEVChargingNeeds => {
1529            ocpp_core::decode_payload::<NotifyEVChargingNeedsResponse>(payload)
1530                .map(|r| serde_json::to_value(r).expect("serializable"))
1531        }
1532        Action::NotifyEVChargingSchedule => {
1533            ocpp_core::decode_payload::<NotifyEVChargingScheduleResponse>(payload)
1534                .map(|r| serde_json::to_value(r).expect("serializable"))
1535        }
1536        Action::NotifyEvent => ocpp_core::decode_payload::<NotifyEventResponse>(payload)
1537            .map(|r| serde_json::to_value(r).expect("serializable")),
1538        Action::NotifyMonitoringReport => {
1539            ocpp_core::decode_payload::<NotifyMonitoringReportResponse>(payload)
1540                .map(|r| serde_json::to_value(r).expect("serializable"))
1541        }
1542        Action::NotifyReport => ocpp_core::decode_payload::<NotifyReportResponse>(payload)
1543            .map(|r| serde_json::to_value(r).expect("serializable")),
1544        Action::PublishFirmware => ocpp_core::decode_payload::<PublishFirmwareResponse>(payload)
1545            .map(|r| serde_json::to_value(r).expect("serializable")),
1546        Action::PublishFirmwareStatusNotification => {
1547            ocpp_core::decode_payload::<PublishFirmwareStatusNotificationResponse>(payload)
1548                .map(|r| serde_json::to_value(r).expect("serializable"))
1549        }
1550        Action::ReportChargingProfiles => {
1551            ocpp_core::decode_payload::<ReportChargingProfilesResponse>(payload)
1552                .map(|r| serde_json::to_value(r).expect("serializable"))
1553        }
1554        Action::RequestStartTransaction => {
1555            ocpp_core::decode_payload::<RequestStartTransactionResponse>(payload)
1556                .map(|r| serde_json::to_value(r).expect("serializable"))
1557        }
1558        Action::RequestStopTransaction => {
1559            ocpp_core::decode_payload::<RequestStopTransactionResponse>(payload)
1560                .map(|r| serde_json::to_value(r).expect("serializable"))
1561        }
1562        Action::ReservationStatusUpdate => {
1563            ocpp_core::decode_payload::<ReservationStatusUpdateResponse>(payload)
1564                .map(|r| serde_json::to_value(r).expect("serializable"))
1565        }
1566        Action::ReserveNow => ocpp_core::decode_payload::<ReserveNowResponse>(payload)
1567            .map(|r| serde_json::to_value(r).expect("serializable")),
1568        Action::Reset => ocpp_core::decode_payload::<ResetResponse>(payload)
1569            .map(|r| serde_json::to_value(r).expect("serializable")),
1570        Action::SecurityEventNotification => {
1571            ocpp_core::decode_payload::<SecurityEventNotificationResponse>(payload)
1572                .map(|r| serde_json::to_value(r).expect("serializable"))
1573        }
1574        Action::SendLocalList => ocpp_core::decode_payload::<SendLocalListResponse>(payload)
1575            .map(|r| serde_json::to_value(r).expect("serializable")),
1576        Action::SetChargingProfile => {
1577            ocpp_core::decode_payload::<SetChargingProfileResponse>(payload)
1578                .map(|r| serde_json::to_value(r).expect("serializable"))
1579        }
1580        Action::SetDisplayMessage => {
1581            ocpp_core::decode_payload::<SetDisplayMessageResponse>(payload)
1582                .map(|r| serde_json::to_value(r).expect("serializable"))
1583        }
1584        Action::SetMonitoringBase => {
1585            ocpp_core::decode_payload::<SetMonitoringBaseResponse>(payload)
1586                .map(|r| serde_json::to_value(r).expect("serializable"))
1587        }
1588        Action::SetMonitoringLevel => {
1589            ocpp_core::decode_payload::<SetMonitoringLevelResponse>(payload)
1590                .map(|r| serde_json::to_value(r).expect("serializable"))
1591        }
1592        Action::SetNetworkProfile => {
1593            ocpp_core::decode_payload::<SetNetworkProfileResponse>(payload)
1594                .map(|r| serde_json::to_value(r).expect("serializable"))
1595        }
1596        Action::SetVariableMonitoring => {
1597            ocpp_core::decode_payload::<SetVariableMonitoringResponse>(payload)
1598                .map(|r| serde_json::to_value(r).expect("serializable"))
1599        }
1600        Action::SetVariables => ocpp_core::decode_payload::<SetVariablesResponse>(payload)
1601            .map(|r| serde_json::to_value(r).expect("serializable")),
1602        Action::SignCertificate => ocpp_core::decode_payload::<SignCertificateResponse>(payload)
1603            .map(|r| serde_json::to_value(r).expect("serializable")),
1604        Action::StatusNotification => {
1605            ocpp_core::decode_payload::<StatusNotificationResponse>(payload)
1606                .map(|r| serde_json::to_value(r).expect("serializable"))
1607        }
1608        Action::TransactionEvent => ocpp_core::decode_payload::<TransactionEventResponse>(payload)
1609            .map(|r| serde_json::to_value(r).expect("serializable")),
1610        Action::TriggerMessage => ocpp_core::decode_payload::<TriggerMessageResponse>(payload)
1611            .map(|r| serde_json::to_value(r).expect("serializable")),
1612        Action::UnlockConnector => ocpp_core::decode_payload::<UnlockConnectorResponse>(payload)
1613            .map(|r| serde_json::to_value(r).expect("serializable")),
1614        Action::UnpublishFirmware => {
1615            ocpp_core::decode_payload::<UnpublishFirmwareResponse>(payload)
1616                .map(|r| serde_json::to_value(r).expect("serializable"))
1617        }
1618        Action::UpdateFirmware => ocpp_core::decode_payload::<UpdateFirmwareResponse>(payload)
1619            .map(|r| serde_json::to_value(r).expect("serializable")),
1620    }
1621}