#![allow(clippy::large_enum_variant)]
use ocpp_core::validate::Violation;
use crate::messages::*;
impl ocpp_core::Request for AuthorizeRequest {
const ACTION: &'static str = "Authorize";
type Response = AuthorizeResponse;
}
impl ocpp_core::Request for BootNotificationRequest {
const ACTION: &'static str = "BootNotification";
type Response = BootNotificationResponse;
}
impl ocpp_core::Request for CancelReservationRequest {
const ACTION: &'static str = "CancelReservation";
type Response = CancelReservationResponse;
}
impl ocpp_core::Request for ChangeAvailabilityRequest {
const ACTION: &'static str = "ChangeAvailability";
type Response = ChangeAvailabilityResponse;
}
impl ocpp_core::Request for ChangeConfigurationRequest {
const ACTION: &'static str = "ChangeConfiguration";
type Response = ChangeConfigurationResponse;
}
impl ocpp_core::Request for ClearCacheRequest {
const ACTION: &'static str = "ClearCache";
type Response = ClearCacheResponse;
}
impl ocpp_core::Request for ClearChargingProfileRequest {
const ACTION: &'static str = "ClearChargingProfile";
type Response = ClearChargingProfileResponse;
}
impl ocpp_core::Request for DataTransferRequest {
const ACTION: &'static str = "DataTransfer";
type Response = DataTransferResponse;
}
impl ocpp_core::Request for DiagnosticsStatusNotificationRequest {
const ACTION: &'static str = "DiagnosticsStatusNotification";
type Response = DiagnosticsStatusNotificationResponse;
}
impl ocpp_core::Request for FirmwareStatusNotificationRequest {
const ACTION: &'static str = "FirmwareStatusNotification";
type Response = FirmwareStatusNotificationResponse;
}
impl ocpp_core::Request for GetCompositeScheduleRequest {
const ACTION: &'static str = "GetCompositeSchedule";
type Response = GetCompositeScheduleResponse;
}
impl ocpp_core::Request for GetConfigurationRequest {
const ACTION: &'static str = "GetConfiguration";
type Response = GetConfigurationResponse;
}
impl ocpp_core::Request for GetDiagnosticsRequest {
const ACTION: &'static str = "GetDiagnostics";
type Response = GetDiagnosticsResponse;
}
impl ocpp_core::Request for GetLocalListVersionRequest {
const ACTION: &'static str = "GetLocalListVersion";
type Response = GetLocalListVersionResponse;
}
impl ocpp_core::Request for HeartbeatRequest {
const ACTION: &'static str = "Heartbeat";
type Response = HeartbeatResponse;
}
impl ocpp_core::Request for MeterValuesRequest {
const ACTION: &'static str = "MeterValues";
type Response = MeterValuesResponse;
}
impl ocpp_core::Request for RemoteStartTransactionRequest {
const ACTION: &'static str = "RemoteStartTransaction";
type Response = RemoteStartTransactionResponse;
}
impl ocpp_core::Request for RemoteStopTransactionRequest {
const ACTION: &'static str = "RemoteStopTransaction";
type Response = RemoteStopTransactionResponse;
}
impl ocpp_core::Request for ReserveNowRequest {
const ACTION: &'static str = "ReserveNow";
type Response = ReserveNowResponse;
}
impl ocpp_core::Request for ResetRequest {
const ACTION: &'static str = "Reset";
type Response = ResetResponse;
}
impl ocpp_core::Request for SendLocalListRequest {
const ACTION: &'static str = "SendLocalList";
type Response = SendLocalListResponse;
}
impl ocpp_core::Request for SetChargingProfileRequest {
const ACTION: &'static str = "SetChargingProfile";
type Response = SetChargingProfileResponse;
}
impl ocpp_core::Request for StartTransactionRequest {
const ACTION: &'static str = "StartTransaction";
type Response = StartTransactionResponse;
}
impl ocpp_core::Request for StatusNotificationRequest {
const ACTION: &'static str = "StatusNotification";
type Response = StatusNotificationResponse;
}
impl ocpp_core::Request for StopTransactionRequest {
const ACTION: &'static str = "StopTransaction";
type Response = StopTransactionResponse;
}
impl ocpp_core::Request for TriggerMessageRequest {
const ACTION: &'static str = "TriggerMessage";
type Response = TriggerMessageResponse;
}
impl ocpp_core::Request for UnlockConnectorRequest {
const ACTION: &'static str = "UnlockConnector";
type Response = UnlockConnectorResponse;
}
impl ocpp_core::Request for UpdateFirmwareRequest {
const ACTION: &'static str = "UpdateFirmware";
type Response = UpdateFirmwareResponse;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Direction {
StationToCsms,
CsmsToStation,
Both,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Action {
Authorize,
BootNotification,
CancelReservation,
ChangeAvailability,
ChangeConfiguration,
ClearCache,
ClearChargingProfile,
DataTransfer,
DiagnosticsStatusNotification,
FirmwareStatusNotification,
GetCompositeSchedule,
GetConfiguration,
GetDiagnostics,
GetLocalListVersion,
Heartbeat,
MeterValues,
RemoteStartTransaction,
RemoteStopTransaction,
ReserveNow,
Reset,
SendLocalList,
SetChargingProfile,
StartTransaction,
StatusNotification,
StopTransaction,
TriggerMessage,
UnlockConnector,
UpdateFirmware,
}
impl Action {
pub const ALL: &'static [Action] = &[
Action::Authorize,
Action::BootNotification,
Action::CancelReservation,
Action::ChangeAvailability,
Action::ChangeConfiguration,
Action::ClearCache,
Action::ClearChargingProfile,
Action::DataTransfer,
Action::DiagnosticsStatusNotification,
Action::FirmwareStatusNotification,
Action::GetCompositeSchedule,
Action::GetConfiguration,
Action::GetDiagnostics,
Action::GetLocalListVersion,
Action::Heartbeat,
Action::MeterValues,
Action::RemoteStartTransaction,
Action::RemoteStopTransaction,
Action::ReserveNow,
Action::Reset,
Action::SendLocalList,
Action::SetChargingProfile,
Action::StartTransaction,
Action::StatusNotification,
Action::StopTransaction,
Action::TriggerMessage,
Action::UnlockConnector,
Action::UpdateFirmware,
];
pub const fn as_str(&self) -> &'static str {
match self {
Action::Authorize => "Authorize",
Action::BootNotification => "BootNotification",
Action::CancelReservation => "CancelReservation",
Action::ChangeAvailability => "ChangeAvailability",
Action::ChangeConfiguration => "ChangeConfiguration",
Action::ClearCache => "ClearCache",
Action::ClearChargingProfile => "ClearChargingProfile",
Action::DataTransfer => "DataTransfer",
Action::DiagnosticsStatusNotification => "DiagnosticsStatusNotification",
Action::FirmwareStatusNotification => "FirmwareStatusNotification",
Action::GetCompositeSchedule => "GetCompositeSchedule",
Action::GetConfiguration => "GetConfiguration",
Action::GetDiagnostics => "GetDiagnostics",
Action::GetLocalListVersion => "GetLocalListVersion",
Action::Heartbeat => "Heartbeat",
Action::MeterValues => "MeterValues",
Action::RemoteStartTransaction => "RemoteStartTransaction",
Action::RemoteStopTransaction => "RemoteStopTransaction",
Action::ReserveNow => "ReserveNow",
Action::Reset => "Reset",
Action::SendLocalList => "SendLocalList",
Action::SetChargingProfile => "SetChargingProfile",
Action::StartTransaction => "StartTransaction",
Action::StatusNotification => "StatusNotification",
Action::StopTransaction => "StopTransaction",
Action::TriggerMessage => "TriggerMessage",
Action::UnlockConnector => "UnlockConnector",
Action::UpdateFirmware => "UpdateFirmware",
}
}
pub fn from_name(s: &str) -> Option<Action> {
match s {
"Authorize" => Some(Action::Authorize),
"BootNotification" => Some(Action::BootNotification),
"CancelReservation" => Some(Action::CancelReservation),
"ChangeAvailability" => Some(Action::ChangeAvailability),
"ChangeConfiguration" => Some(Action::ChangeConfiguration),
"ClearCache" => Some(Action::ClearCache),
"ClearChargingProfile" => Some(Action::ClearChargingProfile),
"DataTransfer" => Some(Action::DataTransfer),
"DiagnosticsStatusNotification" => Some(Action::DiagnosticsStatusNotification),
"FirmwareStatusNotification" => Some(Action::FirmwareStatusNotification),
"GetCompositeSchedule" => Some(Action::GetCompositeSchedule),
"GetConfiguration" => Some(Action::GetConfiguration),
"GetDiagnostics" => Some(Action::GetDiagnostics),
"GetLocalListVersion" => Some(Action::GetLocalListVersion),
"Heartbeat" => Some(Action::Heartbeat),
"MeterValues" => Some(Action::MeterValues),
"RemoteStartTransaction" => Some(Action::RemoteStartTransaction),
"RemoteStopTransaction" => Some(Action::RemoteStopTransaction),
"ReserveNow" => Some(Action::ReserveNow),
"Reset" => Some(Action::Reset),
"SendLocalList" => Some(Action::SendLocalList),
"SetChargingProfile" => Some(Action::SetChargingProfile),
"StartTransaction" => Some(Action::StartTransaction),
"StatusNotification" => Some(Action::StatusNotification),
"StopTransaction" => Some(Action::StopTransaction),
"TriggerMessage" => Some(Action::TriggerMessage),
"UnlockConnector" => Some(Action::UnlockConnector),
"UpdateFirmware" => Some(Action::UpdateFirmware),
_ => None,
}
}
pub const fn direction(&self) -> Direction {
match self {
Action::Authorize => Direction::StationToCsms,
Action::BootNotification => Direction::StationToCsms,
Action::CancelReservation => Direction::CsmsToStation,
Action::ChangeAvailability => Direction::CsmsToStation,
Action::ChangeConfiguration => Direction::CsmsToStation,
Action::ClearCache => Direction::CsmsToStation,
Action::ClearChargingProfile => Direction::CsmsToStation,
Action::DataTransfer => Direction::Both,
Action::DiagnosticsStatusNotification => Direction::StationToCsms,
Action::FirmwareStatusNotification => Direction::StationToCsms,
Action::GetCompositeSchedule => Direction::CsmsToStation,
Action::GetConfiguration => Direction::CsmsToStation,
Action::GetDiagnostics => Direction::CsmsToStation,
Action::GetLocalListVersion => Direction::CsmsToStation,
Action::Heartbeat => Direction::StationToCsms,
Action::MeterValues => Direction::StationToCsms,
Action::RemoteStartTransaction => Direction::CsmsToStation,
Action::RemoteStopTransaction => Direction::CsmsToStation,
Action::ReserveNow => Direction::CsmsToStation,
Action::Reset => Direction::CsmsToStation,
Action::SendLocalList => Direction::CsmsToStation,
Action::SetChargingProfile => Direction::CsmsToStation,
Action::StartTransaction => Direction::StationToCsms,
Action::StatusNotification => Direction::StationToCsms,
Action::StopTransaction => Direction::StationToCsms,
Action::TriggerMessage => Direction::CsmsToStation,
Action::UnlockConnector => Direction::CsmsToStation,
Action::UpdateFirmware => Direction::CsmsToStation,
}
}
pub const fn is_send(&self) -> bool {
false
}
}
impl std::fmt::Display for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DecodeError {
UnknownAction(String),
WrongDirection(Action),
Invalid(Violation),
}
impl std::fmt::Display for DecodeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DecodeError::UnknownAction(a) => write!(f, "unknown action '{a}'"),
DecodeError::WrongDirection(a) => {
write!(f, "action '{a}' is not accepted in this direction")
}
DecodeError::Invalid(v) => write!(f, "{v}"),
}
}
}
impl std::error::Error for DecodeError {}
#[derive(Debug, Clone, PartialEq)]
pub enum StationCall {
Authorize(AuthorizeRequest),
BootNotification(BootNotificationRequest),
DataTransfer(DataTransferRequest),
DiagnosticsStatusNotification(DiagnosticsStatusNotificationRequest),
FirmwareStatusNotification(FirmwareStatusNotificationRequest),
Heartbeat(HeartbeatRequest),
MeterValues(MeterValuesRequest),
StartTransaction(StartTransactionRequest),
StatusNotification(StatusNotificationRequest),
StopTransaction(StopTransactionRequest),
}
impl StationCall {
pub const fn action(&self) -> Action {
match self {
StationCall::Authorize(_) => Action::Authorize,
StationCall::BootNotification(_) => Action::BootNotification,
StationCall::DataTransfer(_) => Action::DataTransfer,
StationCall::DiagnosticsStatusNotification(_) => Action::DiagnosticsStatusNotification,
StationCall::FirmwareStatusNotification(_) => Action::FirmwareStatusNotification,
StationCall::Heartbeat(_) => Action::Heartbeat,
StationCall::MeterValues(_) => Action::MeterValues,
StationCall::StartTransaction(_) => Action::StartTransaction,
StationCall::StatusNotification(_) => Action::StatusNotification,
StationCall::StopTransaction(_) => Action::StopTransaction,
}
}
pub fn decode(action: &str, payload: &str) -> Result<Self, DecodeError> {
let a = Action::from_name(action)
.ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
match a {
Action::Authorize => ocpp_core::decode_payload(payload)
.map(StationCall::Authorize)
.map_err(DecodeError::Invalid),
Action::BootNotification => ocpp_core::decode_payload(payload)
.map(StationCall::BootNotification)
.map_err(DecodeError::Invalid),
Action::DataTransfer => ocpp_core::decode_payload(payload)
.map(StationCall::DataTransfer)
.map_err(DecodeError::Invalid),
Action::DiagnosticsStatusNotification => ocpp_core::decode_payload(payload)
.map(StationCall::DiagnosticsStatusNotification)
.map_err(DecodeError::Invalid),
Action::FirmwareStatusNotification => ocpp_core::decode_payload(payload)
.map(StationCall::FirmwareStatusNotification)
.map_err(DecodeError::Invalid),
Action::Heartbeat => ocpp_core::decode_payload(payload)
.map(StationCall::Heartbeat)
.map_err(DecodeError::Invalid),
Action::MeterValues => ocpp_core::decode_payload(payload)
.map(StationCall::MeterValues)
.map_err(DecodeError::Invalid),
Action::StartTransaction => ocpp_core::decode_payload(payload)
.map(StationCall::StartTransaction)
.map_err(DecodeError::Invalid),
Action::StatusNotification => ocpp_core::decode_payload(payload)
.map(StationCall::StatusNotification)
.map_err(DecodeError::Invalid),
Action::StopTransaction => ocpp_core::decode_payload(payload)
.map(StationCall::StopTransaction)
.map_err(DecodeError::Invalid),
#[allow(unreachable_patterns)]
other => Err(DecodeError::WrongDirection(other)),
}
}
pub fn from_value(action: &str, payload: serde_json::Value) -> Result<Self, DecodeError> {
let a = Action::from_name(action)
.ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
match a {
Action::Authorize => ocpp_core::decode_value(payload)
.map(StationCall::Authorize)
.map_err(DecodeError::Invalid),
Action::BootNotification => ocpp_core::decode_value(payload)
.map(StationCall::BootNotification)
.map_err(DecodeError::Invalid),
Action::DataTransfer => ocpp_core::decode_value(payload)
.map(StationCall::DataTransfer)
.map_err(DecodeError::Invalid),
Action::DiagnosticsStatusNotification => ocpp_core::decode_value(payload)
.map(StationCall::DiagnosticsStatusNotification)
.map_err(DecodeError::Invalid),
Action::FirmwareStatusNotification => ocpp_core::decode_value(payload)
.map(StationCall::FirmwareStatusNotification)
.map_err(DecodeError::Invalid),
Action::Heartbeat => ocpp_core::decode_value(payload)
.map(StationCall::Heartbeat)
.map_err(DecodeError::Invalid),
Action::MeterValues => ocpp_core::decode_value(payload)
.map(StationCall::MeterValues)
.map_err(DecodeError::Invalid),
Action::StartTransaction => ocpp_core::decode_value(payload)
.map(StationCall::StartTransaction)
.map_err(DecodeError::Invalid),
Action::StatusNotification => ocpp_core::decode_value(payload)
.map(StationCall::StatusNotification)
.map_err(DecodeError::Invalid),
Action::StopTransaction => ocpp_core::decode_value(payload)
.map(StationCall::StopTransaction)
.map_err(DecodeError::Invalid),
#[allow(unreachable_patterns)]
other => Err(DecodeError::WrongDirection(other)),
}
}
pub fn to_payload(&self) -> serde_json::Value {
match self {
StationCall::Authorize(r) => serde_json::to_value(r).expect("serializable"),
StationCall::BootNotification(r) => serde_json::to_value(r).expect("serializable"),
StationCall::DataTransfer(r) => serde_json::to_value(r).expect("serializable"),
StationCall::DiagnosticsStatusNotification(r) => {
serde_json::to_value(r).expect("serializable")
}
StationCall::FirmwareStatusNotification(r) => {
serde_json::to_value(r).expect("serializable")
}
StationCall::Heartbeat(r) => serde_json::to_value(r).expect("serializable"),
StationCall::MeterValues(r) => serde_json::to_value(r).expect("serializable"),
StationCall::StartTransaction(r) => serde_json::to_value(r).expect("serializable"),
StationCall::StatusNotification(r) => serde_json::to_value(r).expect("serializable"),
StationCall::StopTransaction(r) => serde_json::to_value(r).expect("serializable"),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum CsmsCall {
CancelReservation(CancelReservationRequest),
ChangeAvailability(ChangeAvailabilityRequest),
ChangeConfiguration(ChangeConfigurationRequest),
ClearCache(ClearCacheRequest),
ClearChargingProfile(ClearChargingProfileRequest),
DataTransfer(DataTransferRequest),
GetCompositeSchedule(GetCompositeScheduleRequest),
GetConfiguration(GetConfigurationRequest),
GetDiagnostics(GetDiagnosticsRequest),
GetLocalListVersion(GetLocalListVersionRequest),
RemoteStartTransaction(RemoteStartTransactionRequest),
RemoteStopTransaction(RemoteStopTransactionRequest),
ReserveNow(ReserveNowRequest),
Reset(ResetRequest),
SendLocalList(SendLocalListRequest),
SetChargingProfile(SetChargingProfileRequest),
TriggerMessage(TriggerMessageRequest),
UnlockConnector(UnlockConnectorRequest),
UpdateFirmware(UpdateFirmwareRequest),
}
impl CsmsCall {
pub const fn action(&self) -> Action {
match self {
CsmsCall::CancelReservation(_) => Action::CancelReservation,
CsmsCall::ChangeAvailability(_) => Action::ChangeAvailability,
CsmsCall::ChangeConfiguration(_) => Action::ChangeConfiguration,
CsmsCall::ClearCache(_) => Action::ClearCache,
CsmsCall::ClearChargingProfile(_) => Action::ClearChargingProfile,
CsmsCall::DataTransfer(_) => Action::DataTransfer,
CsmsCall::GetCompositeSchedule(_) => Action::GetCompositeSchedule,
CsmsCall::GetConfiguration(_) => Action::GetConfiguration,
CsmsCall::GetDiagnostics(_) => Action::GetDiagnostics,
CsmsCall::GetLocalListVersion(_) => Action::GetLocalListVersion,
CsmsCall::RemoteStartTransaction(_) => Action::RemoteStartTransaction,
CsmsCall::RemoteStopTransaction(_) => Action::RemoteStopTransaction,
CsmsCall::ReserveNow(_) => Action::ReserveNow,
CsmsCall::Reset(_) => Action::Reset,
CsmsCall::SendLocalList(_) => Action::SendLocalList,
CsmsCall::SetChargingProfile(_) => Action::SetChargingProfile,
CsmsCall::TriggerMessage(_) => Action::TriggerMessage,
CsmsCall::UnlockConnector(_) => Action::UnlockConnector,
CsmsCall::UpdateFirmware(_) => Action::UpdateFirmware,
}
}
pub fn decode(action: &str, payload: &str) -> Result<Self, DecodeError> {
let a = Action::from_name(action)
.ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
match a {
Action::CancelReservation => ocpp_core::decode_payload(payload)
.map(CsmsCall::CancelReservation)
.map_err(DecodeError::Invalid),
Action::ChangeAvailability => ocpp_core::decode_payload(payload)
.map(CsmsCall::ChangeAvailability)
.map_err(DecodeError::Invalid),
Action::ChangeConfiguration => ocpp_core::decode_payload(payload)
.map(CsmsCall::ChangeConfiguration)
.map_err(DecodeError::Invalid),
Action::ClearCache => ocpp_core::decode_payload(payload)
.map(CsmsCall::ClearCache)
.map_err(DecodeError::Invalid),
Action::ClearChargingProfile => ocpp_core::decode_payload(payload)
.map(CsmsCall::ClearChargingProfile)
.map_err(DecodeError::Invalid),
Action::DataTransfer => ocpp_core::decode_payload(payload)
.map(CsmsCall::DataTransfer)
.map_err(DecodeError::Invalid),
Action::GetCompositeSchedule => ocpp_core::decode_payload(payload)
.map(CsmsCall::GetCompositeSchedule)
.map_err(DecodeError::Invalid),
Action::GetConfiguration => ocpp_core::decode_payload(payload)
.map(CsmsCall::GetConfiguration)
.map_err(DecodeError::Invalid),
Action::GetDiagnostics => ocpp_core::decode_payload(payload)
.map(CsmsCall::GetDiagnostics)
.map_err(DecodeError::Invalid),
Action::GetLocalListVersion => ocpp_core::decode_payload(payload)
.map(CsmsCall::GetLocalListVersion)
.map_err(DecodeError::Invalid),
Action::RemoteStartTransaction => ocpp_core::decode_payload(payload)
.map(CsmsCall::RemoteStartTransaction)
.map_err(DecodeError::Invalid),
Action::RemoteStopTransaction => ocpp_core::decode_payload(payload)
.map(CsmsCall::RemoteStopTransaction)
.map_err(DecodeError::Invalid),
Action::ReserveNow => ocpp_core::decode_payload(payload)
.map(CsmsCall::ReserveNow)
.map_err(DecodeError::Invalid),
Action::Reset => ocpp_core::decode_payload(payload)
.map(CsmsCall::Reset)
.map_err(DecodeError::Invalid),
Action::SendLocalList => ocpp_core::decode_payload(payload)
.map(CsmsCall::SendLocalList)
.map_err(DecodeError::Invalid),
Action::SetChargingProfile => ocpp_core::decode_payload(payload)
.map(CsmsCall::SetChargingProfile)
.map_err(DecodeError::Invalid),
Action::TriggerMessage => ocpp_core::decode_payload(payload)
.map(CsmsCall::TriggerMessage)
.map_err(DecodeError::Invalid),
Action::UnlockConnector => ocpp_core::decode_payload(payload)
.map(CsmsCall::UnlockConnector)
.map_err(DecodeError::Invalid),
Action::UpdateFirmware => ocpp_core::decode_payload(payload)
.map(CsmsCall::UpdateFirmware)
.map_err(DecodeError::Invalid),
#[allow(unreachable_patterns)]
other => Err(DecodeError::WrongDirection(other)),
}
}
pub fn from_value(action: &str, payload: serde_json::Value) -> Result<Self, DecodeError> {
let a = Action::from_name(action)
.ok_or_else(|| DecodeError::UnknownAction(action.to_owned()))?;
match a {
Action::CancelReservation => ocpp_core::decode_value(payload)
.map(CsmsCall::CancelReservation)
.map_err(DecodeError::Invalid),
Action::ChangeAvailability => ocpp_core::decode_value(payload)
.map(CsmsCall::ChangeAvailability)
.map_err(DecodeError::Invalid),
Action::ChangeConfiguration => ocpp_core::decode_value(payload)
.map(CsmsCall::ChangeConfiguration)
.map_err(DecodeError::Invalid),
Action::ClearCache => ocpp_core::decode_value(payload)
.map(CsmsCall::ClearCache)
.map_err(DecodeError::Invalid),
Action::ClearChargingProfile => ocpp_core::decode_value(payload)
.map(CsmsCall::ClearChargingProfile)
.map_err(DecodeError::Invalid),
Action::DataTransfer => ocpp_core::decode_value(payload)
.map(CsmsCall::DataTransfer)
.map_err(DecodeError::Invalid),
Action::GetCompositeSchedule => ocpp_core::decode_value(payload)
.map(CsmsCall::GetCompositeSchedule)
.map_err(DecodeError::Invalid),
Action::GetConfiguration => ocpp_core::decode_value(payload)
.map(CsmsCall::GetConfiguration)
.map_err(DecodeError::Invalid),
Action::GetDiagnostics => ocpp_core::decode_value(payload)
.map(CsmsCall::GetDiagnostics)
.map_err(DecodeError::Invalid),
Action::GetLocalListVersion => ocpp_core::decode_value(payload)
.map(CsmsCall::GetLocalListVersion)
.map_err(DecodeError::Invalid),
Action::RemoteStartTransaction => ocpp_core::decode_value(payload)
.map(CsmsCall::RemoteStartTransaction)
.map_err(DecodeError::Invalid),
Action::RemoteStopTransaction => ocpp_core::decode_value(payload)
.map(CsmsCall::RemoteStopTransaction)
.map_err(DecodeError::Invalid),
Action::ReserveNow => ocpp_core::decode_value(payload)
.map(CsmsCall::ReserveNow)
.map_err(DecodeError::Invalid),
Action::Reset => ocpp_core::decode_value(payload)
.map(CsmsCall::Reset)
.map_err(DecodeError::Invalid),
Action::SendLocalList => ocpp_core::decode_value(payload)
.map(CsmsCall::SendLocalList)
.map_err(DecodeError::Invalid),
Action::SetChargingProfile => ocpp_core::decode_value(payload)
.map(CsmsCall::SetChargingProfile)
.map_err(DecodeError::Invalid),
Action::TriggerMessage => ocpp_core::decode_value(payload)
.map(CsmsCall::TriggerMessage)
.map_err(DecodeError::Invalid),
Action::UnlockConnector => ocpp_core::decode_value(payload)
.map(CsmsCall::UnlockConnector)
.map_err(DecodeError::Invalid),
Action::UpdateFirmware => ocpp_core::decode_value(payload)
.map(CsmsCall::UpdateFirmware)
.map_err(DecodeError::Invalid),
#[allow(unreachable_patterns)]
other => Err(DecodeError::WrongDirection(other)),
}
}
pub fn to_payload(&self) -> serde_json::Value {
match self {
CsmsCall::CancelReservation(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::ChangeAvailability(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::ChangeConfiguration(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::ClearCache(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::ClearChargingProfile(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::DataTransfer(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::GetCompositeSchedule(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::GetConfiguration(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::GetDiagnostics(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::GetLocalListVersion(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::RemoteStartTransaction(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::RemoteStopTransaction(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::ReserveNow(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::Reset(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::SendLocalList(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::SetChargingProfile(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::TriggerMessage(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::UnlockConnector(r) => serde_json::to_value(r).expect("serializable"),
CsmsCall::UpdateFirmware(r) => serde_json::to_value(r).expect("serializable"),
}
}
}
pub fn validate_response(action: Action, payload: &str) -> Result<serde_json::Value, Violation> {
match action {
Action::Authorize => ocpp_core::decode_payload::<AuthorizeResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::BootNotification => ocpp_core::decode_payload::<BootNotificationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::CancelReservation => {
ocpp_core::decode_payload::<CancelReservationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::ChangeAvailability => {
ocpp_core::decode_payload::<ChangeAvailabilityResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::ChangeConfiguration => {
ocpp_core::decode_payload::<ChangeConfigurationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::ClearCache => ocpp_core::decode_payload::<ClearCacheResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::ClearChargingProfile => {
ocpp_core::decode_payload::<ClearChargingProfileResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::DataTransfer => ocpp_core::decode_payload::<DataTransferResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::DiagnosticsStatusNotification => {
ocpp_core::decode_payload::<DiagnosticsStatusNotificationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::FirmwareStatusNotification => {
ocpp_core::decode_payload::<FirmwareStatusNotificationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::GetCompositeSchedule => {
ocpp_core::decode_payload::<GetCompositeScheduleResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::GetConfiguration => ocpp_core::decode_payload::<GetConfigurationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::GetDiagnostics => ocpp_core::decode_payload::<GetDiagnosticsResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::GetLocalListVersion => {
ocpp_core::decode_payload::<GetLocalListVersionResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::Heartbeat => ocpp_core::decode_payload::<HeartbeatResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::MeterValues => ocpp_core::decode_payload::<MeterValuesResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::RemoteStartTransaction => {
ocpp_core::decode_payload::<RemoteStartTransactionResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::RemoteStopTransaction => {
ocpp_core::decode_payload::<RemoteStopTransactionResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::ReserveNow => ocpp_core::decode_payload::<ReserveNowResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::Reset => ocpp_core::decode_payload::<ResetResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::SendLocalList => ocpp_core::decode_payload::<SendLocalListResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::SetChargingProfile => {
ocpp_core::decode_payload::<SetChargingProfileResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::StartTransaction => ocpp_core::decode_payload::<StartTransactionResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::StatusNotification => {
ocpp_core::decode_payload::<StatusNotificationResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable"))
}
Action::StopTransaction => ocpp_core::decode_payload::<StopTransactionResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::TriggerMessage => ocpp_core::decode_payload::<TriggerMessageResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::UnlockConnector => ocpp_core::decode_payload::<UnlockConnectorResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
Action::UpdateFirmware => ocpp_core::decode_payload::<UpdateFirmwareResponse>(payload)
.map(|r| serde_json::to_value(r).expect("serializable")),
}
}