1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//!# OCPP-RS
//!
//! OCPP-RS is a Rust library for implementing the Open Charge Point Protocol (OCPP) in Rust.\
//! it currently only supports OCPP 1.6.
//!
//! ## Usage
//! In Cargo.toml, add the following dependency:
//! ```toml
//! [dependencies]
//! ocpp-rs = "^0.2"
//! ```
//!
//! # Particularities
//! Since the original OCPP 1.6 protocol does not contain a type field for `CallResult`, when parsing `CallResult`lt, you need to handle
//! Special cases where JSON payloads are ambiguous, like empty objects like: ```{}```, these might get serialized as a `EmptyResponse` instead of the variant
//! you are waiting for like `GetConfiguration`.
//!
//! Look at this file to see how to properly handle `CallResults`: [`valid_call_result.rs`](https://github.com/angelorodem/ocpp-rs/blob/main/fuzz/fuzz_targets/valid_call_result.rs)
//!
//! ## Example
//! Receiving a payload from a client:
//! ```rust
//! use ocpp_rs::v16::parse::{self, Message};
//! use ocpp_rs::v16::call::{Action, Call};
//!
//! // Example incoming message
//! let incoming_text = "[2, \"19223201\", \"BootNotification\", { \"chargePointVendor\": \"VendorX\", \"chargePointModel\": \"SingleSocketCharger\" }]";
//! let incoming_message = parse::deserialize_to_message(incoming_text);
//! if let Ok(Message::Call(call)) = incoming_message {
//!
//! // Handle incoming message (Check the type of the message)
//! match call.payload {
//! Action::BootNotification(_boot_notification) => {
//! // Do something with boot_notification
//! }
//! _ => {
//! // Handle other actions
//! }
//! }
//! }
//! ```
//!
//! Sending a payload to a client:
//! ```rust
//! use ocpp_rs::v16::parse::Message;
//! use ocpp_rs::v16::call_result::CallResult;
//! use ocpp_rs::v16::call_result::ResultPayload;
//! use ocpp_rs::v16::call_result;
//! use ocpp_rs::v16::data_types::IdTagInfo;
//! use ocpp_rs::v16::parse;
//! let response = Message::CallResult(CallResult::new(
//! "1234".to_string(),
//! ResultPayload::StartTransaction(call_result::StartTransaction {
//! transaction_id: 0,
//! id_tag_info: IdTagInfo {
//! status: ocpp_rs::v16::enums::ParsedGenericStatus::Accepted,
//! expiry_date: None,
//! parent_id_tag: None,
//! },
//! }),
//! ));
//!
//! let json = parse::serialize_message(&response);
//! println!("Sending to client: {:?}", json);
//! ```
//!
extern crate alloc;