#![allow(unused_imports, clippy::doc_markdown, clippy::struct_excessive_bools)]
#![allow(
clippy::too_many_lines,
clippy::too_many_arguments,
clippy::wildcard_imports
)]
#![allow(clippy::match_same_arms, clippy::fn_params_excessive_bools)]
use alloc::string::String;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
use super::messages::*;
use crate::decode::{DecodeError, DecodeOptions};
use crate::message::{MessageKind, Origin};
use crate::validate::{Validate, ValidationPath, Violations};
use serde_json::value::RawValue;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
pub enum Action {
Authorize,
BootNotification,
CancelReservation,
CertificateSigned,
ChangeAvailability,
ChangeConfiguration,
ClearCache,
ClearChargingProfile,
DataTransfer,
DeleteCertificate,
DiagnosticsStatusNotification,
ExtendedTriggerMessage,
FirmwareStatusNotification,
GetCompositeSchedule,
GetConfiguration,
GetDiagnostics,
GetInstalledCertificateIds,
GetLocalListVersion,
GetLog,
Heartbeat,
InstallCertificate,
LogStatusNotification,
MeterValues,
RemoteStartTransaction,
RemoteStopTransaction,
ReserveNow,
Reset,
SecurityEventNotification,
SendLocalList,
SetChargingProfile,
SignCertificate,
SignedFirmwareStatusNotification,
SignedUpdateFirmware,
StartTransaction,
StatusNotification,
StopTransaction,
TriggerMessage,
UnlockConnector,
UpdateFirmware,
}
impl Action {
pub const ALL: &'static [Action] = &[
Action::Authorize,
Action::BootNotification,
Action::CancelReservation,
Action::CertificateSigned,
Action::ChangeAvailability,
Action::ChangeConfiguration,
Action::ClearCache,
Action::ClearChargingProfile,
Action::DataTransfer,
Action::DeleteCertificate,
Action::DiagnosticsStatusNotification,
Action::ExtendedTriggerMessage,
Action::FirmwareStatusNotification,
Action::GetCompositeSchedule,
Action::GetConfiguration,
Action::GetDiagnostics,
Action::GetInstalledCertificateIds,
Action::GetLocalListVersion,
Action::GetLog,
Action::Heartbeat,
Action::InstallCertificate,
Action::LogStatusNotification,
Action::MeterValues,
Action::RemoteStartTransaction,
Action::RemoteStopTransaction,
Action::ReserveNow,
Action::Reset,
Action::SecurityEventNotification,
Action::SendLocalList,
Action::SetChargingProfile,
Action::SignCertificate,
Action::SignedFirmwareStatusNotification,
Action::SignedUpdateFirmware,
Action::StartTransaction,
Action::StatusNotification,
Action::StopTransaction,
Action::TriggerMessage,
Action::UnlockConnector,
Action::UpdateFirmware,
];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Action::Authorize => "Authorize",
Action::BootNotification => "BootNotification",
Action::CancelReservation => "CancelReservation",
Action::CertificateSigned => "CertificateSigned",
Action::ChangeAvailability => "ChangeAvailability",
Action::ChangeConfiguration => "ChangeConfiguration",
Action::ClearCache => "ClearCache",
Action::ClearChargingProfile => "ClearChargingProfile",
Action::DataTransfer => "DataTransfer",
Action::DeleteCertificate => "DeleteCertificate",
Action::DiagnosticsStatusNotification => "DiagnosticsStatusNotification",
Action::ExtendedTriggerMessage => "ExtendedTriggerMessage",
Action::FirmwareStatusNotification => "FirmwareStatusNotification",
Action::GetCompositeSchedule => "GetCompositeSchedule",
Action::GetConfiguration => "GetConfiguration",
Action::GetDiagnostics => "GetDiagnostics",
Action::GetInstalledCertificateIds => "GetInstalledCertificateIds",
Action::GetLocalListVersion => "GetLocalListVersion",
Action::GetLog => "GetLog",
Action::Heartbeat => "Heartbeat",
Action::InstallCertificate => "InstallCertificate",
Action::LogStatusNotification => "LogStatusNotification",
Action::MeterValues => "MeterValues",
Action::RemoteStartTransaction => "RemoteStartTransaction",
Action::RemoteStopTransaction => "RemoteStopTransaction",
Action::ReserveNow => "ReserveNow",
Action::Reset => "Reset",
Action::SecurityEventNotification => "SecurityEventNotification",
Action::SendLocalList => "SendLocalList",
Action::SetChargingProfile => "SetChargingProfile",
Action::SignCertificate => "SignCertificate",
Action::SignedFirmwareStatusNotification => "SignedFirmwareStatusNotification",
Action::SignedUpdateFirmware => "SignedUpdateFirmware",
Action::StartTransaction => "StartTransaction",
Action::StatusNotification => "StatusNotification",
Action::StopTransaction => "StopTransaction",
Action::TriggerMessage => "TriggerMessage",
Action::UnlockConnector => "UnlockConnector",
Action::UpdateFirmware => "UpdateFirmware",
}
}
#[must_use]
pub fn from_wire(name: &str) -> Option<Self> {
Some(match name {
"Authorize" => Action::Authorize,
"BootNotification" => Action::BootNotification,
"CancelReservation" => Action::CancelReservation,
"CertificateSigned" => Action::CertificateSigned,
"ChangeAvailability" => Action::ChangeAvailability,
"ChangeConfiguration" => Action::ChangeConfiguration,
"ClearCache" => Action::ClearCache,
"ClearChargingProfile" => Action::ClearChargingProfile,
"DataTransfer" => Action::DataTransfer,
"DeleteCertificate" => Action::DeleteCertificate,
"DiagnosticsStatusNotification" => Action::DiagnosticsStatusNotification,
"ExtendedTriggerMessage" => Action::ExtendedTriggerMessage,
"FirmwareStatusNotification" => Action::FirmwareStatusNotification,
"GetCompositeSchedule" => Action::GetCompositeSchedule,
"GetConfiguration" => Action::GetConfiguration,
"GetDiagnostics" => Action::GetDiagnostics,
"GetInstalledCertificateIds" => Action::GetInstalledCertificateIds,
"GetLocalListVersion" => Action::GetLocalListVersion,
"GetLog" => Action::GetLog,
"Heartbeat" => Action::Heartbeat,
"InstallCertificate" => Action::InstallCertificate,
"LogStatusNotification" => Action::LogStatusNotification,
"MeterValues" => Action::MeterValues,
"RemoteStartTransaction" => Action::RemoteStartTransaction,
"RemoteStopTransaction" => Action::RemoteStopTransaction,
"ReserveNow" => Action::ReserveNow,
"Reset" => Action::Reset,
"SecurityEventNotification" => Action::SecurityEventNotification,
"SendLocalList" => Action::SendLocalList,
"SetChargingProfile" => Action::SetChargingProfile,
"SignCertificate" => Action::SignCertificate,
"SignedFirmwareStatusNotification" => Action::SignedFirmwareStatusNotification,
"SignedUpdateFirmware" => Action::SignedUpdateFirmware,
"StartTransaction" => Action::StartTransaction,
"StatusNotification" => Action::StatusNotification,
"StopTransaction" => Action::StopTransaction,
"TriggerMessage" => Action::TriggerMessage,
"UnlockConnector" => Action::UnlockConnector,
"UpdateFirmware" => Action::UpdateFirmware,
_ => return None,
})
}
#[must_use]
pub const fn kind(self) -> MessageKind {
MessageKind::Call
}
#[must_use]
pub const fn origin(self) -> Origin {
match self {
Action::Authorize => Origin::ChargingStation,
Action::BootNotification => Origin::ChargingStation,
Action::CancelReservation => Origin::Csms,
Action::CertificateSigned => Origin::Csms,
Action::ChangeAvailability => Origin::Csms,
Action::ChangeConfiguration => Origin::Csms,
Action::ClearCache => Origin::Csms,
Action::ClearChargingProfile => Origin::Csms,
Action::DataTransfer => Origin::Both,
Action::DeleteCertificate => Origin::Csms,
Action::DiagnosticsStatusNotification => Origin::ChargingStation,
Action::ExtendedTriggerMessage => Origin::Csms,
Action::FirmwareStatusNotification => Origin::ChargingStation,
Action::GetCompositeSchedule => Origin::Csms,
Action::GetConfiguration => Origin::Csms,
Action::GetDiagnostics => Origin::Csms,
Action::GetInstalledCertificateIds => Origin::Csms,
Action::GetLocalListVersion => Origin::Csms,
Action::GetLog => Origin::Csms,
Action::Heartbeat => Origin::ChargingStation,
Action::InstallCertificate => Origin::Csms,
Action::LogStatusNotification => Origin::ChargingStation,
Action::MeterValues => Origin::ChargingStation,
Action::RemoteStartTransaction => Origin::Csms,
Action::RemoteStopTransaction => Origin::Csms,
Action::ReserveNow => Origin::Csms,
Action::Reset => Origin::Csms,
Action::SecurityEventNotification => Origin::ChargingStation,
Action::SendLocalList => Origin::Csms,
Action::SetChargingProfile => Origin::Csms,
Action::SignCertificate => Origin::ChargingStation,
Action::SignedFirmwareStatusNotification => Origin::ChargingStation,
Action::SignedUpdateFirmware => Origin::Csms,
Action::StartTransaction => Origin::ChargingStation,
Action::StatusNotification => Origin::ChargingStation,
Action::StopTransaction => Origin::ChargingStation,
Action::TriggerMessage => Origin::Csms,
Action::UnlockConnector => Origin::Csms,
Action::UpdateFirmware => Origin::Csms,
}
}
#[must_use]
pub const fn block(self) -> &'static str {
match self {
Action::Authorize => "Core",
Action::BootNotification => "Core",
Action::CancelReservation => "Reservation",
Action::CertificateSigned => "Security",
Action::ChangeAvailability => "Core",
Action::ChangeConfiguration => "Core",
Action::ClearCache => "Core",
Action::ClearChargingProfile => "SmartCharging",
Action::DataTransfer => "Core",
Action::DeleteCertificate => "Security",
Action::DiagnosticsStatusNotification => "FirmwareManagement",
Action::ExtendedTriggerMessage => "Security",
Action::FirmwareStatusNotification => "FirmwareManagement",
Action::GetCompositeSchedule => "SmartCharging",
Action::GetConfiguration => "Core",
Action::GetDiagnostics => "FirmwareManagement",
Action::GetInstalledCertificateIds => "Security",
Action::GetLocalListVersion => "LocalAuthListManagement",
Action::GetLog => "Security",
Action::Heartbeat => "Core",
Action::InstallCertificate => "Security",
Action::LogStatusNotification => "Security",
Action::MeterValues => "Core",
Action::RemoteStartTransaction => "Core",
Action::RemoteStopTransaction => "Core",
Action::ReserveNow => "Reservation",
Action::Reset => "Core",
Action::SecurityEventNotification => "Security",
Action::SendLocalList => "LocalAuthListManagement",
Action::SetChargingProfile => "SmartCharging",
Action::SignCertificate => "Security",
Action::SignedFirmwareStatusNotification => "Security",
Action::SignedUpdateFirmware => "Security",
Action::StartTransaction => "Core",
Action::StatusNotification => "Core",
Action::StopTransaction => "Core",
Action::TriggerMessage => "RemoteTrigger",
Action::UnlockConnector => "Core",
Action::UpdateFirmware => "FirmwareManagement",
}
}
}
impl crate::message::ActionName for Action {
fn all() -> &'static [Self] {
Self::ALL
}
fn as_str(&self) -> &'static str {
Action::as_str(*self)
}
fn from_wire(name: &str) -> Option<Self> {
Action::from_wire(name)
}
fn kind(&self) -> MessageKind {
Action::kind(*self)
}
fn origin(&self) -> Origin {
Action::origin(*self)
}
fn block(&self) -> &'static str {
Action::block(*self)
}
}
impl core::fmt::Display for Action {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
impl core::str::FromStr for Action {
type Err = crate::message::UnknownAction;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::from_wire(s).ok_or(crate::message::UnknownAction)
}
}
impl Serialize for Action {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
ser.serialize_str(self.as_str())
}
}
impl<'de> Deserialize<'de> for Action {
fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
let s = <&str as Deserialize>::deserialize(de)?;
Self::from_wire(s).ok_or_else(|| serde::de::Error::custom("unknown OCPP action"))
}
}
impl Action {
#[must_use]
pub const fn has_response(self) -> bool {
matches!(self.kind(), MessageKind::Call)
}
}
pub fn transcode_request(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
match action {
Action::Authorize => crate::decode::transcode::<AuthorizeRequest>(payload, options),
Action::BootNotification => {
crate::decode::transcode::<BootNotificationRequest>(payload, options)
}
Action::CancelReservation => {
crate::decode::transcode::<CancelReservationRequest>(payload, options)
}
Action::CertificateSigned => {
crate::decode::transcode::<CertificateSignedRequest>(payload, options)
}
Action::ChangeAvailability => {
crate::decode::transcode::<ChangeAvailabilityRequest>(payload, options)
}
Action::ChangeConfiguration => {
crate::decode::transcode::<ChangeConfigurationRequest>(payload, options)
}
Action::ClearCache => crate::decode::transcode::<ClearCacheRequest>(payload, options),
Action::ClearChargingProfile => {
crate::decode::transcode::<ClearChargingProfileRequest>(payload, options)
}
Action::DataTransfer => crate::decode::transcode::<DataTransferRequest>(payload, options),
Action::DeleteCertificate => {
crate::decode::transcode::<DeleteCertificateRequest>(payload, options)
}
Action::DiagnosticsStatusNotification => {
crate::decode::transcode::<DiagnosticsStatusNotificationRequest>(payload, options)
}
Action::ExtendedTriggerMessage => {
crate::decode::transcode::<ExtendedTriggerMessageRequest>(payload, options)
}
Action::FirmwareStatusNotification => {
crate::decode::transcode::<FirmwareStatusNotificationRequest>(payload, options)
}
Action::GetCompositeSchedule => {
crate::decode::transcode::<GetCompositeScheduleRequest>(payload, options)
}
Action::GetConfiguration => {
crate::decode::transcode::<GetConfigurationRequest>(payload, options)
}
Action::GetDiagnostics => {
crate::decode::transcode::<GetDiagnosticsRequest>(payload, options)
}
Action::GetInstalledCertificateIds => {
crate::decode::transcode::<GetInstalledCertificateIdsRequest>(payload, options)
}
Action::GetLocalListVersion => {
crate::decode::transcode::<GetLocalListVersionRequest>(payload, options)
}
Action::GetLog => crate::decode::transcode::<GetLogRequest>(payload, options),
Action::Heartbeat => crate::decode::transcode::<HeartbeatRequest>(payload, options),
Action::InstallCertificate => {
crate::decode::transcode::<InstallCertificateRequest>(payload, options)
}
Action::LogStatusNotification => {
crate::decode::transcode::<LogStatusNotificationRequest>(payload, options)
}
Action::MeterValues => crate::decode::transcode::<MeterValuesRequest>(payload, options),
Action::RemoteStartTransaction => {
crate::decode::transcode::<RemoteStartTransactionRequest>(payload, options)
}
Action::RemoteStopTransaction => {
crate::decode::transcode::<RemoteStopTransactionRequest>(payload, options)
}
Action::ReserveNow => crate::decode::transcode::<ReserveNowRequest>(payload, options),
Action::Reset => crate::decode::transcode::<ResetRequest>(payload, options),
Action::SecurityEventNotification => {
crate::decode::transcode::<SecurityEventNotificationRequest>(payload, options)
}
Action::SendLocalList => crate::decode::transcode::<SendLocalListRequest>(payload, options),
Action::SetChargingProfile => {
crate::decode::transcode::<SetChargingProfileRequest>(payload, options)
}
Action::SignCertificate => {
crate::decode::transcode::<SignCertificateRequest>(payload, options)
}
Action::SignedFirmwareStatusNotification => {
crate::decode::transcode::<SignedFirmwareStatusNotificationRequest>(payload, options)
}
Action::SignedUpdateFirmware => {
crate::decode::transcode::<SignedUpdateFirmwareRequest>(payload, options)
}
Action::StartTransaction => {
crate::decode::transcode::<StartTransactionRequest>(payload, options)
}
Action::StatusNotification => {
crate::decode::transcode::<StatusNotificationRequest>(payload, options)
}
Action::StopTransaction => {
crate::decode::transcode::<StopTransactionRequest>(payload, options)
}
Action::TriggerMessage => {
crate::decode::transcode::<TriggerMessageRequest>(payload, options)
}
Action::UnlockConnector => {
crate::decode::transcode::<UnlockConnectorRequest>(payload, options)
}
Action::UpdateFirmware => {
crate::decode::transcode::<UpdateFirmwareRequest>(payload, options)
}
}
}
pub fn transcode_response(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<alloc::boxed::Box<RawValue>, DecodeError> {
match action {
Action::Authorize => crate::decode::transcode::<AuthorizeResponse>(payload, options),
Action::BootNotification => {
crate::decode::transcode::<BootNotificationResponse>(payload, options)
}
Action::CancelReservation => {
crate::decode::transcode::<CancelReservationResponse>(payload, options)
}
Action::CertificateSigned => {
crate::decode::transcode::<CertificateSignedResponse>(payload, options)
}
Action::ChangeAvailability => {
crate::decode::transcode::<ChangeAvailabilityResponse>(payload, options)
}
Action::ChangeConfiguration => {
crate::decode::transcode::<ChangeConfigurationResponse>(payload, options)
}
Action::ClearCache => crate::decode::transcode::<ClearCacheResponse>(payload, options),
Action::ClearChargingProfile => {
crate::decode::transcode::<ClearChargingProfileResponse>(payload, options)
}
Action::DataTransfer => crate::decode::transcode::<DataTransferResponse>(payload, options),
Action::DeleteCertificate => {
crate::decode::transcode::<DeleteCertificateResponse>(payload, options)
}
Action::DiagnosticsStatusNotification => {
crate::decode::transcode::<DiagnosticsStatusNotificationResponse>(payload, options)
}
Action::ExtendedTriggerMessage => {
crate::decode::transcode::<ExtendedTriggerMessageResponse>(payload, options)
}
Action::FirmwareStatusNotification => {
crate::decode::transcode::<FirmwareStatusNotificationResponse>(payload, options)
}
Action::GetCompositeSchedule => {
crate::decode::transcode::<GetCompositeScheduleResponse>(payload, options)
}
Action::GetConfiguration => {
crate::decode::transcode::<GetConfigurationResponse>(payload, options)
}
Action::GetDiagnostics => {
crate::decode::transcode::<GetDiagnosticsResponse>(payload, options)
}
Action::GetInstalledCertificateIds => {
crate::decode::transcode::<GetInstalledCertificateIdsResponse>(payload, options)
}
Action::GetLocalListVersion => {
crate::decode::transcode::<GetLocalListVersionResponse>(payload, options)
}
Action::GetLog => crate::decode::transcode::<GetLogResponse>(payload, options),
Action::Heartbeat => crate::decode::transcode::<HeartbeatResponse>(payload, options),
Action::InstallCertificate => {
crate::decode::transcode::<InstallCertificateResponse>(payload, options)
}
Action::LogStatusNotification => {
crate::decode::transcode::<LogStatusNotificationResponse>(payload, options)
}
Action::MeterValues => crate::decode::transcode::<MeterValuesResponse>(payload, options),
Action::RemoteStartTransaction => {
crate::decode::transcode::<RemoteStartTransactionResponse>(payload, options)
}
Action::RemoteStopTransaction => {
crate::decode::transcode::<RemoteStopTransactionResponse>(payload, options)
}
Action::ReserveNow => crate::decode::transcode::<ReserveNowResponse>(payload, options),
Action::Reset => crate::decode::transcode::<ResetResponse>(payload, options),
Action::SecurityEventNotification => {
crate::decode::transcode::<SecurityEventNotificationResponse>(payload, options)
}
Action::SendLocalList => {
crate::decode::transcode::<SendLocalListResponse>(payload, options)
}
Action::SetChargingProfile => {
crate::decode::transcode::<SetChargingProfileResponse>(payload, options)
}
Action::SignCertificate => {
crate::decode::transcode::<SignCertificateResponse>(payload, options)
}
Action::SignedFirmwareStatusNotification => {
crate::decode::transcode::<SignedFirmwareStatusNotificationResponse>(payload, options)
}
Action::SignedUpdateFirmware => {
crate::decode::transcode::<SignedUpdateFirmwareResponse>(payload, options)
}
Action::StartTransaction => {
crate::decode::transcode::<StartTransactionResponse>(payload, options)
}
Action::StatusNotification => {
crate::decode::transcode::<StatusNotificationResponse>(payload, options)
}
Action::StopTransaction => {
crate::decode::transcode::<StopTransactionResponse>(payload, options)
}
Action::TriggerMessage => {
crate::decode::transcode::<TriggerMessageResponse>(payload, options)
}
Action::UnlockConnector => {
crate::decode::transcode::<UnlockConnectorResponse>(payload, options)
}
Action::UpdateFirmware => {
crate::decode::transcode::<UpdateFirmwareResponse>(payload, options)
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum CsRequest {
Authorize(AuthorizeRequest),
BootNotification(BootNotificationRequest),
DataTransfer(DataTransferRequest),
DiagnosticsStatusNotification(DiagnosticsStatusNotificationRequest),
FirmwareStatusNotification(FirmwareStatusNotificationRequest),
Heartbeat(HeartbeatRequest),
LogStatusNotification(LogStatusNotificationRequest),
MeterValues(MeterValuesRequest),
SecurityEventNotification(SecurityEventNotificationRequest),
SignCertificate(SignCertificateRequest),
SignedFirmwareStatusNotification(SignedFirmwareStatusNotificationRequest),
StartTransaction(StartTransactionRequest),
StatusNotification(StatusNotificationRequest),
StopTransaction(StopTransactionRequest),
}
impl CsRequest {
#[must_use]
pub const fn action(&self) -> Action {
match self {
Self::Authorize(_) => Action::Authorize,
Self::BootNotification(_) => Action::BootNotification,
Self::DataTransfer(_) => Action::DataTransfer,
Self::DiagnosticsStatusNotification(_) => Action::DiagnosticsStatusNotification,
Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
Self::Heartbeat(_) => Action::Heartbeat,
Self::LogStatusNotification(_) => Action::LogStatusNotification,
Self::MeterValues(_) => Action::MeterValues,
Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
Self::SignCertificate(_) => Action::SignCertificate,
Self::SignedFirmwareStatusNotification(_) => Action::SignedFirmwareStatusNotification,
Self::StartTransaction(_) => Action::StartTransaction,
Self::StatusNotification(_) => Action::StatusNotification,
Self::StopTransaction(_) => Action::StopTransaction,
}
}
pub fn decode(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<Self, DecodeError> {
Ok(match action {
Action::Authorize => Self::Authorize(
crate::decode::decode_payload::<AuthorizeRequest>(payload, options)?,
),
Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
BootNotificationRequest,
>(payload, options)?),
Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
DataTransferRequest,
>(payload, options)?),
Action::DiagnosticsStatusNotification => {
Self::DiagnosticsStatusNotification(crate::decode::decode_payload::<
DiagnosticsStatusNotificationRequest,
>(payload, options)?)
}
Action::FirmwareStatusNotification => {
Self::FirmwareStatusNotification(crate::decode::decode_payload::<
FirmwareStatusNotificationRequest,
>(payload, options)?)
}
Action::Heartbeat => Self::Heartbeat(
crate::decode::decode_payload::<HeartbeatRequest>(payload, options)?,
),
Action::LogStatusNotification => {
Self::LogStatusNotification(crate::decode::decode_payload::<
LogStatusNotificationRequest,
>(payload, options)?)
}
Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
MeterValuesRequest,
>(payload, options)?),
Action::SecurityEventNotification => {
Self::SecurityEventNotification(crate::decode::decode_payload::<
SecurityEventNotificationRequest,
>(payload, options)?)
}
Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
SignCertificateRequest,
>(payload, options)?),
Action::SignedFirmwareStatusNotification => {
Self::SignedFirmwareStatusNotification(crate::decode::decode_payload::<
SignedFirmwareStatusNotificationRequest,
>(payload, options)?)
}
Action::StartTransaction => Self::StartTransaction(crate::decode::decode_payload::<
StartTransactionRequest,
>(payload, options)?),
Action::StatusNotification => Self::StatusNotification(
crate::decode::decode_payload::<StatusNotificationRequest>(payload, options)?,
),
Action::StopTransaction => Self::StopTransaction(crate::decode::decode_payload::<
StopTransactionRequest,
>(payload, options)?),
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn decode_reporting(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<crate::decode::Decoded<Self>, DecodeError> {
Ok(match action {
Action::Authorize => {
crate::decode::decode_payload_reporting::<AuthorizeRequest>(payload, options)?
.map(Self::Authorize)
}
Action::BootNotification => crate::decode::decode_payload_reporting::<
BootNotificationRequest,
>(payload, options)?
.map(Self::BootNotification),
Action::DataTransfer => {
crate::decode::decode_payload_reporting::<DataTransferRequest>(payload, options)?
.map(Self::DataTransfer)
}
Action::DiagnosticsStatusNotification => crate::decode::decode_payload_reporting::<
DiagnosticsStatusNotificationRequest,
>(payload, options)?
.map(Self::DiagnosticsStatusNotification),
Action::FirmwareStatusNotification => crate::decode::decode_payload_reporting::<
FirmwareStatusNotificationRequest,
>(payload, options)?
.map(Self::FirmwareStatusNotification),
Action::Heartbeat => {
crate::decode::decode_payload_reporting::<HeartbeatRequest>(payload, options)?
.map(Self::Heartbeat)
}
Action::LogStatusNotification => crate::decode::decode_payload_reporting::<
LogStatusNotificationRequest,
>(payload, options)?
.map(Self::LogStatusNotification),
Action::MeterValues => {
crate::decode::decode_payload_reporting::<MeterValuesRequest>(payload, options)?
.map(Self::MeterValues)
}
Action::SecurityEventNotification => crate::decode::decode_payload_reporting::<
SecurityEventNotificationRequest,
>(payload, options)?
.map(Self::SecurityEventNotification),
Action::SignCertificate => {
crate::decode::decode_payload_reporting::<SignCertificateRequest>(payload, options)?
.map(Self::SignCertificate)
}
Action::SignedFirmwareStatusNotification => crate::decode::decode_payload_reporting::<
SignedFirmwareStatusNotificationRequest,
>(payload, options)?
.map(Self::SignedFirmwareStatusNotification),
Action::StartTransaction => crate::decode::decode_payload_reporting::<
StartTransactionRequest,
>(payload, options)?
.map(Self::StartTransaction),
Action::StatusNotification => crate::decode::decode_payload_reporting::<
StatusNotificationRequest,
>(payload, options)?
.map(Self::StatusNotification),
Action::StopTransaction => {
crate::decode::decode_payload_reporting::<StopTransactionRequest>(payload, options)?
.map(Self::StopTransaction)
}
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
match self {
Self::Authorize(p) => serde_json::to_string(p),
Self::BootNotification(p) => serde_json::to_string(p),
Self::DataTransfer(p) => serde_json::to_string(p),
Self::DiagnosticsStatusNotification(p) => serde_json::to_string(p),
Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
Self::Heartbeat(p) => serde_json::to_string(p),
Self::LogStatusNotification(p) => serde_json::to_string(p),
Self::MeterValues(p) => serde_json::to_string(p),
Self::SecurityEventNotification(p) => serde_json::to_string(p),
Self::SignCertificate(p) => serde_json::to_string(p),
Self::SignedFirmwareStatusNotification(p) => serde_json::to_string(p),
Self::StartTransaction(p) => serde_json::to_string(p),
Self::StatusNotification(p) => serde_json::to_string(p),
Self::StopTransaction(p) => serde_json::to_string(p),
}
}
}
impl Validate for CsRequest {
fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
match self {
Self::Authorize(p) => p.validate_at(path, out),
Self::BootNotification(p) => p.validate_at(path, out),
Self::DataTransfer(p) => p.validate_at(path, out),
Self::DiagnosticsStatusNotification(p) => p.validate_at(path, out),
Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
Self::Heartbeat(p) => p.validate_at(path, out),
Self::LogStatusNotification(p) => p.validate_at(path, out),
Self::MeterValues(p) => p.validate_at(path, out),
Self::SecurityEventNotification(p) => p.validate_at(path, out),
Self::SignCertificate(p) => p.validate_at(path, out),
Self::SignedFirmwareStatusNotification(p) => p.validate_at(path, out),
Self::StartTransaction(p) => p.validate_at(path, out),
Self::StatusNotification(p) => p.validate_at(path, out),
Self::StopTransaction(p) => p.validate_at(path, out),
}
}
}
impl serde::Serialize for CsRequest {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self {
Self::Authorize(p) => p.serialize(ser),
Self::BootNotification(p) => p.serialize(ser),
Self::DataTransfer(p) => p.serialize(ser),
Self::DiagnosticsStatusNotification(p) => p.serialize(ser),
Self::FirmwareStatusNotification(p) => p.serialize(ser),
Self::Heartbeat(p) => p.serialize(ser),
Self::LogStatusNotification(p) => p.serialize(ser),
Self::MeterValues(p) => p.serialize(ser),
Self::SecurityEventNotification(p) => p.serialize(ser),
Self::SignCertificate(p) => p.serialize(ser),
Self::SignedFirmwareStatusNotification(p) => p.serialize(ser),
Self::StartTransaction(p) => p.serialize(ser),
Self::StatusNotification(p) => p.serialize(ser),
Self::StopTransaction(p) => p.serialize(ser),
}
}
}
impl crate::message::Sealed for CsRequest {}
impl crate::message::DecodeRequest for CsRequest {
type Action = Action;
fn decode_reporting(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<crate::decode::Decoded<Self>, DecodeError> {
CsRequest::decode_reporting(action, payload, options)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum CsResponse {
Authorize(AuthorizeResponse),
BootNotification(BootNotificationResponse),
DataTransfer(DataTransferResponse),
DiagnosticsStatusNotification(DiagnosticsStatusNotificationResponse),
FirmwareStatusNotification(FirmwareStatusNotificationResponse),
Heartbeat(HeartbeatResponse),
LogStatusNotification(LogStatusNotificationResponse),
MeterValues(MeterValuesResponse),
SecurityEventNotification(SecurityEventNotificationResponse),
SignCertificate(SignCertificateResponse),
SignedFirmwareStatusNotification(SignedFirmwareStatusNotificationResponse),
StartTransaction(StartTransactionResponse),
StatusNotification(StatusNotificationResponse),
StopTransaction(StopTransactionResponse),
}
impl CsResponse {
#[must_use]
pub const fn action(&self) -> Action {
match self {
Self::Authorize(_) => Action::Authorize,
Self::BootNotification(_) => Action::BootNotification,
Self::DataTransfer(_) => Action::DataTransfer,
Self::DiagnosticsStatusNotification(_) => Action::DiagnosticsStatusNotification,
Self::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
Self::Heartbeat(_) => Action::Heartbeat,
Self::LogStatusNotification(_) => Action::LogStatusNotification,
Self::MeterValues(_) => Action::MeterValues,
Self::SecurityEventNotification(_) => Action::SecurityEventNotification,
Self::SignCertificate(_) => Action::SignCertificate,
Self::SignedFirmwareStatusNotification(_) => Action::SignedFirmwareStatusNotification,
Self::StartTransaction(_) => Action::StartTransaction,
Self::StatusNotification(_) => Action::StatusNotification,
Self::StopTransaction(_) => Action::StopTransaction,
}
}
pub fn decode(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<Self, DecodeError> {
Ok(match action {
Action::Authorize => Self::Authorize(
crate::decode::decode_payload::<AuthorizeResponse>(payload, options)?,
),
Action::BootNotification => Self::BootNotification(crate::decode::decode_payload::<
BootNotificationResponse,
>(payload, options)?),
Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
DataTransferResponse,
>(payload, options)?),
Action::DiagnosticsStatusNotification => {
Self::DiagnosticsStatusNotification(crate::decode::decode_payload::<
DiagnosticsStatusNotificationResponse,
>(payload, options)?)
}
Action::FirmwareStatusNotification => {
Self::FirmwareStatusNotification(crate::decode::decode_payload::<
FirmwareStatusNotificationResponse,
>(payload, options)?)
}
Action::Heartbeat => Self::Heartbeat(
crate::decode::decode_payload::<HeartbeatResponse>(payload, options)?,
),
Action::LogStatusNotification => {
Self::LogStatusNotification(crate::decode::decode_payload::<
LogStatusNotificationResponse,
>(payload, options)?)
}
Action::MeterValues => Self::MeterValues(crate::decode::decode_payload::<
MeterValuesResponse,
>(payload, options)?),
Action::SecurityEventNotification => {
Self::SecurityEventNotification(crate::decode::decode_payload::<
SecurityEventNotificationResponse,
>(payload, options)?)
}
Action::SignCertificate => Self::SignCertificate(crate::decode::decode_payload::<
SignCertificateResponse,
>(payload, options)?),
Action::SignedFirmwareStatusNotification => {
Self::SignedFirmwareStatusNotification(crate::decode::decode_payload::<
SignedFirmwareStatusNotificationResponse,
>(payload, options)?)
}
Action::StartTransaction => Self::StartTransaction(crate::decode::decode_payload::<
StartTransactionResponse,
>(payload, options)?),
Action::StatusNotification => Self::StatusNotification(
crate::decode::decode_payload::<StatusNotificationResponse>(payload, options)?,
),
Action::StopTransaction => Self::StopTransaction(crate::decode::decode_payload::<
StopTransactionResponse,
>(payload, options)?),
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
match self {
Self::Authorize(p) => serde_json::to_string(p),
Self::BootNotification(p) => serde_json::to_string(p),
Self::DataTransfer(p) => serde_json::to_string(p),
Self::DiagnosticsStatusNotification(p) => serde_json::to_string(p),
Self::FirmwareStatusNotification(p) => serde_json::to_string(p),
Self::Heartbeat(p) => serde_json::to_string(p),
Self::LogStatusNotification(p) => serde_json::to_string(p),
Self::MeterValues(p) => serde_json::to_string(p),
Self::SecurityEventNotification(p) => serde_json::to_string(p),
Self::SignCertificate(p) => serde_json::to_string(p),
Self::SignedFirmwareStatusNotification(p) => serde_json::to_string(p),
Self::StartTransaction(p) => serde_json::to_string(p),
Self::StatusNotification(p) => serde_json::to_string(p),
Self::StopTransaction(p) => serde_json::to_string(p),
}
}
}
impl Validate for CsResponse {
fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
match self {
Self::Authorize(p) => p.validate_at(path, out),
Self::BootNotification(p) => p.validate_at(path, out),
Self::DataTransfer(p) => p.validate_at(path, out),
Self::DiagnosticsStatusNotification(p) => p.validate_at(path, out),
Self::FirmwareStatusNotification(p) => p.validate_at(path, out),
Self::Heartbeat(p) => p.validate_at(path, out),
Self::LogStatusNotification(p) => p.validate_at(path, out),
Self::MeterValues(p) => p.validate_at(path, out),
Self::SecurityEventNotification(p) => p.validate_at(path, out),
Self::SignCertificate(p) => p.validate_at(path, out),
Self::SignedFirmwareStatusNotification(p) => p.validate_at(path, out),
Self::StartTransaction(p) => p.validate_at(path, out),
Self::StatusNotification(p) => p.validate_at(path, out),
Self::StopTransaction(p) => p.validate_at(path, out),
}
}
}
impl serde::Serialize for CsResponse {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self {
Self::Authorize(p) => p.serialize(ser),
Self::BootNotification(p) => p.serialize(ser),
Self::DataTransfer(p) => p.serialize(ser),
Self::DiagnosticsStatusNotification(p) => p.serialize(ser),
Self::FirmwareStatusNotification(p) => p.serialize(ser),
Self::Heartbeat(p) => p.serialize(ser),
Self::LogStatusNotification(p) => p.serialize(ser),
Self::MeterValues(p) => p.serialize(ser),
Self::SecurityEventNotification(p) => p.serialize(ser),
Self::SignCertificate(p) => p.serialize(ser),
Self::SignedFirmwareStatusNotification(p) => p.serialize(ser),
Self::StartTransaction(p) => p.serialize(ser),
Self::StatusNotification(p) => p.serialize(ser),
Self::StopTransaction(p) => p.serialize(ser),
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum CsmsRequest {
CancelReservation(CancelReservationRequest),
CertificateSigned(CertificateSignedRequest),
ChangeAvailability(ChangeAvailabilityRequest),
ChangeConfiguration(ChangeConfigurationRequest),
ClearCache(ClearCacheRequest),
ClearChargingProfile(ClearChargingProfileRequest),
DataTransfer(DataTransferRequest),
DeleteCertificate(DeleteCertificateRequest),
ExtendedTriggerMessage(ExtendedTriggerMessageRequest),
GetCompositeSchedule(GetCompositeScheduleRequest),
GetConfiguration(GetConfigurationRequest),
GetDiagnostics(GetDiagnosticsRequest),
GetInstalledCertificateIds(GetInstalledCertificateIdsRequest),
GetLocalListVersion(GetLocalListVersionRequest),
GetLog(GetLogRequest),
InstallCertificate(InstallCertificateRequest),
RemoteStartTransaction(RemoteStartTransactionRequest),
RemoteStopTransaction(RemoteStopTransactionRequest),
ReserveNow(ReserveNowRequest),
Reset(ResetRequest),
SendLocalList(SendLocalListRequest),
SetChargingProfile(SetChargingProfileRequest),
SignedUpdateFirmware(SignedUpdateFirmwareRequest),
TriggerMessage(TriggerMessageRequest),
UnlockConnector(UnlockConnectorRequest),
UpdateFirmware(UpdateFirmwareRequest),
}
impl CsmsRequest {
#[must_use]
pub const fn action(&self) -> Action {
match self {
Self::CancelReservation(_) => Action::CancelReservation,
Self::CertificateSigned(_) => Action::CertificateSigned,
Self::ChangeAvailability(_) => Action::ChangeAvailability,
Self::ChangeConfiguration(_) => Action::ChangeConfiguration,
Self::ClearCache(_) => Action::ClearCache,
Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
Self::DataTransfer(_) => Action::DataTransfer,
Self::DeleteCertificate(_) => Action::DeleteCertificate,
Self::ExtendedTriggerMessage(_) => Action::ExtendedTriggerMessage,
Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
Self::GetConfiguration(_) => Action::GetConfiguration,
Self::GetDiagnostics(_) => Action::GetDiagnostics,
Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
Self::GetLog(_) => Action::GetLog,
Self::InstallCertificate(_) => Action::InstallCertificate,
Self::RemoteStartTransaction(_) => Action::RemoteStartTransaction,
Self::RemoteStopTransaction(_) => Action::RemoteStopTransaction,
Self::ReserveNow(_) => Action::ReserveNow,
Self::Reset(_) => Action::Reset,
Self::SendLocalList(_) => Action::SendLocalList,
Self::SetChargingProfile(_) => Action::SetChargingProfile,
Self::SignedUpdateFirmware(_) => Action::SignedUpdateFirmware,
Self::TriggerMessage(_) => Action::TriggerMessage,
Self::UnlockConnector(_) => Action::UnlockConnector,
Self::UpdateFirmware(_) => Action::UpdateFirmware,
}
}
pub fn decode(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<Self, DecodeError> {
Ok(match action {
Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
CancelReservationRequest,
>(payload, options)?),
Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
CertificateSignedRequest,
>(payload, options)?),
Action::ChangeAvailability => Self::ChangeAvailability(
crate::decode::decode_payload::<ChangeAvailabilityRequest>(payload, options)?,
),
Action::ChangeConfiguration => {
Self::ChangeConfiguration(crate::decode::decode_payload::<
ChangeConfigurationRequest,
>(payload, options)?)
}
Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
ClearCacheRequest,
>(payload, options)?),
Action::ClearChargingProfile => {
Self::ClearChargingProfile(crate::decode::decode_payload::<
ClearChargingProfileRequest,
>(payload, options)?)
}
Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
DataTransferRequest,
>(payload, options)?),
Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
DeleteCertificateRequest,
>(payload, options)?),
Action::ExtendedTriggerMessage => {
Self::ExtendedTriggerMessage(crate::decode::decode_payload::<
ExtendedTriggerMessageRequest,
>(payload, options)?)
}
Action::GetCompositeSchedule => {
Self::GetCompositeSchedule(crate::decode::decode_payload::<
GetCompositeScheduleRequest,
>(payload, options)?)
}
Action::GetConfiguration => Self::GetConfiguration(crate::decode::decode_payload::<
GetConfigurationRequest,
>(payload, options)?),
Action::GetDiagnostics => Self::GetDiagnostics(crate::decode::decode_payload::<
GetDiagnosticsRequest,
>(payload, options)?),
Action::GetInstalledCertificateIds => {
Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
GetInstalledCertificateIdsRequest,
>(payload, options)?)
}
Action::GetLocalListVersion => {
Self::GetLocalListVersion(crate::decode::decode_payload::<
GetLocalListVersionRequest,
>(payload, options)?)
}
Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogRequest>(
payload, options,
)?),
Action::InstallCertificate => Self::InstallCertificate(
crate::decode::decode_payload::<InstallCertificateRequest>(payload, options)?,
),
Action::RemoteStartTransaction => {
Self::RemoteStartTransaction(crate::decode::decode_payload::<
RemoteStartTransactionRequest,
>(payload, options)?)
}
Action::RemoteStopTransaction => {
Self::RemoteStopTransaction(crate::decode::decode_payload::<
RemoteStopTransactionRequest,
>(payload, options)?)
}
Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
ReserveNowRequest,
>(payload, options)?),
Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetRequest>(
payload, options,
)?),
Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
SendLocalListRequest,
>(payload, options)?),
Action::SetChargingProfile => Self::SetChargingProfile(
crate::decode::decode_payload::<SetChargingProfileRequest>(payload, options)?,
),
Action::SignedUpdateFirmware => {
Self::SignedUpdateFirmware(crate::decode::decode_payload::<
SignedUpdateFirmwareRequest,
>(payload, options)?)
}
Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
TriggerMessageRequest,
>(payload, options)?),
Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
UnlockConnectorRequest,
>(payload, options)?),
Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
UpdateFirmwareRequest,
>(payload, options)?),
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn decode_reporting(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<crate::decode::Decoded<Self>, DecodeError> {
Ok(match action {
Action::CancelReservation => crate::decode::decode_payload_reporting::<
CancelReservationRequest,
>(payload, options)?
.map(Self::CancelReservation),
Action::CertificateSigned => crate::decode::decode_payload_reporting::<
CertificateSignedRequest,
>(payload, options)?
.map(Self::CertificateSigned),
Action::ChangeAvailability => crate::decode::decode_payload_reporting::<
ChangeAvailabilityRequest,
>(payload, options)?
.map(Self::ChangeAvailability),
Action::ChangeConfiguration => crate::decode::decode_payload_reporting::<
ChangeConfigurationRequest,
>(payload, options)?
.map(Self::ChangeConfiguration),
Action::ClearCache => {
crate::decode::decode_payload_reporting::<ClearCacheRequest>(payload, options)?
.map(Self::ClearCache)
}
Action::ClearChargingProfile => crate::decode::decode_payload_reporting::<
ClearChargingProfileRequest,
>(payload, options)?
.map(Self::ClearChargingProfile),
Action::DataTransfer => {
crate::decode::decode_payload_reporting::<DataTransferRequest>(payload, options)?
.map(Self::DataTransfer)
}
Action::DeleteCertificate => crate::decode::decode_payload_reporting::<
DeleteCertificateRequest,
>(payload, options)?
.map(Self::DeleteCertificate),
Action::ExtendedTriggerMessage => crate::decode::decode_payload_reporting::<
ExtendedTriggerMessageRequest,
>(payload, options)?
.map(Self::ExtendedTriggerMessage),
Action::GetCompositeSchedule => crate::decode::decode_payload_reporting::<
GetCompositeScheduleRequest,
>(payload, options)?
.map(Self::GetCompositeSchedule),
Action::GetConfiguration => crate::decode::decode_payload_reporting::<
GetConfigurationRequest,
>(payload, options)?
.map(Self::GetConfiguration),
Action::GetDiagnostics => {
crate::decode::decode_payload_reporting::<GetDiagnosticsRequest>(payload, options)?
.map(Self::GetDiagnostics)
}
Action::GetInstalledCertificateIds => crate::decode::decode_payload_reporting::<
GetInstalledCertificateIdsRequest,
>(payload, options)?
.map(Self::GetInstalledCertificateIds),
Action::GetLocalListVersion => crate::decode::decode_payload_reporting::<
GetLocalListVersionRequest,
>(payload, options)?
.map(Self::GetLocalListVersion),
Action::GetLog => {
crate::decode::decode_payload_reporting::<GetLogRequest>(payload, options)?
.map(Self::GetLog)
}
Action::InstallCertificate => crate::decode::decode_payload_reporting::<
InstallCertificateRequest,
>(payload, options)?
.map(Self::InstallCertificate),
Action::RemoteStartTransaction => crate::decode::decode_payload_reporting::<
RemoteStartTransactionRequest,
>(payload, options)?
.map(Self::RemoteStartTransaction),
Action::RemoteStopTransaction => crate::decode::decode_payload_reporting::<
RemoteStopTransactionRequest,
>(payload, options)?
.map(Self::RemoteStopTransaction),
Action::ReserveNow => {
crate::decode::decode_payload_reporting::<ReserveNowRequest>(payload, options)?
.map(Self::ReserveNow)
}
Action::Reset => {
crate::decode::decode_payload_reporting::<ResetRequest>(payload, options)?
.map(Self::Reset)
}
Action::SendLocalList => {
crate::decode::decode_payload_reporting::<SendLocalListRequest>(payload, options)?
.map(Self::SendLocalList)
}
Action::SetChargingProfile => crate::decode::decode_payload_reporting::<
SetChargingProfileRequest,
>(payload, options)?
.map(Self::SetChargingProfile),
Action::SignedUpdateFirmware => crate::decode::decode_payload_reporting::<
SignedUpdateFirmwareRequest,
>(payload, options)?
.map(Self::SignedUpdateFirmware),
Action::TriggerMessage => {
crate::decode::decode_payload_reporting::<TriggerMessageRequest>(payload, options)?
.map(Self::TriggerMessage)
}
Action::UnlockConnector => {
crate::decode::decode_payload_reporting::<UnlockConnectorRequest>(payload, options)?
.map(Self::UnlockConnector)
}
Action::UpdateFirmware => {
crate::decode::decode_payload_reporting::<UpdateFirmwareRequest>(payload, options)?
.map(Self::UpdateFirmware)
}
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
match self {
Self::CancelReservation(p) => serde_json::to_string(p),
Self::CertificateSigned(p) => serde_json::to_string(p),
Self::ChangeAvailability(p) => serde_json::to_string(p),
Self::ChangeConfiguration(p) => serde_json::to_string(p),
Self::ClearCache(p) => serde_json::to_string(p),
Self::ClearChargingProfile(p) => serde_json::to_string(p),
Self::DataTransfer(p) => serde_json::to_string(p),
Self::DeleteCertificate(p) => serde_json::to_string(p),
Self::ExtendedTriggerMessage(p) => serde_json::to_string(p),
Self::GetCompositeSchedule(p) => serde_json::to_string(p),
Self::GetConfiguration(p) => serde_json::to_string(p),
Self::GetDiagnostics(p) => serde_json::to_string(p),
Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
Self::GetLocalListVersion(p) => serde_json::to_string(p),
Self::GetLog(p) => serde_json::to_string(p),
Self::InstallCertificate(p) => serde_json::to_string(p),
Self::RemoteStartTransaction(p) => serde_json::to_string(p),
Self::RemoteStopTransaction(p) => serde_json::to_string(p),
Self::ReserveNow(p) => serde_json::to_string(p),
Self::Reset(p) => serde_json::to_string(p),
Self::SendLocalList(p) => serde_json::to_string(p),
Self::SetChargingProfile(p) => serde_json::to_string(p),
Self::SignedUpdateFirmware(p) => serde_json::to_string(p),
Self::TriggerMessage(p) => serde_json::to_string(p),
Self::UnlockConnector(p) => serde_json::to_string(p),
Self::UpdateFirmware(p) => serde_json::to_string(p),
}
}
}
impl Validate for CsmsRequest {
fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
match self {
Self::CancelReservation(p) => p.validate_at(path, out),
Self::CertificateSigned(p) => p.validate_at(path, out),
Self::ChangeAvailability(p) => p.validate_at(path, out),
Self::ChangeConfiguration(p) => p.validate_at(path, out),
Self::ClearCache(p) => p.validate_at(path, out),
Self::ClearChargingProfile(p) => p.validate_at(path, out),
Self::DataTransfer(p) => p.validate_at(path, out),
Self::DeleteCertificate(p) => p.validate_at(path, out),
Self::ExtendedTriggerMessage(p) => p.validate_at(path, out),
Self::GetCompositeSchedule(p) => p.validate_at(path, out),
Self::GetConfiguration(p) => p.validate_at(path, out),
Self::GetDiagnostics(p) => p.validate_at(path, out),
Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
Self::GetLocalListVersion(p) => p.validate_at(path, out),
Self::GetLog(p) => p.validate_at(path, out),
Self::InstallCertificate(p) => p.validate_at(path, out),
Self::RemoteStartTransaction(p) => p.validate_at(path, out),
Self::RemoteStopTransaction(p) => p.validate_at(path, out),
Self::ReserveNow(p) => p.validate_at(path, out),
Self::Reset(p) => p.validate_at(path, out),
Self::SendLocalList(p) => p.validate_at(path, out),
Self::SetChargingProfile(p) => p.validate_at(path, out),
Self::SignedUpdateFirmware(p) => p.validate_at(path, out),
Self::TriggerMessage(p) => p.validate_at(path, out),
Self::UnlockConnector(p) => p.validate_at(path, out),
Self::UpdateFirmware(p) => p.validate_at(path, out),
}
}
}
impl serde::Serialize for CsmsRequest {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self {
Self::CancelReservation(p) => p.serialize(ser),
Self::CertificateSigned(p) => p.serialize(ser),
Self::ChangeAvailability(p) => p.serialize(ser),
Self::ChangeConfiguration(p) => p.serialize(ser),
Self::ClearCache(p) => p.serialize(ser),
Self::ClearChargingProfile(p) => p.serialize(ser),
Self::DataTransfer(p) => p.serialize(ser),
Self::DeleteCertificate(p) => p.serialize(ser),
Self::ExtendedTriggerMessage(p) => p.serialize(ser),
Self::GetCompositeSchedule(p) => p.serialize(ser),
Self::GetConfiguration(p) => p.serialize(ser),
Self::GetDiagnostics(p) => p.serialize(ser),
Self::GetInstalledCertificateIds(p) => p.serialize(ser),
Self::GetLocalListVersion(p) => p.serialize(ser),
Self::GetLog(p) => p.serialize(ser),
Self::InstallCertificate(p) => p.serialize(ser),
Self::RemoteStartTransaction(p) => p.serialize(ser),
Self::RemoteStopTransaction(p) => p.serialize(ser),
Self::ReserveNow(p) => p.serialize(ser),
Self::Reset(p) => p.serialize(ser),
Self::SendLocalList(p) => p.serialize(ser),
Self::SetChargingProfile(p) => p.serialize(ser),
Self::SignedUpdateFirmware(p) => p.serialize(ser),
Self::TriggerMessage(p) => p.serialize(ser),
Self::UnlockConnector(p) => p.serialize(ser),
Self::UpdateFirmware(p) => p.serialize(ser),
}
}
}
impl crate::message::Sealed for CsmsRequest {}
impl crate::message::DecodeRequest for CsmsRequest {
type Action = Action;
fn decode_reporting(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<crate::decode::Decoded<Self>, DecodeError> {
CsmsRequest::decode_reporting(action, payload, options)
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)]
pub enum CsmsResponse {
CancelReservation(CancelReservationResponse),
CertificateSigned(CertificateSignedResponse),
ChangeAvailability(ChangeAvailabilityResponse),
ChangeConfiguration(ChangeConfigurationResponse),
ClearCache(ClearCacheResponse),
ClearChargingProfile(ClearChargingProfileResponse),
DataTransfer(DataTransferResponse),
DeleteCertificate(DeleteCertificateResponse),
ExtendedTriggerMessage(ExtendedTriggerMessageResponse),
GetCompositeSchedule(GetCompositeScheduleResponse),
GetConfiguration(GetConfigurationResponse),
GetDiagnostics(GetDiagnosticsResponse),
GetInstalledCertificateIds(GetInstalledCertificateIdsResponse),
GetLocalListVersion(GetLocalListVersionResponse),
GetLog(GetLogResponse),
InstallCertificate(InstallCertificateResponse),
RemoteStartTransaction(RemoteStartTransactionResponse),
RemoteStopTransaction(RemoteStopTransactionResponse),
ReserveNow(ReserveNowResponse),
Reset(ResetResponse),
SendLocalList(SendLocalListResponse),
SetChargingProfile(SetChargingProfileResponse),
SignedUpdateFirmware(SignedUpdateFirmwareResponse),
TriggerMessage(TriggerMessageResponse),
UnlockConnector(UnlockConnectorResponse),
UpdateFirmware(UpdateFirmwareResponse),
}
impl CsmsResponse {
#[must_use]
pub const fn action(&self) -> Action {
match self {
Self::CancelReservation(_) => Action::CancelReservation,
Self::CertificateSigned(_) => Action::CertificateSigned,
Self::ChangeAvailability(_) => Action::ChangeAvailability,
Self::ChangeConfiguration(_) => Action::ChangeConfiguration,
Self::ClearCache(_) => Action::ClearCache,
Self::ClearChargingProfile(_) => Action::ClearChargingProfile,
Self::DataTransfer(_) => Action::DataTransfer,
Self::DeleteCertificate(_) => Action::DeleteCertificate,
Self::ExtendedTriggerMessage(_) => Action::ExtendedTriggerMessage,
Self::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
Self::GetConfiguration(_) => Action::GetConfiguration,
Self::GetDiagnostics(_) => Action::GetDiagnostics,
Self::GetInstalledCertificateIds(_) => Action::GetInstalledCertificateIds,
Self::GetLocalListVersion(_) => Action::GetLocalListVersion,
Self::GetLog(_) => Action::GetLog,
Self::InstallCertificate(_) => Action::InstallCertificate,
Self::RemoteStartTransaction(_) => Action::RemoteStartTransaction,
Self::RemoteStopTransaction(_) => Action::RemoteStopTransaction,
Self::ReserveNow(_) => Action::ReserveNow,
Self::Reset(_) => Action::Reset,
Self::SendLocalList(_) => Action::SendLocalList,
Self::SetChargingProfile(_) => Action::SetChargingProfile,
Self::SignedUpdateFirmware(_) => Action::SignedUpdateFirmware,
Self::TriggerMessage(_) => Action::TriggerMessage,
Self::UnlockConnector(_) => Action::UnlockConnector,
Self::UpdateFirmware(_) => Action::UpdateFirmware,
}
}
pub fn decode(
action: Action,
payload: &RawValue,
options: &DecodeOptions,
) -> Result<Self, DecodeError> {
Ok(match action {
Action::CancelReservation => Self::CancelReservation(crate::decode::decode_payload::<
CancelReservationResponse,
>(payload, options)?),
Action::CertificateSigned => Self::CertificateSigned(crate::decode::decode_payload::<
CertificateSignedResponse,
>(payload, options)?),
Action::ChangeAvailability => Self::ChangeAvailability(
crate::decode::decode_payload::<ChangeAvailabilityResponse>(payload, options)?,
),
Action::ChangeConfiguration => {
Self::ChangeConfiguration(crate::decode::decode_payload::<
ChangeConfigurationResponse,
>(payload, options)?)
}
Action::ClearCache => Self::ClearCache(crate::decode::decode_payload::<
ClearCacheResponse,
>(payload, options)?),
Action::ClearChargingProfile => {
Self::ClearChargingProfile(crate::decode::decode_payload::<
ClearChargingProfileResponse,
>(payload, options)?)
}
Action::DataTransfer => Self::DataTransfer(crate::decode::decode_payload::<
DataTransferResponse,
>(payload, options)?),
Action::DeleteCertificate => Self::DeleteCertificate(crate::decode::decode_payload::<
DeleteCertificateResponse,
>(payload, options)?),
Action::ExtendedTriggerMessage => {
Self::ExtendedTriggerMessage(crate::decode::decode_payload::<
ExtendedTriggerMessageResponse,
>(payload, options)?)
}
Action::GetCompositeSchedule => {
Self::GetCompositeSchedule(crate::decode::decode_payload::<
GetCompositeScheduleResponse,
>(payload, options)?)
}
Action::GetConfiguration => Self::GetConfiguration(crate::decode::decode_payload::<
GetConfigurationResponse,
>(payload, options)?),
Action::GetDiagnostics => Self::GetDiagnostics(crate::decode::decode_payload::<
GetDiagnosticsResponse,
>(payload, options)?),
Action::GetInstalledCertificateIds => {
Self::GetInstalledCertificateIds(crate::decode::decode_payload::<
GetInstalledCertificateIdsResponse,
>(payload, options)?)
}
Action::GetLocalListVersion => {
Self::GetLocalListVersion(crate::decode::decode_payload::<
GetLocalListVersionResponse,
>(payload, options)?)
}
Action::GetLog => Self::GetLog(crate::decode::decode_payload::<GetLogResponse>(
payload, options,
)?),
Action::InstallCertificate => Self::InstallCertificate(
crate::decode::decode_payload::<InstallCertificateResponse>(payload, options)?,
),
Action::RemoteStartTransaction => {
Self::RemoteStartTransaction(crate::decode::decode_payload::<
RemoteStartTransactionResponse,
>(payload, options)?)
}
Action::RemoteStopTransaction => {
Self::RemoteStopTransaction(crate::decode::decode_payload::<
RemoteStopTransactionResponse,
>(payload, options)?)
}
Action::ReserveNow => Self::ReserveNow(crate::decode::decode_payload::<
ReserveNowResponse,
>(payload, options)?),
Action::Reset => Self::Reset(crate::decode::decode_payload::<ResetResponse>(
payload, options,
)?),
Action::SendLocalList => Self::SendLocalList(crate::decode::decode_payload::<
SendLocalListResponse,
>(payload, options)?),
Action::SetChargingProfile => Self::SetChargingProfile(
crate::decode::decode_payload::<SetChargingProfileResponse>(payload, options)?,
),
Action::SignedUpdateFirmware => {
Self::SignedUpdateFirmware(crate::decode::decode_payload::<
SignedUpdateFirmwareResponse,
>(payload, options)?)
}
Action::TriggerMessage => Self::TriggerMessage(crate::decode::decode_payload::<
TriggerMessageResponse,
>(payload, options)?),
Action::UnlockConnector => Self::UnlockConnector(crate::decode::decode_payload::<
UnlockConnectorResponse,
>(payload, options)?),
Action::UpdateFirmware => Self::UpdateFirmware(crate::decode::decode_payload::<
UpdateFirmwareResponse,
>(payload, options)?),
other => return Err(DecodeError::unsupported_action(other.as_str())),
})
}
pub fn to_json(&self) -> Result<alloc::string::String, serde_json::Error> {
match self {
Self::CancelReservation(p) => serde_json::to_string(p),
Self::CertificateSigned(p) => serde_json::to_string(p),
Self::ChangeAvailability(p) => serde_json::to_string(p),
Self::ChangeConfiguration(p) => serde_json::to_string(p),
Self::ClearCache(p) => serde_json::to_string(p),
Self::ClearChargingProfile(p) => serde_json::to_string(p),
Self::DataTransfer(p) => serde_json::to_string(p),
Self::DeleteCertificate(p) => serde_json::to_string(p),
Self::ExtendedTriggerMessage(p) => serde_json::to_string(p),
Self::GetCompositeSchedule(p) => serde_json::to_string(p),
Self::GetConfiguration(p) => serde_json::to_string(p),
Self::GetDiagnostics(p) => serde_json::to_string(p),
Self::GetInstalledCertificateIds(p) => serde_json::to_string(p),
Self::GetLocalListVersion(p) => serde_json::to_string(p),
Self::GetLog(p) => serde_json::to_string(p),
Self::InstallCertificate(p) => serde_json::to_string(p),
Self::RemoteStartTransaction(p) => serde_json::to_string(p),
Self::RemoteStopTransaction(p) => serde_json::to_string(p),
Self::ReserveNow(p) => serde_json::to_string(p),
Self::Reset(p) => serde_json::to_string(p),
Self::SendLocalList(p) => serde_json::to_string(p),
Self::SetChargingProfile(p) => serde_json::to_string(p),
Self::SignedUpdateFirmware(p) => serde_json::to_string(p),
Self::TriggerMessage(p) => serde_json::to_string(p),
Self::UnlockConnector(p) => serde_json::to_string(p),
Self::UpdateFirmware(p) => serde_json::to_string(p),
}
}
}
impl Validate for CsmsResponse {
fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
match self {
Self::CancelReservation(p) => p.validate_at(path, out),
Self::CertificateSigned(p) => p.validate_at(path, out),
Self::ChangeAvailability(p) => p.validate_at(path, out),
Self::ChangeConfiguration(p) => p.validate_at(path, out),
Self::ClearCache(p) => p.validate_at(path, out),
Self::ClearChargingProfile(p) => p.validate_at(path, out),
Self::DataTransfer(p) => p.validate_at(path, out),
Self::DeleteCertificate(p) => p.validate_at(path, out),
Self::ExtendedTriggerMessage(p) => p.validate_at(path, out),
Self::GetCompositeSchedule(p) => p.validate_at(path, out),
Self::GetConfiguration(p) => p.validate_at(path, out),
Self::GetDiagnostics(p) => p.validate_at(path, out),
Self::GetInstalledCertificateIds(p) => p.validate_at(path, out),
Self::GetLocalListVersion(p) => p.validate_at(path, out),
Self::GetLog(p) => p.validate_at(path, out),
Self::InstallCertificate(p) => p.validate_at(path, out),
Self::RemoteStartTransaction(p) => p.validate_at(path, out),
Self::RemoteStopTransaction(p) => p.validate_at(path, out),
Self::ReserveNow(p) => p.validate_at(path, out),
Self::Reset(p) => p.validate_at(path, out),
Self::SendLocalList(p) => p.validate_at(path, out),
Self::SetChargingProfile(p) => p.validate_at(path, out),
Self::SignedUpdateFirmware(p) => p.validate_at(path, out),
Self::TriggerMessage(p) => p.validate_at(path, out),
Self::UnlockConnector(p) => p.validate_at(path, out),
Self::UpdateFirmware(p) => p.validate_at(path, out),
}
}
}
impl serde::Serialize for CsmsResponse {
fn serialize<S: serde::Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self {
Self::CancelReservation(p) => p.serialize(ser),
Self::CertificateSigned(p) => p.serialize(ser),
Self::ChangeAvailability(p) => p.serialize(ser),
Self::ChangeConfiguration(p) => p.serialize(ser),
Self::ClearCache(p) => p.serialize(ser),
Self::ClearChargingProfile(p) => p.serialize(ser),
Self::DataTransfer(p) => p.serialize(ser),
Self::DeleteCertificate(p) => p.serialize(ser),
Self::ExtendedTriggerMessage(p) => p.serialize(ser),
Self::GetCompositeSchedule(p) => p.serialize(ser),
Self::GetConfiguration(p) => p.serialize(ser),
Self::GetDiagnostics(p) => p.serialize(ser),
Self::GetInstalledCertificateIds(p) => p.serialize(ser),
Self::GetLocalListVersion(p) => p.serialize(ser),
Self::GetLog(p) => p.serialize(ser),
Self::InstallCertificate(p) => p.serialize(ser),
Self::RemoteStartTransaction(p) => p.serialize(ser),
Self::RemoteStopTransaction(p) => p.serialize(ser),
Self::ReserveNow(p) => p.serialize(ser),
Self::Reset(p) => p.serialize(ser),
Self::SendLocalList(p) => p.serialize(ser),
Self::SetChargingProfile(p) => p.serialize(ser),
Self::SignedUpdateFirmware(p) => p.serialize(ser),
Self::TriggerMessage(p) => p.serialize(ser),
Self::UnlockConnector(p) => p.serialize(ser),
Self::UpdateFirmware(p) => p.serialize(ser),
}
}
}