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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//!# OCPP-RS
//!
//! OCPP-RS is a Rust library for implementing the Open Charge Point Protocol (OCPP) in Rust.\
//! It supports OCPP 1.6 and OCPP 2.1.
//!
//! ## Usage
//! In Cargo.toml, add the following dependency:
//! ```toml
//! [dependencies]
//! ocpp-rs = "^0.4"
//! ```
//!
//! # Particularities
//!
//! ## OCPP 1.6
//! CALLRESULT has no action on the wire. Blind parse yields [`v16::call_result::CallResultRaw`].
//! Correlate with [`v16::pending::PendingCalls`] (or action-name store /
//! [`v16::pending::resolve_with_action_name`]). Do **not** guess from JSON shape.
//! Datetime: parse always accepts RFC3339; serialize defaults to `%Y-%m-%dT%H:%M:%S%.3fZ`
//! (enable `datetime_serialize_rfc3339` to emit RFC3339 millis — see [`datetime`]).
//! Migration from 0.2.x: `guides/migration-0.4.md`.
//!
//! ## OCPP 2.1
//! Same CallResult model under [`v21::pending`]. Framing includes types 2–6
//! (CALL, CALLRESULT, CALLERROR, CALLRESULTERROR, SEND).
//! Datetime helpers share [`datetime`] with v16 (RFC3339 parse; `%.3fZ` serialize by default).
//!
//! ## Example (1.6 CALL)
//! ```rust
//! use ocpp_rs::v16::parse::{self, Message};
//! use ocpp_rs::v16::call::Action;
//!
//! 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 {
//! match call.payload {
//! Action::BootNotification(_boot_notification) => {}
//! _ => {}
//! }
//! }
//! ```
//!
//! ## Example (1.6 CallResult with PendingCalls)
//! ```rust
//! use ocpp_rs::v16::call::{Action, Call, Heartbeat};
//! use ocpp_rs::v16::parse::TypedMessage;
//! use ocpp_rs::v16::pending::PendingCalls;
//! use ocpp_rs::v16::typed_call_result::TypedCallResult;
//!
//! let mut pending = PendingCalls::new();
//! let _ = pending
//! .send_call(Call::new("1".to_string(), Action::Heartbeat(Heartbeat {})))
//! .expect("serialize");
//! let typed = pending
//! .deserialize_typed(r#"[3, "1", {"currentTime": "2024-01-01T00:00:00.000Z"}]"#)
//! .expect("typed");
//! assert!(matches!(
//! typed,
//! TypedMessage::CallResult(TypedCallResult::Heartbeat(_))
//! ));
//! ```
//!
//! ## Example (2.1)
//! ```rust
//! use ocpp_rs::v21::call::{Action, Call};
//! use ocpp_rs::v21::messages::heartbeat::HeartbeatRequest;
//! use ocpp_rs::v21::parse::TypedMessage;
//! use ocpp_rs::v21::pending::PendingCalls;
//! use ocpp_rs::v21::typed_call_result::TypedCallResult;
//!
//! let mut pending = PendingCalls::new();
//! let call = Call::new(
//! "1".to_string(),
//! Action::Heartbeat(HeartbeatRequest { custom_data: None }),
//! );
//! let _outgoing = pending.send_call(call).expect("serialize");
//! let typed = pending
//! .deserialize_typed(r#"[3, "1", {"currentTime": "2024-01-01T00:00:00.000Z"}]"#)
//! .expect("typed result");
//! assert!(matches!(
//! typed,
//! TypedMessage::CallResult(TypedCallResult::Heartbeat(_))
//! ));
//! ```
//!
extern crate alloc;