1#![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#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29#[non_exhaustive]
30pub enum Action {
31 Authorize,
33 BootNotification,
35 CancelReservation,
37 CertificateSigned,
39 ChangeAvailability,
41 ChangeConfiguration,
43 ClearCache,
45 ClearChargingProfile,
47 DataTransfer,
49 DeleteCertificate,
51 DiagnosticsStatusNotification,
53 ExtendedTriggerMessage,
55 FirmwareStatusNotification,
57 GetCompositeSchedule,
59 GetConfiguration,
61 GetDiagnostics,
63 GetInstalledCertificateIds,
65 GetLocalListVersion,
67 GetLog,
69 Heartbeat,
71 InstallCertificate,
73 LogStatusNotification,
75 MeterValues,
77 RemoteStartTransaction,
79 RemoteStopTransaction,
81 ReserveNow,
83 Reset,
85 SecurityEventNotification,
87 SendLocalList,
89 SetChargingProfile,
91 SignCertificate,
93 SignedFirmwareStatusNotification,
95 SignedUpdateFirmware,
97 StartTransaction,
99 StatusNotification,
101 StopTransaction,
103 TriggerMessage,
105 UnlockConnector,
107 UpdateFirmware,
109}
110
111impl Action {
112 pub const ALL: &'static [Action] = &[
114 Action::Authorize,
115 Action::BootNotification,
116 Action::CancelReservation,
117 Action::CertificateSigned,
118 Action::ChangeAvailability,
119 Action::ChangeConfiguration,
120 Action::ClearCache,
121 Action::ClearChargingProfile,
122 Action::DataTransfer,
123 Action::DeleteCertificate,
124 Action::DiagnosticsStatusNotification,
125 Action::ExtendedTriggerMessage,
126 Action::FirmwareStatusNotification,
127 Action::GetCompositeSchedule,
128 Action::GetConfiguration,
129 Action::GetDiagnostics,
130 Action::GetInstalledCertificateIds,
131 Action::GetLocalListVersion,
132 Action::GetLog,
133 Action::Heartbeat,
134 Action::InstallCertificate,
135 Action::LogStatusNotification,
136 Action::MeterValues,
137 Action::RemoteStartTransaction,
138 Action::RemoteStopTransaction,
139 Action::ReserveNow,
140 Action::Reset,
141 Action::SecurityEventNotification,
142 Action::SendLocalList,
143 Action::SetChargingProfile,
144 Action::SignCertificate,
145 Action::SignedFirmwareStatusNotification,
146 Action::SignedUpdateFirmware,
147 Action::StartTransaction,
148 Action::StatusNotification,
149 Action::StopTransaction,
150 Action::TriggerMessage,
151 Action::UnlockConnector,
152 Action::UpdateFirmware,
153 ];
154
155 #[must_use]
157 pub const fn as_str(self) -> &'static str {
158 match self {
159 Action::Authorize => "Authorize",
160 Action::BootNotification => "BootNotification",
161 Action::CancelReservation => "CancelReservation",
162 Action::CertificateSigned => "CertificateSigned",
163 Action::ChangeAvailability => "ChangeAvailability",
164 Action::ChangeConfiguration => "ChangeConfiguration",
165 Action::ClearCache => "ClearCache",
166 Action::ClearChargingProfile => "ClearChargingProfile",
167 Action::DataTransfer => "DataTransfer",
168 Action::DeleteCertificate => "DeleteCertificate",
169 Action::DiagnosticsStatusNotification => "DiagnosticsStatusNotification",
170 Action::ExtendedTriggerMessage => "ExtendedTriggerMessage",
171 Action::FirmwareStatusNotification => "FirmwareStatusNotification",
172 Action::GetCompositeSchedule => "GetCompositeSchedule",
173 Action::GetConfiguration => "GetConfiguration",
174 Action::GetDiagnostics => "GetDiagnostics",
175 Action::GetInstalledCertificateIds => "GetInstalledCertificateIds",
176 Action::GetLocalListVersion => "GetLocalListVersion",
177 Action::GetLog => "GetLog",
178 Action::Heartbeat => "Heartbeat",
179 Action::InstallCertificate => "InstallCertificate",
180 Action::LogStatusNotification => "LogStatusNotification",
181 Action::MeterValues => "MeterValues",
182 Action::RemoteStartTransaction => "RemoteStartTransaction",
183 Action::RemoteStopTransaction => "RemoteStopTransaction",
184 Action::ReserveNow => "ReserveNow",
185 Action::Reset => "Reset",
186 Action::SecurityEventNotification => "SecurityEventNotification",
187 Action::SendLocalList => "SendLocalList",
188 Action::SetChargingProfile => "SetChargingProfile",
189 Action::SignCertificate => "SignCertificate",
190 Action::SignedFirmwareStatusNotification => "SignedFirmwareStatusNotification",
191 Action::SignedUpdateFirmware => "SignedUpdateFirmware",
192 Action::StartTransaction => "StartTransaction",
193 Action::StatusNotification => "StatusNotification",
194 Action::StopTransaction => "StopTransaction",
195 Action::TriggerMessage => "TriggerMessage",
196 Action::UnlockConnector => "UnlockConnector",
197 Action::UpdateFirmware => "UpdateFirmware",
198 }
199 }
200
201 #[must_use]
203 pub fn from_wire(name: &str) -> Option<Self> {
204 Some(match name {
205 "Authorize" => Action::Authorize,
206 "BootNotification" => Action::BootNotification,
207 "CancelReservation" => Action::CancelReservation,
208 "CertificateSigned" => Action::CertificateSigned,
209 "ChangeAvailability" => Action::ChangeAvailability,
210 "ChangeConfiguration" => Action::ChangeConfiguration,
211 "ClearCache" => Action::ClearCache,
212 "ClearChargingProfile" => Action::ClearChargingProfile,
213 "DataTransfer" => Action::DataTransfer,
214 "DeleteCertificate" => Action::DeleteCertificate,
215 "DiagnosticsStatusNotification" => Action::DiagnosticsStatusNotification,
216 "ExtendedTriggerMessage" => Action::ExtendedTriggerMessage,
217 "FirmwareStatusNotification" => Action::FirmwareStatusNotification,
218 "GetCompositeSchedule" => Action::GetCompositeSchedule,
219 "GetConfiguration" => Action::GetConfiguration,
220 "GetDiagnostics" => Action::GetDiagnostics,
221 "GetInstalledCertificateIds" => Action::GetInstalledCertificateIds,
222 "GetLocalListVersion" => Action::GetLocalListVersion,
223 "GetLog" => Action::GetLog,
224 "Heartbeat" => Action::Heartbeat,
225 "InstallCertificate" => Action::InstallCertificate,
226 "LogStatusNotification" => Action::LogStatusNotification,
227 "MeterValues" => Action::MeterValues,
228 "RemoteStartTransaction" => Action::RemoteStartTransaction,
229 "RemoteStopTransaction" => Action::RemoteStopTransaction,
230 "ReserveNow" => Action::ReserveNow,
231 "Reset" => Action::Reset,
232 "SecurityEventNotification" => Action::SecurityEventNotification,
233 "SendLocalList" => Action::SendLocalList,
234 "SetChargingProfile" => Action::SetChargingProfile,
235 "SignCertificate" => Action::SignCertificate,
236 "SignedFirmwareStatusNotification" => Action::SignedFirmwareStatusNotification,
237 "SignedUpdateFirmware" => Action::SignedUpdateFirmware,
238 "StartTransaction" => Action::StartTransaction,
239 "StatusNotification" => Action::StatusNotification,
240 "StopTransaction" => Action::StopTransaction,
241 "TriggerMessage" => Action::TriggerMessage,
242 "UnlockConnector" => Action::UnlockConnector,
243 "UpdateFirmware" => Action::UpdateFirmware,
244 _ => return None,
245 })
246 }
247
248 #[must_use]
250 pub const fn kind(self) -> MessageKind {
251 MessageKind::Call
252 }
253
254 #[must_use]
256 pub const fn origin(self) -> Origin {
257 match self {
258 Action::Authorize => Origin::ChargingStation,
259 Action::BootNotification => Origin::ChargingStation,
260 Action::CancelReservation => Origin::Csms,
261 Action::CertificateSigned => Origin::Csms,
262 Action::ChangeAvailability => Origin::Csms,
263 Action::ChangeConfiguration => Origin::Csms,
264 Action::ClearCache => Origin::Csms,
265 Action::ClearChargingProfile => Origin::Csms,
266 Action::DataTransfer => Origin::Both,
267 Action::DeleteCertificate => Origin::Csms,
268 Action::DiagnosticsStatusNotification => Origin::ChargingStation,
269 Action::ExtendedTriggerMessage => Origin::Csms,
270 Action::FirmwareStatusNotification => Origin::ChargingStation,
271 Action::GetCompositeSchedule => Origin::Csms,
272 Action::GetConfiguration => Origin::Csms,
273 Action::GetDiagnostics => Origin::Csms,
274 Action::GetInstalledCertificateIds => Origin::Csms,
275 Action::GetLocalListVersion => Origin::Csms,
276 Action::GetLog => Origin::Csms,
277 Action::Heartbeat => Origin::ChargingStation,
278 Action::InstallCertificate => Origin::Csms,
279 Action::LogStatusNotification => Origin::ChargingStation,
280 Action::MeterValues => Origin::ChargingStation,
281 Action::RemoteStartTransaction => Origin::Csms,
282 Action::RemoteStopTransaction => Origin::Csms,
283 Action::ReserveNow => Origin::Csms,
284 Action::Reset => Origin::Csms,
285 Action::SecurityEventNotification => Origin::ChargingStation,
286 Action::SendLocalList => Origin::Csms,
287 Action::SetChargingProfile => Origin::Csms,
288 Action::SignCertificate => Origin::ChargingStation,
289 Action::SignedFirmwareStatusNotification => Origin::ChargingStation,
290 Action::SignedUpdateFirmware => Origin::Csms,
291 Action::StartTransaction => Origin::ChargingStation,
292 Action::StatusNotification => Origin::ChargingStation,
293 Action::StopTransaction => Origin::ChargingStation,
294 Action::TriggerMessage => Origin::Csms,
295 Action::UnlockConnector => Origin::Csms,
296 Action::UpdateFirmware => Origin::Csms,
297 }
298 }
299
300 #[must_use]
302 pub const fn block(self) -> &'static str {
303 match self {
304 Action::Authorize => "Core",
305 Action::BootNotification => "Core",
306 Action::CancelReservation => "Reservation",
307 Action::CertificateSigned => "Security",
308 Action::ChangeAvailability => "Core",
309 Action::ChangeConfiguration => "Core",
310 Action::ClearCache => "Core",
311 Action::ClearChargingProfile => "SmartCharging",
312 Action::DataTransfer => "Core",
313 Action::DeleteCertificate => "Security",
314 Action::DiagnosticsStatusNotification => "FirmwareManagement",
315 Action::ExtendedTriggerMessage => "Security",
316 Action::FirmwareStatusNotification => "FirmwareManagement",
317 Action::GetCompositeSchedule => "SmartCharging",
318 Action::GetConfiguration => "Core",
319 Action::GetDiagnostics => "FirmwareManagement",
320 Action::GetInstalledCertificateIds => "Security",
321 Action::GetLocalListVersion => "LocalAuthListManagement",
322 Action::GetLog => "Security",
323 Action::Heartbeat => "Core",
324 Action::InstallCertificate => "Security",
325 Action::LogStatusNotification => "Security",
326 Action::MeterValues => "Core",
327 Action::RemoteStartTransaction => "Core",
328 Action::RemoteStopTransaction => "Core",
329 Action::ReserveNow => "Reservation",
330 Action::Reset => "Core",
331 Action::SecurityEventNotification => "Security",
332 Action::SendLocalList => "LocalAuthListManagement",
333 Action::SetChargingProfile => "SmartCharging",
334 Action::SignCertificate => "Security",
335 Action::SignedFirmwareStatusNotification => "Security",
336 Action::SignedUpdateFirmware => "Security",
337 Action::StartTransaction => "Core",
338 Action::StatusNotification => "Core",
339 Action::StopTransaction => "Core",
340 Action::TriggerMessage => "RemoteTrigger",
341 Action::UnlockConnector => "Core",
342 Action::UpdateFirmware => "FirmwareManagement",
343 }
344 }
345}
346
347impl crate::message::ActionName for Action {
348 fn all() -> &'static [Self] {
349 Self::ALL
350 }
351 fn as_str(&self) -> &'static str {
352 Action::as_str(*self)
353 }
354 fn from_wire(name: &str) -> Option<Self> {
355 Action::from_wire(name)
356 }
357 fn kind(&self) -> MessageKind {
358 Action::kind(*self)
359 }
360 fn origin(&self) -> Origin {
361 Action::origin(*self)
362 }
363 fn block(&self) -> &'static str {
364 Action::block(*self)
365 }
366}
367
368impl core::fmt::Display for Action {
369 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
370 f.write_str(self.as_str())
371 }
372}
373
374impl core::str::FromStr for Action {
375 type Err = crate::message::UnknownAction;
376 fn from_str(s: &str) -> Result<Self, Self::Err> {
377 Self::from_wire(s).ok_or(crate::message::UnknownAction)
378 }
379}
380
381impl Serialize for Action {
382 fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
383 ser.serialize_str(self.as_str())
384 }
385}
386
387impl<'de> Deserialize<'de> for Action {
388 fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
389 let s = <&str as Deserialize>::deserialize(de)?;
390 Self::from_wire(s).ok_or_else(|| serde::de::Error::custom("unknown OCPP action"))
391 }
392}
393
394impl Action {
395 #[must_use]
399 pub const fn has_response(self) -> bool {
400 matches!(self.kind(), MessageKind::Call)
401 }
402}
403
404pub fn transcode_request(
410 action: Action,
411 payload: &RawValue,
412 options: &DecodeOptions,
413) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
414 match action {
415 Action::Authorize => crate::decode::transcode::<AuthorizeRequest>(payload, options),
416 Action::BootNotification => {
417 crate::decode::transcode::<BootNotificationRequest>(payload, options)
418 }
419 Action::CancelReservation => {
420 crate::decode::transcode::<CancelReservationRequest>(payload, options)
421 }
422 Action::CertificateSigned => {
423 crate::decode::transcode::<CertificateSignedRequest>(payload, options)
424 }
425 Action::ChangeAvailability => {
426 crate::decode::transcode::<ChangeAvailabilityRequest>(payload, options)
427 }
428 Action::ChangeConfiguration => {
429 crate::decode::transcode::<ChangeConfigurationRequest>(payload, options)
430 }
431 Action::ClearCache => crate::decode::transcode::<ClearCacheRequest>(payload, options),
432 Action::ClearChargingProfile => {
433 crate::decode::transcode::<ClearChargingProfileRequest>(payload, options)
434 }
435 Action::DataTransfer => crate::decode::transcode::<DataTransferRequest>(payload, options),
436 Action::DeleteCertificate => {
437 crate::decode::transcode::<DeleteCertificateRequest>(payload, options)
438 }
439 Action::DiagnosticsStatusNotification => {
440 crate::decode::transcode::<DiagnosticsStatusNotificationRequest>(payload, options)
441 }
442 Action::ExtendedTriggerMessage => {
443 crate::decode::transcode::<ExtendedTriggerMessageRequest>(payload, options)
444 }
445 Action::FirmwareStatusNotification => {
446 crate::decode::transcode::<FirmwareStatusNotificationRequest>(payload, options)
447 }
448 Action::GetCompositeSchedule => {
449 crate::decode::transcode::<GetCompositeScheduleRequest>(payload, options)
450 }
451 Action::GetConfiguration => {
452 crate::decode::transcode::<GetConfigurationRequest>(payload, options)
453 }
454 Action::GetDiagnostics => {
455 crate::decode::transcode::<GetDiagnosticsRequest>(payload, options)
456 }
457 Action::GetInstalledCertificateIds => {
458 crate::decode::transcode::<GetInstalledCertificateIdsRequest>(payload, options)
459 }
460 Action::GetLocalListVersion => {
461 crate::decode::transcode::<GetLocalListVersionRequest>(payload, options)
462 }
463 Action::GetLog => crate::decode::transcode::<GetLogRequest>(payload, options),
464 Action::Heartbeat => crate::decode::transcode::<HeartbeatRequest>(payload, options),
465 Action::InstallCertificate => {
466 crate::decode::transcode::<InstallCertificateRequest>(payload, options)
467 }
468 Action::LogStatusNotification => {
469 crate::decode::transcode::<LogStatusNotificationRequest>(payload, options)
470 }
471 Action::MeterValues => crate::decode::transcode::<MeterValuesRequest>(payload, options),
472 Action::RemoteStartTransaction => {
473 crate::decode::transcode::<RemoteStartTransactionRequest>(payload, options)
474 }
475 Action::RemoteStopTransaction => {
476 crate::decode::transcode::<RemoteStopTransactionRequest>(payload, options)
477 }
478 Action::ReserveNow => crate::decode::transcode::<ReserveNowRequest>(payload, options),
479 Action::Reset => crate::decode::transcode::<ResetRequest>(payload, options),
480 Action::SecurityEventNotification => {
481 crate::decode::transcode::<SecurityEventNotificationRequest>(payload, options)
482 }
483 Action::SendLocalList => crate::decode::transcode::<SendLocalListRequest>(payload, options),
484 Action::SetChargingProfile => {
485 crate::decode::transcode::<SetChargingProfileRequest>(payload, options)
486 }
487 Action::SignCertificate => {
488 crate::decode::transcode::<SignCertificateRequest>(payload, options)
489 }
490 Action::SignedFirmwareStatusNotification => {
491 crate::decode::transcode::<SignedFirmwareStatusNotificationRequest>(payload, options)
492 }
493 Action::SignedUpdateFirmware => {
494 crate::decode::transcode::<SignedUpdateFirmwareRequest>(payload, options)
495 }
496 Action::StartTransaction => {
497 crate::decode::transcode::<StartTransactionRequest>(payload, options)
498 }
499 Action::StatusNotification => {
500 crate::decode::transcode::<StatusNotificationRequest>(payload, options)
501 }
502 Action::StopTransaction => {
503 crate::decode::transcode::<StopTransactionRequest>(payload, options)
504 }
505 Action::TriggerMessage => {
506 crate::decode::transcode::<TriggerMessageRequest>(payload, options)
507 }
508 Action::UnlockConnector => {
509 crate::decode::transcode::<UnlockConnectorRequest>(payload, options)
510 }
511 Action::UpdateFirmware => {
512 crate::decode::transcode::<UpdateFirmwareRequest>(payload, options)
513 }
514 }
515}
516
517pub fn transcode_response(
521 action: Action,
522 payload: &RawValue,
523 options: &DecodeOptions,
524) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
525 match action {
526 Action::Authorize => crate::decode::transcode::<AuthorizeResponse>(payload, options),
527 Action::BootNotification => {
528 crate::decode::transcode::<BootNotificationResponse>(payload, options)
529 }
530 Action::CancelReservation => {
531 crate::decode::transcode::<CancelReservationResponse>(payload, options)
532 }
533 Action::CertificateSigned => {
534 crate::decode::transcode::<CertificateSignedResponse>(payload, options)
535 }
536 Action::ChangeAvailability => {
537 crate::decode::transcode::<ChangeAvailabilityResponse>(payload, options)
538 }
539 Action::ChangeConfiguration => {
540 crate::decode::transcode::<ChangeConfigurationResponse>(payload, options)
541 }
542 Action::ClearCache => crate::decode::transcode::<ClearCacheResponse>(payload, options),
543 Action::ClearChargingProfile => {
544 crate::decode::transcode::<ClearChargingProfileResponse>(payload, options)
545 }
546 Action::DataTransfer => crate::decode::transcode::<DataTransferResponse>(payload, options),
547 Action::DeleteCertificate => {
548 crate::decode::transcode::<DeleteCertificateResponse>(payload, options)
549 }
550 Action::DiagnosticsStatusNotification => {
551 crate::decode::transcode::<DiagnosticsStatusNotificationResponse>(payload, options)
552 }
553 Action::ExtendedTriggerMessage => {
554 crate::decode::transcode::<ExtendedTriggerMessageResponse>(payload, options)
555 }
556 Action::FirmwareStatusNotification => {
557 crate::decode::transcode::<FirmwareStatusNotificationResponse>(payload, options)
558 }
559 Action::GetCompositeSchedule => {
560 crate::decode::transcode::<GetCompositeScheduleResponse>(payload, options)
561 }
562 Action::GetConfiguration => {
563 crate::decode::transcode::<GetConfigurationResponse>(payload, options)
564 }
565 Action::GetDiagnostics => {
566 crate::decode::transcode::<GetDiagnosticsResponse>(payload, options)
567 }
568 Action::GetInstalledCertificateIds => {
569 crate::decode::transcode::<GetInstalledCertificateIdsResponse>(payload, options)
570 }
571 Action::GetLocalListVersion => {
572 crate::decode::transcode::<GetLocalListVersionResponse>(payload, options)
573 }
574 Action::GetLog => crate::decode::transcode::<GetLogResponse>(payload, options),
575 Action::Heartbeat => crate::decode::transcode::<HeartbeatResponse>(payload, options),
576 Action::InstallCertificate => {
577 crate::decode::transcode::<InstallCertificateResponse>(payload, options)
578 }
579 Action::LogStatusNotification => {
580 crate::decode::transcode::<LogStatusNotificationResponse>(payload, options)
581 }
582 Action::MeterValues => crate::decode::transcode::<MeterValuesResponse>(payload, options),
583 Action::RemoteStartTransaction => {
584 crate::decode::transcode::<RemoteStartTransactionResponse>(payload, options)
585 }
586 Action::RemoteStopTransaction => {
587 crate::decode::transcode::<RemoteStopTransactionResponse>(payload, options)
588 }
589 Action::ReserveNow => crate::decode::transcode::<ReserveNowResponse>(payload, options),
590 Action::Reset => crate::decode::transcode::<ResetResponse>(payload, options),
591 Action::SecurityEventNotification => {
592 crate::decode::transcode::<SecurityEventNotificationResponse>(payload, options)
593 }
594 Action::SendLocalList => {
595 crate::decode::transcode::<SendLocalListResponse>(payload, options)
596 }
597 Action::SetChargingProfile => {
598 crate::decode::transcode::<SetChargingProfileResponse>(payload, options)
599 }
600 Action::SignCertificate => {
601 crate::decode::transcode::<SignCertificateResponse>(payload, options)
602 }
603 Action::SignedFirmwareStatusNotification => {
604 crate::decode::transcode::<SignedFirmwareStatusNotificationResponse>(payload, options)
605 }
606 Action::SignedUpdateFirmware => {
607 crate::decode::transcode::<SignedUpdateFirmwareResponse>(payload, options)
608 }
609 Action::StartTransaction => {
610 crate::decode::transcode::<StartTransactionResponse>(payload, options)
611 }
612 Action::StatusNotification => {
613 crate::decode::transcode::<StatusNotificationResponse>(payload, options)
614 }
615 Action::StopTransaction => {
616 crate::decode::transcode::<StopTransactionResponse>(payload, options)
617 }
618 Action::TriggerMessage => {
619 crate::decode::transcode::<TriggerMessageResponse>(payload, options)
620 }
621 Action::UnlockConnector => {
622 crate::decode::transcode::<UnlockConnectorResponse>(payload, options)
623 }
624 Action::UpdateFirmware => {
625 crate::decode::transcode::<UpdateFirmwareResponse>(payload, options)
626 }
627 }
628}
629
630#[derive(Clone, Debug, PartialEq)]
632#[non_exhaustive]
633#[allow(clippy::large_enum_variant)]
634pub enum CsRequest {
635 Authorize(AuthorizeRequest),
637 BootNotification(BootNotificationRequest),
639 DataTransfer(DataTransferRequest),
641 DiagnosticsStatusNotification(DiagnosticsStatusNotificationRequest),
643 FirmwareStatusNotification(FirmwareStatusNotificationRequest),
645 Heartbeat(HeartbeatRequest),
647 LogStatusNotification(LogStatusNotificationRequest),
649 MeterValues(MeterValuesRequest),
651 SecurityEventNotification(SecurityEventNotificationRequest),
653 SignCertificate(SignCertificateRequest),
655 SignedFirmwareStatusNotification(SignedFirmwareStatusNotificationRequest),
657 StartTransaction(StartTransactionRequest),
659 StatusNotification(StatusNotificationRequest),
661 StopTransaction(StopTransactionRequest),
663}
664
665impl CsRequest {
666 #[must_use]
668 pub const fn action(&self) -> Action {
669 match self {
670 Self::Authorize(_) => Action::Authorize,
671 Self::BootNotification(_) => Action::BootNotification,
672 Self::DataTransfer(_) => Action::DataTransfer,
673 Self::DiagnosticsStatusNotification(_) => Action::DiagnosticsStatusNotification,
674 Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
675 Self::Heartbeat(_) => Action::Heartbeat,
676 Self::LogStatusNotification(_) => Action::LogStatusNotification,
677 Self::MeterValues(_) => Action::MeterValues,
678 Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
679 Self::SignCertificate(_) => Action::SignCertificate,
680 Self::SignedFirmwareStatusNotification(_) => Action::SignedFirmwareStatusNotification,
681 Self::StartTransaction(_) => Action::StartTransaction,
682 Self::StatusNotification(_) => Action::StatusNotification,
683 Self::StopTransaction(_) => Action::StopTransaction,
684 }
685 }
686
687 pub fn decode(
690 action: Action,
691 payload: &RawValue,
692 options: &DecodeOptions,
693 ) -> Result<Self, DecodeError> {
694 Ok(match action {
695 Action::Authorize => Self::Authorize(
696 crate::decode::decode_payload::<AuthorizeRequest>(payload, options)?,
697 ),
698 Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
699 BootNotificationRequest,
700 >(payload, options)?),
701 Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
702 DataTransferRequest,
703 >(payload, options)?),
704 Action::DiagnosticsStatusNotification => {
705 Self::DiagnosticsStatusNotification(crate::decode::decode_payload::<
706 DiagnosticsStatusNotificationRequest,
707 >(payload, options)?)
708 }
709 Action::FirmwareStatusNotification => {
710 Self::FirmwareStatusNotification(crate::decode::decode_payload::<
711 FirmwareStatusNotificationRequest,
712 >(payload, options)?)
713 }
714 Action::Heartbeat => Self::Heartbeat(
715 crate::decode::decode_payload::<HeartbeatRequest>(payload, options)?,
716 ),
717 Action::LogStatusNotification => {
718 Self::LogStatusNotification(crate::decode::decode_payload::<
719 LogStatusNotificationRequest,
720 >(payload, options)?)
721 }
722 Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
723 MeterValuesRequest,
724 >(payload, options)?),
725 Action::SecurityEventNotification => {
726 Self::SecurityEventNotification(crate::decode::decode_payload::<
727 SecurityEventNotificationRequest,
728 >(payload, options)?)
729 }
730 Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
731 SignCertificateRequest,
732 >(payload, options)?),
733 Action::SignedFirmwareStatusNotification => {
734 Self::SignedFirmwareStatusNotification(crate::decode::decode_payload::<
735 SignedFirmwareStatusNotificationRequest,
736 >(payload, options)?)
737 }
738 Action::StartTransaction => Self::StartTransaction(crate::decode::decode_payload::<
739 StartTransactionRequest,
740 >(payload, options)?),
741 Action::StatusNotification => Self::StatusNotification(
742 crate::decode::decode_payload::<StatusNotificationRequest>(payload, options)?,
743 ),
744 Action::StopTransaction => Self::StopTransaction(crate::decode::decode_payload::<
745 StopTransactionRequest,
746 >(payload, options)?),
747 other => return Err(DecodeError::unsupported_action(other.as_str())),
748 })
749 }
750
751 pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
753 match self {
754 Self::Authorize(p) => serde_json::to_string(p),
755 Self::BootNotification(p) => serde_json::to_string(p),
756 Self::DataTransfer(p) => serde_json::to_string(p),
757 Self::DiagnosticsStatusNotification(p) => serde_json::to_string(p),
758 Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
759 Self::Heartbeat(p) => serde_json::to_string(p),
760 Self::LogStatusNotification(p) => serde_json::to_string(p),
761 Self::MeterValues(p) => serde_json::to_string(p),
762 Self::SecurityEventNotification(p) => serde_json::to_string(p),
763 Self::SignCertificate(p) => serde_json::to_string(p),
764 Self::SignedFirmwareStatusNotification(p) => serde_json::to_string(p),
765 Self::StartTransaction(p) => serde_json::to_string(p),
766 Self::StatusNotification(p) => serde_json::to_string(p),
767 Self::StopTransaction(p) => serde_json::to_string(p),
768 }
769 }
770}
771
772impl Validate for CsRequest {
773 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
774 match self {
775 Self::Authorize(p) => p.validate_at(path, out),
776 Self::BootNotification(p) => p.validate_at(path, out),
777 Self::DataTransfer(p) => p.validate_at(path, out),
778 Self::DiagnosticsStatusNotification(p) => p.validate_at(path, out),
779 Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
780 Self::Heartbeat(p) => p.validate_at(path, out),
781 Self::LogStatusNotification(p) => p.validate_at(path, out),
782 Self::MeterValues(p) => p.validate_at(path, out),
783 Self::SecurityEventNotification(p) => p.validate_at(path, out),
784 Self::SignCertificate(p) => p.validate_at(path, out),
785 Self::SignedFirmwareStatusNotification(p) => p.validate_at(path, out),
786 Self::StartTransaction(p) => p.validate_at(path, out),
787 Self::StatusNotification(p) => p.validate_at(path, out),
788 Self::StopTransaction(p) => p.validate_at(path, out),
789 }
790 }
791}
792
793impl serde::Serialize for CsRequest {
794 fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
795 match self {
796 Self::Authorize(p) => p.serialize(ser),
797 Self::BootNotification(p) => p.serialize(ser),
798 Self::DataTransfer(p) => p.serialize(ser),
799 Self::DiagnosticsStatusNotification(p) => p.serialize(ser),
800 Self::FirmwareStatusNotification(p) => p.serialize(ser),
801 Self::Heartbeat(p) => p.serialize(ser),
802 Self::LogStatusNotification(p) => p.serialize(ser),
803 Self::MeterValues(p) => p.serialize(ser),
804 Self::SecurityEventNotification(p) => p.serialize(ser),
805 Self::SignCertificate(p) => p.serialize(ser),
806 Self::SignedFirmwareStatusNotification(p) => p.serialize(ser),
807 Self::StartTransaction(p) => p.serialize(ser),
808 Self::StatusNotification(p) => p.serialize(ser),
809 Self::StopTransaction(p) => p.serialize(ser),
810 }
811 }
812}
813
814#[derive(Clone, Debug, PartialEq)]
818#[non_exhaustive]
819#[allow(clippy::large_enum_variant)]
820pub enum CsResponse {
821 Authorize(AuthorizeResponse),
823 BootNotification(BootNotificationResponse),
825 DataTransfer(DataTransferResponse),
827 DiagnosticsStatusNotification(DiagnosticsStatusNotificationResponse),
829 FirmwareStatusNotification(FirmwareStatusNotificationResponse),
831 Heartbeat(HeartbeatResponse),
833 LogStatusNotification(LogStatusNotificationResponse),
835 MeterValues(MeterValuesResponse),
837 SecurityEventNotification(SecurityEventNotificationResponse),
839 SignCertificate(SignCertificateResponse),
841 SignedFirmwareStatusNotification(SignedFirmwareStatusNotificationResponse),
843 StartTransaction(StartTransactionResponse),
845 StatusNotification(StatusNotificationResponse),
847 StopTransaction(StopTransactionResponse),
849}
850
851impl CsResponse {
852 #[must_use]
854 pub const fn action(&self) -> Action {
855 match self {
856 Self::Authorize(_) => Action::Authorize,
857 Self::BootNotification(_) => Action::BootNotification,
858 Self::DataTransfer(_) => Action::DataTransfer,
859 Self::DiagnosticsStatusNotification(_) => Action::DiagnosticsStatusNotification,
860 Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
861 Self::Heartbeat(_) => Action::Heartbeat,
862 Self::LogStatusNotification(_) => Action::LogStatusNotification,
863 Self::MeterValues(_) => Action::MeterValues,
864 Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
865 Self::SignCertificate(_) => Action::SignCertificate,
866 Self::SignedFirmwareStatusNotification(_) => Action::SignedFirmwareStatusNotification,
867 Self::StartTransaction(_) => Action::StartTransaction,
868 Self::StatusNotification(_) => Action::StatusNotification,
869 Self::StopTransaction(_) => Action::StopTransaction,
870 }
871 }
872
873 pub fn decode(
876 action: Action,
877 payload: &RawValue,
878 options: &DecodeOptions,
879 ) -> Result<Self, DecodeError> {
880 Ok(match action {
881 Action::Authorize => Self::Authorize(
882 crate::decode::decode_payload::<AuthorizeResponse>(payload, options)?,
883 ),
884 Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
885 BootNotificationResponse,
886 >(payload, options)?),
887 Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
888 DataTransferResponse,
889 >(payload, options)?),
890 Action::DiagnosticsStatusNotification => {
891 Self::DiagnosticsStatusNotification(crate::decode::decode_payload::<
892 DiagnosticsStatusNotificationResponse,
893 >(payload, options)?)
894 }
895 Action::FirmwareStatusNotification => {
896 Self::FirmwareStatusNotification(crate::decode::decode_payload::<
897 FirmwareStatusNotificationResponse,
898 >(payload, options)?)
899 }
900 Action::Heartbeat => Self::Heartbeat(
901 crate::decode::decode_payload::<HeartbeatResponse>(payload, options)?,
902 ),
903 Action::LogStatusNotification => {
904 Self::LogStatusNotification(crate::decode::decode_payload::<
905 LogStatusNotificationResponse,
906 >(payload, options)?)
907 }
908 Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
909 MeterValuesResponse,
910 >(payload, options)?),
911 Action::SecurityEventNotification => {
912 Self::SecurityEventNotification(crate::decode::decode_payload::<
913 SecurityEventNotificationResponse,
914 >(payload, options)?)
915 }
916 Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
917 SignCertificateResponse,
918 >(payload, options)?),
919 Action::SignedFirmwareStatusNotification => {
920 Self::SignedFirmwareStatusNotification(crate::decode::decode_payload::<
921 SignedFirmwareStatusNotificationResponse,
922 >(payload, options)?)
923 }
924 Action::StartTransaction => Self::StartTransaction(crate::decode::decode_payload::<
925 StartTransactionResponse,
926 >(payload, options)?),
927 Action::StatusNotification => Self::StatusNotification(
928 crate::decode::decode_payload::<StatusNotificationResponse>(payload, options)?,
929 ),
930 Action::StopTransaction => Self::StopTransaction(crate::decode::decode_payload::<
931 StopTransactionResponse,
932 >(payload, options)?),
933 other => return Err(DecodeError::unsupported_action(other.as_str())),
934 })
935 }
936
937 pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
939 match self {
940 Self::Authorize(p) => serde_json::to_string(p),
941 Self::BootNotification(p) => serde_json::to_string(p),
942 Self::DataTransfer(p) => serde_json::to_string(p),
943 Self::DiagnosticsStatusNotification(p) => serde_json::to_string(p),
944 Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
945 Self::Heartbeat(p) => serde_json::to_string(p),
946 Self::LogStatusNotification(p) => serde_json::to_string(p),
947 Self::MeterValues(p) => serde_json::to_string(p),
948 Self::SecurityEventNotification(p) => serde_json::to_string(p),
949 Self::SignCertificate(p) => serde_json::to_string(p),
950 Self::SignedFirmwareStatusNotification(p) => serde_json::to_string(p),
951 Self::StartTransaction(p) => serde_json::to_string(p),
952 Self::StatusNotification(p) => serde_json::to_string(p),
953 Self::StopTransaction(p) => serde_json::to_string(p),
954 }
955 }
956}
957
958impl Validate for CsResponse {
959 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
960 match self {
961 Self::Authorize(p) => p.validate_at(path, out),
962 Self::BootNotification(p) => p.validate_at(path, out),
963 Self::DataTransfer(p) => p.validate_at(path, out),
964 Self::DiagnosticsStatusNotification(p) => p.validate_at(path, out),
965 Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
966 Self::Heartbeat(p) => p.validate_at(path, out),
967 Self::LogStatusNotification(p) => p.validate_at(path, out),
968 Self::MeterValues(p) => p.validate_at(path, out),
969 Self::SecurityEventNotification(p) => p.validate_at(path, out),
970 Self::SignCertificate(p) => p.validate_at(path, out),
971 Self::SignedFirmwareStatusNotification(p) => p.validate_at(path, out),
972 Self::StartTransaction(p) => p.validate_at(path, out),
973 Self::StatusNotification(p) => p.validate_at(path, out),
974 Self::StopTransaction(p) => p.validate_at(path, out),
975 }
976 }
977}
978
979impl serde::Serialize for CsResponse {
980 fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
981 match self {
982 Self::Authorize(p) => p.serialize(ser),
983 Self::BootNotification(p) => p.serialize(ser),
984 Self::DataTransfer(p) => p.serialize(ser),
985 Self::DiagnosticsStatusNotification(p) => p.serialize(ser),
986 Self::FirmwareStatusNotification(p) => p.serialize(ser),
987 Self::Heartbeat(p) => p.serialize(ser),
988 Self::LogStatusNotification(p) => p.serialize(ser),
989 Self::MeterValues(p) => p.serialize(ser),
990 Self::SecurityEventNotification(p) => p.serialize(ser),
991 Self::SignCertificate(p) => p.serialize(ser),
992 Self::SignedFirmwareStatusNotification(p) => p.serialize(ser),
993 Self::StartTransaction(p) => p.serialize(ser),
994 Self::StatusNotification(p) => p.serialize(ser),
995 Self::StopTransaction(p) => p.serialize(ser),
996 }
997 }
998}
999
1000#[derive(Clone, Debug, PartialEq)]
1002#[non_exhaustive]
1003#[allow(clippy::large_enum_variant)]
1004pub enum CsmsRequest {
1005 CancelReservation(CancelReservationRequest),
1007 CertificateSigned(CertificateSignedRequest),
1009 ChangeAvailability(ChangeAvailabilityRequest),
1011 ChangeConfiguration(ChangeConfigurationRequest),
1013 ClearCache(ClearCacheRequest),
1015 ClearChargingProfile(ClearChargingProfileRequest),
1017 DataTransfer(DataTransferRequest),
1019 DeleteCertificate(DeleteCertificateRequest),
1021 ExtendedTriggerMessage(ExtendedTriggerMessageRequest),
1023 GetCompositeSchedule(GetCompositeScheduleRequest),
1025 GetConfiguration(GetConfigurationRequest),
1027 GetDiagnostics(GetDiagnosticsRequest),
1029 GetInstalledCertificateIds(GetInstalledCertificateIdsRequest),
1031 GetLocalListVersion(GetLocalListVersionRequest),
1033 GetLog(GetLogRequest),
1035 InstallCertificate(InstallCertificateRequest),
1037 RemoteStartTransaction(RemoteStartTransactionRequest),
1039 RemoteStopTransaction(RemoteStopTransactionRequest),
1041 ReserveNow(ReserveNowRequest),
1043 Reset(ResetRequest),
1045 SendLocalList(SendLocalListRequest),
1047 SetChargingProfile(SetChargingProfileRequest),
1049 SignedUpdateFirmware(SignedUpdateFirmwareRequest),
1051 TriggerMessage(TriggerMessageRequest),
1053 UnlockConnector(UnlockConnectorRequest),
1055 UpdateFirmware(UpdateFirmwareRequest),
1057}
1058
1059impl CsmsRequest {
1060 #[must_use]
1062 pub const fn action(&self) -> Action {
1063 match self {
1064 Self::CancelReservation(_) => Action::CancelReservation,
1065 Self::CertificateSigned(_) => Action::CertificateSigned,
1066 Self::ChangeAvailability(_) => Action::ChangeAvailability,
1067 Self::ChangeConfiguration(_) => Action::ChangeConfiguration,
1068 Self::ClearCache(_) => Action::ClearCache,
1069 Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
1070 Self::DataTransfer(_) => Action::DataTransfer,
1071 Self::DeleteCertificate(_) => Action::DeleteCertificate,
1072 Self::ExtendedTriggerMessage(_) => Action::ExtendedTriggerMessage,
1073 Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
1074 Self::GetConfiguration(_) => Action::GetConfiguration,
1075 Self::GetDiagnostics(_) => Action::GetDiagnostics,
1076 Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
1077 Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
1078 Self::GetLog(_) => Action::GetLog,
1079 Self::InstallCertificate(_) => Action::InstallCertificate,
1080 Self::RemoteStartTransaction(_) => Action::RemoteStartTransaction,
1081 Self::RemoteStopTransaction(_) => Action::RemoteStopTransaction,
1082 Self::ReserveNow(_) => Action::ReserveNow,
1083 Self::Reset(_) => Action::Reset,
1084 Self::SendLocalList(_) => Action::SendLocalList,
1085 Self::SetChargingProfile(_) => Action::SetChargingProfile,
1086 Self::SignedUpdateFirmware(_) => Action::SignedUpdateFirmware,
1087 Self::TriggerMessage(_) => Action::TriggerMessage,
1088 Self::UnlockConnector(_) => Action::UnlockConnector,
1089 Self::UpdateFirmware(_) => Action::UpdateFirmware,
1090 }
1091 }
1092
1093 pub fn decode(
1096 action: Action,
1097 payload: &RawValue,
1098 options: &DecodeOptions,
1099 ) -> Result<Self, DecodeError> {
1100 Ok(match action {
1101 Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
1102 CancelReservationRequest,
1103 >(payload, options)?),
1104 Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
1105 CertificateSignedRequest,
1106 >(payload, options)?),
1107 Action::ChangeAvailability => Self::ChangeAvailability(
1108 crate::decode::decode_payload::<ChangeAvailabilityRequest>(payload, options)?,
1109 ),
1110 Action::ChangeConfiguration => {
1111 Self::ChangeConfiguration(crate::decode::decode_payload::<
1112 ChangeConfigurationRequest,
1113 >(payload, options)?)
1114 }
1115 Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
1116 ClearCacheRequest,
1117 >(payload, options)?),
1118 Action::ClearChargingProfile => {
1119 Self::ClearChargingProfile(crate::decode::decode_payload::<
1120 ClearChargingProfileRequest,
1121 >(payload, options)?)
1122 }
1123 Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
1124 DataTransferRequest,
1125 >(payload, options)?),
1126 Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
1127 DeleteCertificateRequest,
1128 >(payload, options)?),
1129 Action::ExtendedTriggerMessage => {
1130 Self::ExtendedTriggerMessage(crate::decode::decode_payload::<
1131 ExtendedTriggerMessageRequest,
1132 >(payload, options)?)
1133 }
1134 Action::GetCompositeSchedule => {
1135 Self::GetCompositeSchedule(crate::decode::decode_payload::<
1136 GetCompositeScheduleRequest,
1137 >(payload, options)?)
1138 }
1139 Action::GetConfiguration => Self::GetConfiguration(crate::decode::decode_payload::<
1140 GetConfigurationRequest,
1141 >(payload, options)?),
1142 Action::GetDiagnostics => Self::GetDiagnostics(crate::decode::decode_payload::<
1143 GetDiagnosticsRequest,
1144 >(payload, options)?),
1145 Action::GetInstalledCertificateIds => {
1146 Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
1147 GetInstalledCertificateIdsRequest,
1148 >(payload, options)?)
1149 }
1150 Action::GetLocalListVersion => {
1151 Self::GetLocalListVersion(crate::decode::decode_payload::<
1152 GetLocalListVersionRequest,
1153 >(payload, options)?)
1154 }
1155 Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogRequest>(
1156 payload, options,
1157 )?),
1158 Action::InstallCertificate => Self::InstallCertificate(
1159 crate::decode::decode_payload::<InstallCertificateRequest>(payload, options)?,
1160 ),
1161 Action::RemoteStartTransaction => {
1162 Self::RemoteStartTransaction(crate::decode::decode_payload::<
1163 RemoteStartTransactionRequest,
1164 >(payload, options)?)
1165 }
1166 Action::RemoteStopTransaction => {
1167 Self::RemoteStopTransaction(crate::decode::decode_payload::<
1168 RemoteStopTransactionRequest,
1169 >(payload, options)?)
1170 }
1171 Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
1172 ReserveNowRequest,
1173 >(payload, options)?),
1174 Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetRequest>(
1175 payload, options,
1176 )?),
1177 Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
1178 SendLocalListRequest,
1179 >(payload, options)?),
1180 Action::SetChargingProfile => Self::SetChargingProfile(
1181 crate::decode::decode_payload::<SetChargingProfileRequest>(payload, options)?,
1182 ),
1183 Action::SignedUpdateFirmware => {
1184 Self::SignedUpdateFirmware(crate::decode::decode_payload::<
1185 SignedUpdateFirmwareRequest,
1186 >(payload, options)?)
1187 }
1188 Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
1189 TriggerMessageRequest,
1190 >(payload, options)?),
1191 Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
1192 UnlockConnectorRequest,
1193 >(payload, options)?),
1194 Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
1195 UpdateFirmwareRequest,
1196 >(payload, options)?),
1197 other => return Err(DecodeError::unsupported_action(other.as_str())),
1198 })
1199 }
1200
1201 pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
1203 match self {
1204 Self::CancelReservation(p) => serde_json::to_string(p),
1205 Self::CertificateSigned(p) => serde_json::to_string(p),
1206 Self::ChangeAvailability(p) => serde_json::to_string(p),
1207 Self::ChangeConfiguration(p) => serde_json::to_string(p),
1208 Self::ClearCache(p) => serde_json::to_string(p),
1209 Self::ClearChargingProfile(p) => serde_json::to_string(p),
1210 Self::DataTransfer(p) => serde_json::to_string(p),
1211 Self::DeleteCertificate(p) => serde_json::to_string(p),
1212 Self::ExtendedTriggerMessage(p) => serde_json::to_string(p),
1213 Self::GetCompositeSchedule(p) => serde_json::to_string(p),
1214 Self::GetConfiguration(p) => serde_json::to_string(p),
1215 Self::GetDiagnostics(p) => serde_json::to_string(p),
1216 Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
1217 Self::GetLocalListVersion(p) => serde_json::to_string(p),
1218 Self::GetLog(p) => serde_json::to_string(p),
1219 Self::InstallCertificate(p) => serde_json::to_string(p),
1220 Self::RemoteStartTransaction(p) => serde_json::to_string(p),
1221 Self::RemoteStopTransaction(p) => serde_json::to_string(p),
1222 Self::ReserveNow(p) => serde_json::to_string(p),
1223 Self::Reset(p) => serde_json::to_string(p),
1224 Self::SendLocalList(p) => serde_json::to_string(p),
1225 Self::SetChargingProfile(p) => serde_json::to_string(p),
1226 Self::SignedUpdateFirmware(p) => serde_json::to_string(p),
1227 Self::TriggerMessage(p) => serde_json::to_string(p),
1228 Self::UnlockConnector(p) => serde_json::to_string(p),
1229 Self::UpdateFirmware(p) => serde_json::to_string(p),
1230 }
1231 }
1232}
1233
1234impl Validate for CsmsRequest {
1235 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
1236 match self {
1237 Self::CancelReservation(p) => p.validate_at(path, out),
1238 Self::CertificateSigned(p) => p.validate_at(path, out),
1239 Self::ChangeAvailability(p) => p.validate_at(path, out),
1240 Self::ChangeConfiguration(p) => p.validate_at(path, out),
1241 Self::ClearCache(p) => p.validate_at(path, out),
1242 Self::ClearChargingProfile(p) => p.validate_at(path, out),
1243 Self::DataTransfer(p) => p.validate_at(path, out),
1244 Self::DeleteCertificate(p) => p.validate_at(path, out),
1245 Self::ExtendedTriggerMessage(p) => p.validate_at(path, out),
1246 Self::GetCompositeSchedule(p) => p.validate_at(path, out),
1247 Self::GetConfiguration(p) => p.validate_at(path, out),
1248 Self::GetDiagnostics(p) => p.validate_at(path, out),
1249 Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
1250 Self::GetLocalListVersion(p) => p.validate_at(path, out),
1251 Self::GetLog(p) => p.validate_at(path, out),
1252 Self::InstallCertificate(p) => p.validate_at(path, out),
1253 Self::RemoteStartTransaction(p) => p.validate_at(path, out),
1254 Self::RemoteStopTransaction(p) => p.validate_at(path, out),
1255 Self::ReserveNow(p) => p.validate_at(path, out),
1256 Self::Reset(p) => p.validate_at(path, out),
1257 Self::SendLocalList(p) => p.validate_at(path, out),
1258 Self::SetChargingProfile(p) => p.validate_at(path, out),
1259 Self::SignedUpdateFirmware(p) => p.validate_at(path, out),
1260 Self::TriggerMessage(p) => p.validate_at(path, out),
1261 Self::UnlockConnector(p) => p.validate_at(path, out),
1262 Self::UpdateFirmware(p) => p.validate_at(path, out),
1263 }
1264 }
1265}
1266
1267impl serde::Serialize for CsmsRequest {
1268 fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
1269 match self {
1270 Self::CancelReservation(p) => p.serialize(ser),
1271 Self::CertificateSigned(p) => p.serialize(ser),
1272 Self::ChangeAvailability(p) => p.serialize(ser),
1273 Self::ChangeConfiguration(p) => p.serialize(ser),
1274 Self::ClearCache(p) => p.serialize(ser),
1275 Self::ClearChargingProfile(p) => p.serialize(ser),
1276 Self::DataTransfer(p) => p.serialize(ser),
1277 Self::DeleteCertificate(p) => p.serialize(ser),
1278 Self::ExtendedTriggerMessage(p) => p.serialize(ser),
1279 Self::GetCompositeSchedule(p) => p.serialize(ser),
1280 Self::GetConfiguration(p) => p.serialize(ser),
1281 Self::GetDiagnostics(p) => p.serialize(ser),
1282 Self::GetInstalledCertificateIds(p) => p.serialize(ser),
1283 Self::GetLocalListVersion(p) => p.serialize(ser),
1284 Self::GetLog(p) => p.serialize(ser),
1285 Self::InstallCertificate(p) => p.serialize(ser),
1286 Self::RemoteStartTransaction(p) => p.serialize(ser),
1287 Self::RemoteStopTransaction(p) => p.serialize(ser),
1288 Self::ReserveNow(p) => p.serialize(ser),
1289 Self::Reset(p) => p.serialize(ser),
1290 Self::SendLocalList(p) => p.serialize(ser),
1291 Self::SetChargingProfile(p) => p.serialize(ser),
1292 Self::SignedUpdateFirmware(p) => p.serialize(ser),
1293 Self::TriggerMessage(p) => p.serialize(ser),
1294 Self::UnlockConnector(p) => p.serialize(ser),
1295 Self::UpdateFirmware(p) => p.serialize(ser),
1296 }
1297 }
1298}
1299
1300#[derive(Clone, Debug, PartialEq)]
1302#[non_exhaustive]
1303#[allow(clippy::large_enum_variant)]
1304pub enum CsmsResponse {
1305 CancelReservation(CancelReservationResponse),
1307 CertificateSigned(CertificateSignedResponse),
1309 ChangeAvailability(ChangeAvailabilityResponse),
1311 ChangeConfiguration(ChangeConfigurationResponse),
1313 ClearCache(ClearCacheResponse),
1315 ClearChargingProfile(ClearChargingProfileResponse),
1317 DataTransfer(DataTransferResponse),
1319 DeleteCertificate(DeleteCertificateResponse),
1321 ExtendedTriggerMessage(ExtendedTriggerMessageResponse),
1323 GetCompositeSchedule(GetCompositeScheduleResponse),
1325 GetConfiguration(GetConfigurationResponse),
1327 GetDiagnostics(GetDiagnosticsResponse),
1329 GetInstalledCertificateIds(GetInstalledCertificateIdsResponse),
1331 GetLocalListVersion(GetLocalListVersionResponse),
1333 GetLog(GetLogResponse),
1335 InstallCertificate(InstallCertificateResponse),
1337 RemoteStartTransaction(RemoteStartTransactionResponse),
1339 RemoteStopTransaction(RemoteStopTransactionResponse),
1341 ReserveNow(ReserveNowResponse),
1343 Reset(ResetResponse),
1345 SendLocalList(SendLocalListResponse),
1347 SetChargingProfile(SetChargingProfileResponse),
1349 SignedUpdateFirmware(SignedUpdateFirmwareResponse),
1351 TriggerMessage(TriggerMessageResponse),
1353 UnlockConnector(UnlockConnectorResponse),
1355 UpdateFirmware(UpdateFirmwareResponse),
1357}
1358
1359impl CsmsResponse {
1360 #[must_use]
1362 pub const fn action(&self) -> Action {
1363 match self {
1364 Self::CancelReservation(_) => Action::CancelReservation,
1365 Self::CertificateSigned(_) => Action::CertificateSigned,
1366 Self::ChangeAvailability(_) => Action::ChangeAvailability,
1367 Self::ChangeConfiguration(_) => Action::ChangeConfiguration,
1368 Self::ClearCache(_) => Action::ClearCache,
1369 Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
1370 Self::DataTransfer(_) => Action::DataTransfer,
1371 Self::DeleteCertificate(_) => Action::DeleteCertificate,
1372 Self::ExtendedTriggerMessage(_) => Action::ExtendedTriggerMessage,
1373 Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
1374 Self::GetConfiguration(_) => Action::GetConfiguration,
1375 Self::GetDiagnostics(_) => Action::GetDiagnostics,
1376 Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
1377 Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
1378 Self::GetLog(_) => Action::GetLog,
1379 Self::InstallCertificate(_) => Action::InstallCertificate,
1380 Self::RemoteStartTransaction(_) => Action::RemoteStartTransaction,
1381 Self::RemoteStopTransaction(_) => Action::RemoteStopTransaction,
1382 Self::ReserveNow(_) => Action::ReserveNow,
1383 Self::Reset(_) => Action::Reset,
1384 Self::SendLocalList(_) => Action::SendLocalList,
1385 Self::SetChargingProfile(_) => Action::SetChargingProfile,
1386 Self::SignedUpdateFirmware(_) => Action::SignedUpdateFirmware,
1387 Self::TriggerMessage(_) => Action::TriggerMessage,
1388 Self::UnlockConnector(_) => Action::UnlockConnector,
1389 Self::UpdateFirmware(_) => Action::UpdateFirmware,
1390 }
1391 }
1392
1393 pub fn decode(
1396 action: Action,
1397 payload: &RawValue,
1398 options: &DecodeOptions,
1399 ) -> Result<Self, DecodeError> {
1400 Ok(match action {
1401 Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
1402 CancelReservationResponse,
1403 >(payload, options)?),
1404 Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
1405 CertificateSignedResponse,
1406 >(payload, options)?),
1407 Action::ChangeAvailability => Self::ChangeAvailability(
1408 crate::decode::decode_payload::<ChangeAvailabilityResponse>(payload, options)?,
1409 ),
1410 Action::ChangeConfiguration => {
1411 Self::ChangeConfiguration(crate::decode::decode_payload::<
1412 ChangeConfigurationResponse,
1413 >(payload, options)?)
1414 }
1415 Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
1416 ClearCacheResponse,
1417 >(payload, options)?),
1418 Action::ClearChargingProfile => {
1419 Self::ClearChargingProfile(crate::decode::decode_payload::<
1420 ClearChargingProfileResponse,
1421 >(payload, options)?)
1422 }
1423 Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
1424 DataTransferResponse,
1425 >(payload, options)?),
1426 Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
1427 DeleteCertificateResponse,
1428 >(payload, options)?),
1429 Action::ExtendedTriggerMessage => {
1430 Self::ExtendedTriggerMessage(crate::decode::decode_payload::<
1431 ExtendedTriggerMessageResponse,
1432 >(payload, options)?)
1433 }
1434 Action::GetCompositeSchedule => {
1435 Self::GetCompositeSchedule(crate::decode::decode_payload::<
1436 GetCompositeScheduleResponse,
1437 >(payload, options)?)
1438 }
1439 Action::GetConfiguration => Self::GetConfiguration(crate::decode::decode_payload::<
1440 GetConfigurationResponse,
1441 >(payload, options)?),
1442 Action::GetDiagnostics => Self::GetDiagnostics(crate::decode::decode_payload::<
1443 GetDiagnosticsResponse,
1444 >(payload, options)?),
1445 Action::GetInstalledCertificateIds => {
1446 Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
1447 GetInstalledCertificateIdsResponse,
1448 >(payload, options)?)
1449 }
1450 Action::GetLocalListVersion => {
1451 Self::GetLocalListVersion(crate::decode::decode_payload::<
1452 GetLocalListVersionResponse,
1453 >(payload, options)?)
1454 }
1455 Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogResponse>(
1456 payload, options,
1457 )?),
1458 Action::InstallCertificate => Self::InstallCertificate(
1459 crate::decode::decode_payload::<InstallCertificateResponse>(payload, options)?,
1460 ),
1461 Action::RemoteStartTransaction => {
1462 Self::RemoteStartTransaction(crate::decode::decode_payload::<
1463 RemoteStartTransactionResponse,
1464 >(payload, options)?)
1465 }
1466 Action::RemoteStopTransaction => {
1467 Self::RemoteStopTransaction(crate::decode::decode_payload::<
1468 RemoteStopTransactionResponse,
1469 >(payload, options)?)
1470 }
1471 Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
1472 ReserveNowResponse,
1473 >(payload, options)?),
1474 Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetResponse>(
1475 payload, options,
1476 )?),
1477 Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
1478 SendLocalListResponse,
1479 >(payload, options)?),
1480 Action::SetChargingProfile => Self::SetChargingProfile(
1481 crate::decode::decode_payload::<SetChargingProfileResponse>(payload, options)?,
1482 ),
1483 Action::SignedUpdateFirmware => {
1484 Self::SignedUpdateFirmware(crate::decode::decode_payload::<
1485 SignedUpdateFirmwareResponse,
1486 >(payload, options)?)
1487 }
1488 Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
1489 TriggerMessageResponse,
1490 >(payload, options)?),
1491 Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
1492 UnlockConnectorResponse,
1493 >(payload, options)?),
1494 Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
1495 UpdateFirmwareResponse,
1496 >(payload, options)?),
1497 other => return Err(DecodeError::unsupported_action(other.as_str())),
1498 })
1499 }
1500
1501 pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
1503 match self {
1504 Self::CancelReservation(p) => serde_json::to_string(p),
1505 Self::CertificateSigned(p) => serde_json::to_string(p),
1506 Self::ChangeAvailability(p) => serde_json::to_string(p),
1507 Self::ChangeConfiguration(p) => serde_json::to_string(p),
1508 Self::ClearCache(p) => serde_json::to_string(p),
1509 Self::ClearChargingProfile(p) => serde_json::to_string(p),
1510 Self::DataTransfer(p) => serde_json::to_string(p),
1511 Self::DeleteCertificate(p) => serde_json::to_string(p),
1512 Self::ExtendedTriggerMessage(p) => serde_json::to_string(p),
1513 Self::GetCompositeSchedule(p) => serde_json::to_string(p),
1514 Self::GetConfiguration(p) => serde_json::to_string(p),
1515 Self::GetDiagnostics(p) => serde_json::to_string(p),
1516 Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
1517 Self::GetLocalListVersion(p) => serde_json::to_string(p),
1518 Self::GetLog(p) => serde_json::to_string(p),
1519 Self::InstallCertificate(p) => serde_json::to_string(p),
1520 Self::RemoteStartTransaction(p) => serde_json::to_string(p),
1521 Self::RemoteStopTransaction(p) => serde_json::to_string(p),
1522 Self::ReserveNow(p) => serde_json::to_string(p),
1523 Self::Reset(p) => serde_json::to_string(p),
1524 Self::SendLocalList(p) => serde_json::to_string(p),
1525 Self::SetChargingProfile(p) => serde_json::to_string(p),
1526 Self::SignedUpdateFirmware(p) => serde_json::to_string(p),
1527 Self::TriggerMessage(p) => serde_json::to_string(p),
1528 Self::UnlockConnector(p) => serde_json::to_string(p),
1529 Self::UpdateFirmware(p) => serde_json::to_string(p),
1530 }
1531 }
1532}
1533
1534impl Validate for CsmsResponse {
1535 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
1536 match self {
1537 Self::CancelReservation(p) => p.validate_at(path, out),
1538 Self::CertificateSigned(p) => p.validate_at(path, out),
1539 Self::ChangeAvailability(p) => p.validate_at(path, out),
1540 Self::ChangeConfiguration(p) => p.validate_at(path, out),
1541 Self::ClearCache(p) => p.validate_at(path, out),
1542 Self::ClearChargingProfile(p) => p.validate_at(path, out),
1543 Self::DataTransfer(p) => p.validate_at(path, out),
1544 Self::DeleteCertificate(p) => p.validate_at(path, out),
1545 Self::ExtendedTriggerMessage(p) => p.validate_at(path, out),
1546 Self::GetCompositeSchedule(p) => p.validate_at(path, out),
1547 Self::GetConfiguration(p) => p.validate_at(path, out),
1548 Self::GetDiagnostics(p) => p.validate_at(path, out),
1549 Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
1550 Self::GetLocalListVersion(p) => p.validate_at(path, out),
1551 Self::GetLog(p) => p.validate_at(path, out),
1552 Self::InstallCertificate(p) => p.validate_at(path, out),
1553 Self::RemoteStartTransaction(p) => p.validate_at(path, out),
1554 Self::RemoteStopTransaction(p) => p.validate_at(path, out),
1555 Self::ReserveNow(p) => p.validate_at(path, out),
1556 Self::Reset(p) => p.validate_at(path, out),
1557 Self::SendLocalList(p) => p.validate_at(path, out),
1558 Self::SetChargingProfile(p) => p.validate_at(path, out),
1559 Self::SignedUpdateFirmware(p) => p.validate_at(path, out),
1560 Self::TriggerMessage(p) => p.validate_at(path, out),
1561 Self::UnlockConnector(p) => p.validate_at(path, out),
1562 Self::UpdateFirmware(p) => p.validate_at(path, out),
1563 }
1564 }
1565}
1566
1567impl serde::Serialize for CsmsResponse {
1568 fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
1569 match self {
1570 Self::CancelReservation(p) => p.serialize(ser),
1571 Self::CertificateSigned(p) => p.serialize(ser),
1572 Self::ChangeAvailability(p) => p.serialize(ser),
1573 Self::ChangeConfiguration(p) => p.serialize(ser),
1574 Self::ClearCache(p) => p.serialize(ser),
1575 Self::ClearChargingProfile(p) => p.serialize(ser),
1576 Self::DataTransfer(p) => p.serialize(ser),
1577 Self::DeleteCertificate(p) => p.serialize(ser),
1578 Self::ExtendedTriggerMessage(p) => p.serialize(ser),
1579 Self::GetCompositeSchedule(p) => p.serialize(ser),
1580 Self::GetConfiguration(p) => p.serialize(ser),
1581 Self::GetDiagnostics(p) => p.serialize(ser),
1582 Self::GetInstalledCertificateIds(p) => p.serialize(ser),
1583 Self::GetLocalListVersion(p) => p.serialize(ser),
1584 Self::GetLog(p) => p.serialize(ser),
1585 Self::InstallCertificate(p) => p.serialize(ser),
1586 Self::RemoteStartTransaction(p) => p.serialize(ser),
1587 Self::RemoteStopTransaction(p) => p.serialize(ser),
1588 Self::ReserveNow(p) => p.serialize(ser),
1589 Self::Reset(p) => p.serialize(ser),
1590 Self::SendLocalList(p) => p.serialize(ser),
1591 Self::SetChargingProfile(p) => p.serialize(ser),
1592 Self::SignedUpdateFirmware(p) => p.serialize(ser),
1593 Self::TriggerMessage(p) => p.serialize(ser),
1594 Self::UnlockConnector(p) => p.serialize(ser),
1595 Self::UpdateFirmware(p) => p.serialize(ser),
1596 }
1597 }
1598}