Skip to main content

ocpp_kit/v1_6/
types.rs

1// @generated by `cargo xtask codegen` from the vendored OCPP JSON schemas.
2// DO NOT EDIT — re-run the generator instead. CI fails if this file is stale.
3
4//! Data types shared between OCPP 1.6 messages, generated from the official JSON schemas.
5
6#![allow(unused_imports, clippy::doc_markdown, clippy::struct_excessive_bools)]
7#![allow(
8    clippy::too_many_lines,
9    clippy::too_many_arguments,
10    clippy::wildcard_imports
11)]
12#![allow(clippy::match_same_arms, clippy::fn_params_excessive_bools)]
13
14use alloc::string::String;
15use alloc::vec::Vec;
16
17use serde::{Deserialize, Serialize};
18
19use super::enums::*;
20use crate::validate::{self, Validate, ValidationPath, Violations};
21
22/// The OCPP 1.6 `AuthorizationData` data type.
23#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
24pub struct AuthorizationData {
25    /// The `idTag` member.
26    #[serde(rename = "idTag")]
27    pub id_tag: String,
28    /// The `idTagInfo` member.
29    #[serde(rename = "idTagInfo")]
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub id_tag_info: Option<IdTagInfo>,
32}
33
34impl AuthorizationData {
35    /// Creates a `AuthorizationData` from its required fields.
36    #[must_use]
37    pub fn new(id_tag: impl Into<String>) -> Self {
38        Self {
39            id_tag: id_tag.into(),
40            id_tag_info: None,
41        }
42    }
43
44    /// Sets the optional `idTagInfo` field.
45    #[must_use]
46    pub fn with_id_tag_info(mut self, value: IdTagInfo) -> Self {
47        self.id_tag_info = Some(value);
48        self
49    }
50}
51
52impl Validate for AuthorizationData {
53    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
54        path.push_key("idTag");
55        validate::string(self.id_tag.as_str(), None, Some(20), path, out);
56        path.pop();
57        path.push_key("idTagInfo");
58        if let Some(value) = &self.id_tag_info {
59            Validate::validate_at(value, path, out);
60        }
61        path.pop();
62    }
63}
64
65/// The OCPP 1.6 `CertificateHashData` data type.
66#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
67pub struct CertificateHashData {
68    /// The `hashAlgorithm` member.
69    #[serde(rename = "hashAlgorithm")]
70    pub hash_algorithm: HashAlgorithm,
71    /// The `issuerNameHash` member.
72    #[serde(rename = "issuerNameHash")]
73    pub issuer_name_hash: String,
74    /// The `issuerKeyHash` member.
75    #[serde(rename = "issuerKeyHash")]
76    pub issuer_key_hash: String,
77    /// The `serialNumber` member.
78    #[serde(rename = "serialNumber")]
79    pub serial_number: String,
80}
81
82impl CertificateHashData {
83    /// Creates a `CertificateHashData` from its required fields.
84    #[must_use]
85    pub fn new(
86        hash_algorithm: HashAlgorithm,
87        issuer_name_hash: impl Into<String>,
88        issuer_key_hash: impl Into<String>,
89        serial_number: impl Into<String>,
90    ) -> Self {
91        Self {
92            hash_algorithm,
93            issuer_name_hash: issuer_name_hash.into(),
94            issuer_key_hash: issuer_key_hash.into(),
95            serial_number: serial_number.into(),
96        }
97    }
98}
99
100impl Validate for CertificateHashData {
101    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
102        path.push_key("hashAlgorithm");
103        Validate::validate_at(&self.hash_algorithm, path, out);
104        path.pop();
105        path.push_key("issuerNameHash");
106        validate::string(self.issuer_name_hash.as_str(), None, Some(128), path, out);
107        path.pop();
108        path.push_key("issuerKeyHash");
109        validate::string(self.issuer_key_hash.as_str(), None, Some(128), path, out);
110        path.pop();
111        path.push_key("serialNumber");
112        validate::string(self.serial_number.as_str(), None, Some(40), path, out);
113        path.pop();
114    }
115}
116
117/// The OCPP 1.6 `ChargingProfile` data type.
118#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
119pub struct ChargingProfile {
120    /// The `chargingProfileId` member.
121    #[serde(rename = "chargingProfileId")]
122    pub charging_profile_id: i32,
123    /// The `stackLevel` member.
124    #[serde(rename = "stackLevel")]
125    pub stack_level: i32,
126    /// The `chargingProfilePurpose` member.
127    #[serde(rename = "chargingProfilePurpose")]
128    pub charging_profile_purpose: ChargingProfilePurpose,
129    /// The `chargingProfileKind` member.
130    #[serde(rename = "chargingProfileKind")]
131    pub charging_profile_kind: ChargingProfileKind,
132    /// The `chargingSchedule` member.
133    #[serde(rename = "chargingSchedule")]
134    pub charging_schedule: ChargingSchedule,
135    /// The `transactionId` member.
136    #[serde(rename = "transactionId")]
137    #[serde(default, skip_serializing_if = "Option::is_none")]
138    pub transaction_id: Option<i32>,
139    /// The `recurrencyKind` member.
140    #[serde(rename = "recurrencyKind")]
141    #[serde(default, skip_serializing_if = "Option::is_none")]
142    pub recurrency_kind: Option<RecurrencyKind>,
143    /// The `validFrom` member.
144    #[serde(rename = "validFrom")]
145    #[serde(default, skip_serializing_if = "Option::is_none")]
146    pub valid_from: Option<crate::types::DateTime>,
147    /// The `validTo` member.
148    #[serde(rename = "validTo")]
149    #[serde(default, skip_serializing_if = "Option::is_none")]
150    pub valid_to: Option<crate::types::DateTime>,
151}
152
153impl ChargingProfile {
154    /// Creates a `ChargingProfile` from its required fields.
155    #[must_use]
156    pub fn new(
157        charging_profile_id: i32,
158        stack_level: i32,
159        charging_profile_purpose: ChargingProfilePurpose,
160        charging_profile_kind: ChargingProfileKind,
161        charging_schedule: ChargingSchedule,
162    ) -> Self {
163        Self {
164            charging_profile_id,
165            stack_level,
166            charging_profile_purpose,
167            charging_profile_kind,
168            charging_schedule,
169            transaction_id: None,
170            recurrency_kind: None,
171            valid_from: None,
172            valid_to: None,
173        }
174    }
175
176    /// Sets the optional `transactionId` field.
177    #[must_use]
178    pub fn with_transaction_id(mut self, value: i32) -> Self {
179        self.transaction_id = Some(value);
180        self
181    }
182
183    /// Sets the optional `recurrencyKind` field.
184    #[must_use]
185    pub fn with_recurrency_kind(mut self, value: RecurrencyKind) -> Self {
186        self.recurrency_kind = Some(value);
187        self
188    }
189
190    /// Sets the optional `validFrom` field.
191    #[must_use]
192    pub fn with_valid_from(mut self, value: impl Into<crate::types::DateTime>) -> Self {
193        self.valid_from = Some(value.into());
194        self
195    }
196
197    /// Sets the optional `validTo` field.
198    #[must_use]
199    pub fn with_valid_to(mut self, value: impl Into<crate::types::DateTime>) -> Self {
200        self.valid_to = Some(value.into());
201        self
202    }
203}
204
205impl Validate for ChargingProfile {
206    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
207        path.push_key("chargingProfilePurpose");
208        Validate::validate_at(&self.charging_profile_purpose, path, out);
209        path.pop();
210        path.push_key("chargingProfileKind");
211        Validate::validate_at(&self.charging_profile_kind, path, out);
212        path.pop();
213        path.push_key("chargingSchedule");
214        Validate::validate_at(&self.charging_schedule, path, out);
215        path.pop();
216        path.push_key("recurrencyKind");
217        if let Some(value) = &self.recurrency_kind {
218            Validate::validate_at(value, path, out);
219        }
220        path.pop();
221    }
222}
223
224/// The OCPP 1.6 `ChargingSchedule` data type.
225#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
226pub struct ChargingSchedule {
227    /// The `chargingRateUnit` member.
228    #[serde(rename = "chargingRateUnit")]
229    pub charging_rate_unit: ChargingRateUnit,
230    /// The `chargingSchedulePeriod` member.
231    #[serde(rename = "chargingSchedulePeriod")]
232    pub charging_schedule_period: Vec<ChargingSchedulePeriod>,
233    /// The `duration` member.
234    #[serde(default, skip_serializing_if = "Option::is_none")]
235    pub duration: Option<i32>,
236    /// The `startSchedule` member.
237    #[serde(rename = "startSchedule")]
238    #[serde(default, skip_serializing_if = "Option::is_none")]
239    pub start_schedule: Option<crate::types::DateTime>,
240    /// The `minChargingRate` member.
241    #[serde(rename = "minChargingRate")]
242    #[serde(default, skip_serializing_if = "Option::is_none")]
243    pub min_charging_rate: Option<crate::types::Decimal>,
244}
245
246impl ChargingSchedule {
247    /// Creates a `ChargingSchedule` from its required fields.
248    #[must_use]
249    pub fn new(
250        charging_rate_unit: ChargingRateUnit,
251        charging_schedule_period: Vec<ChargingSchedulePeriod>,
252    ) -> Self {
253        Self {
254            charging_rate_unit,
255            charging_schedule_period,
256            duration: None,
257            start_schedule: None,
258            min_charging_rate: None,
259        }
260    }
261
262    /// Sets the optional `duration` field.
263    #[must_use]
264    pub fn with_duration(mut self, value: i32) -> Self {
265        self.duration = Some(value);
266        self
267    }
268
269    /// Sets the optional `startSchedule` field.
270    #[must_use]
271    pub fn with_start_schedule(mut self, value: impl Into<crate::types::DateTime>) -> Self {
272        self.start_schedule = Some(value.into());
273        self
274    }
275
276    /// Sets the optional `minChargingRate` field.
277    #[must_use]
278    pub fn with_min_charging_rate(mut self, value: impl Into<crate::types::Decimal>) -> Self {
279        self.min_charging_rate = Some(value.into());
280        self
281    }
282}
283
284impl Validate for ChargingSchedule {
285    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
286        path.push_key("chargingRateUnit");
287        Validate::validate_at(&self.charging_rate_unit, path, out);
288        path.pop();
289        path.push_key("chargingSchedulePeriod");
290        for (index, item) in self.charging_schedule_period.iter().enumerate() {
291            path.push_index(index);
292            Validate::validate_at(item, path, out);
293            path.pop();
294        }
295        path.pop();
296    }
297}
298
299/// The OCPP 1.6 `ChargingSchedulePeriod` data type.
300#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
301pub struct ChargingSchedulePeriod {
302    /// The `startPeriod` member.
303    #[serde(rename = "startPeriod")]
304    pub start_period: i32,
305    /// The `limit` member.
306    pub limit: crate::types::Decimal,
307    /// The `numberPhases` member.
308    #[serde(rename = "numberPhases")]
309    #[serde(default, skip_serializing_if = "Option::is_none")]
310    pub number_phases: Option<i32>,
311}
312
313impl ChargingSchedulePeriod {
314    /// Creates a `ChargingSchedulePeriod` from its required fields.
315    #[must_use]
316    pub fn new(start_period: i32, limit: impl Into<crate::types::Decimal>) -> Self {
317        Self {
318            start_period,
319            limit: limit.into(),
320            number_phases: None,
321        }
322    }
323
324    /// Sets the optional `numberPhases` field.
325    #[must_use]
326    pub fn with_number_phases(mut self, value: i32) -> Self {
327        self.number_phases = Some(value);
328        self
329    }
330}
331
332impl Validate for ChargingSchedulePeriod {
333    fn validate_at(&self, _path: &mut ValidationPath, _out: &mut Violations) {}
334}
335
336/// The OCPP 1.6 `Firmware` data type.
337#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
338pub struct Firmware {
339    /// The `location` member.
340    pub location: String,
341    /// The `retrieveDateTime` member.
342    #[serde(rename = "retrieveDateTime")]
343    pub retrieve_date_time: crate::types::DateTime,
344    /// The `signingCertificate` member.
345    #[serde(rename = "signingCertificate")]
346    pub signing_certificate: String,
347    /// The `signature` member.
348    pub signature: String,
349    /// The `installDateTime` member.
350    #[serde(rename = "installDateTime")]
351    #[serde(default, skip_serializing_if = "Option::is_none")]
352    pub install_date_time: Option<crate::types::DateTime>,
353}
354
355impl Firmware {
356    /// Creates a `Firmware` from its required fields.
357    #[must_use]
358    pub fn new(
359        location: impl Into<String>,
360        retrieve_date_time: impl Into<crate::types::DateTime>,
361        signing_certificate: impl Into<String>,
362        signature: impl Into<String>,
363    ) -> Self {
364        Self {
365            location: location.into(),
366            retrieve_date_time: retrieve_date_time.into(),
367            signing_certificate: signing_certificate.into(),
368            signature: signature.into(),
369            install_date_time: None,
370        }
371    }
372
373    /// Sets the optional `installDateTime` field.
374    #[must_use]
375    pub fn with_install_date_time(mut self, value: impl Into<crate::types::DateTime>) -> Self {
376        self.install_date_time = Some(value.into());
377        self
378    }
379}
380
381impl Validate for Firmware {
382    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
383        path.push_key("location");
384        validate::string(self.location.as_str(), None, Some(512), path, out);
385        path.pop();
386        path.push_key("signingCertificate");
387        validate::string(
388            self.signing_certificate.as_str(),
389            None,
390            Some(5500),
391            path,
392            out,
393        );
394        path.pop();
395        path.push_key("signature");
396        validate::string(self.signature.as_str(), None, Some(800), path, out);
397        path.pop();
398    }
399}
400
401/// The OCPP 1.6 `IdTagInfo` data type.
402#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
403pub struct IdTagInfo {
404    /// The `status` member.
405    pub status: AuthorizationStatus,
406    /// The `expiryDate` member.
407    #[serde(rename = "expiryDate")]
408    #[serde(default, skip_serializing_if = "Option::is_none")]
409    pub expiry_date: Option<crate::types::DateTime>,
410    /// The `parentIdTag` member.
411    #[serde(rename = "parentIdTag")]
412    #[serde(default, skip_serializing_if = "Option::is_none")]
413    pub parent_id_tag: Option<String>,
414}
415
416impl IdTagInfo {
417    /// Creates a `IdTagInfo` from its required fields.
418    #[must_use]
419    pub fn new(status: AuthorizationStatus) -> Self {
420        Self {
421            status,
422            expiry_date: None,
423            parent_id_tag: None,
424        }
425    }
426
427    /// Sets the optional `expiryDate` field.
428    #[must_use]
429    pub fn with_expiry_date(mut self, value: impl Into<crate::types::DateTime>) -> Self {
430        self.expiry_date = Some(value.into());
431        self
432    }
433
434    /// Sets the optional `parentIdTag` field.
435    #[must_use]
436    pub fn with_parent_id_tag(mut self, value: impl Into<String>) -> Self {
437        self.parent_id_tag = Some(value.into());
438        self
439    }
440}
441
442impl Validate for IdTagInfo {
443    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
444        path.push_key("status");
445        Validate::validate_at(&self.status, path, out);
446        path.pop();
447        path.push_key("parentIdTag");
448        if let Some(value) = &self.parent_id_tag {
449            validate::string(value.as_str(), None, Some(20), path, out);
450        }
451        path.pop();
452    }
453}
454
455/// The OCPP 1.6 `KeyValue` data type.
456#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
457pub struct KeyValue {
458    /// The `key` member.
459    pub key: String,
460    /// The `readonly` member.
461    pub readonly: bool,
462    /// The `value` member.
463    #[serde(default, skip_serializing_if = "Option::is_none")]
464    pub value: Option<String>,
465}
466
467impl KeyValue {
468    /// Creates a `KeyValue` from its required fields.
469    #[must_use]
470    pub fn new(key: impl Into<String>, readonly: bool) -> Self {
471        Self {
472            key: key.into(),
473            readonly,
474            value: None,
475        }
476    }
477
478    /// Sets the optional `value` field.
479    #[must_use]
480    pub fn with_value(mut self, value: impl Into<String>) -> Self {
481        self.value = Some(value.into());
482        self
483    }
484}
485
486impl Validate for KeyValue {
487    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
488        path.push_key("key");
489        validate::string(self.key.as_str(), None, Some(50), path, out);
490        path.pop();
491        path.push_key("value");
492        if let Some(value) = &self.value {
493            validate::string(value.as_str(), None, Some(500), path, out);
494        }
495        path.pop();
496    }
497}
498
499/// The OCPP 1.6 `LogParameters` data type.
500#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
501pub struct LogParameters {
502    /// The `remoteLocation` member.
503    #[serde(rename = "remoteLocation")]
504    pub remote_location: String,
505    /// The `oldestTimestamp` member.
506    #[serde(rename = "oldestTimestamp")]
507    #[serde(default, skip_serializing_if = "Option::is_none")]
508    pub oldest_timestamp: Option<crate::types::DateTime>,
509    /// The `latestTimestamp` member.
510    #[serde(rename = "latestTimestamp")]
511    #[serde(default, skip_serializing_if = "Option::is_none")]
512    pub latest_timestamp: Option<crate::types::DateTime>,
513}
514
515impl LogParameters {
516    /// Creates a `LogParameters` from its required fields.
517    #[must_use]
518    pub fn new(remote_location: impl Into<String>) -> Self {
519        Self {
520            remote_location: remote_location.into(),
521            oldest_timestamp: None,
522            latest_timestamp: None,
523        }
524    }
525
526    /// Sets the optional `oldestTimestamp` field.
527    #[must_use]
528    pub fn with_oldest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
529        self.oldest_timestamp = Some(value.into());
530        self
531    }
532
533    /// Sets the optional `latestTimestamp` field.
534    #[must_use]
535    pub fn with_latest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
536        self.latest_timestamp = Some(value.into());
537        self
538    }
539}
540
541impl Validate for LogParameters {
542    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
543        path.push_key("remoteLocation");
544        validate::string(self.remote_location.as_str(), None, Some(512), path, out);
545        path.pop();
546    }
547}
548
549/// The OCPP 1.6 `MeterValue` data type.
550#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
551pub struct MeterValue {
552    /// The `timestamp` member.
553    pub timestamp: crate::types::DateTime,
554    /// The `sampledValue` member.
555    #[serde(rename = "sampledValue")]
556    pub sampled_value: Vec<SampledValue>,
557}
558
559impl MeterValue {
560    /// Creates a `MeterValue` from its required fields.
561    #[must_use]
562    pub fn new(
563        timestamp: impl Into<crate::types::DateTime>,
564        sampled_value: Vec<SampledValue>,
565    ) -> Self {
566        Self {
567            timestamp: timestamp.into(),
568            sampled_value,
569        }
570    }
571}
572
573impl Validate for MeterValue {
574    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
575        path.push_key("sampledValue");
576        validate::list_len(self.sampled_value.len(), Some(1), None, path, out);
577        for (index, item) in self.sampled_value.iter().enumerate() {
578            path.push_index(index);
579            Validate::validate_at(item, path, out);
580            path.pop();
581        }
582        path.pop();
583    }
584}
585
586/// The OCPP 1.6 `SampledValue` data type.
587#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
588pub struct SampledValue {
589    /// The `value` member.
590    pub value: String,
591    /// The `context` member.
592    #[serde(default, skip_serializing_if = "Option::is_none")]
593    pub context: Option<ReadingContext>,
594    /// The `format` member.
595    #[serde(default, skip_serializing_if = "Option::is_none")]
596    pub format: Option<ValueFormat>,
597    /// The `measurand` member.
598    #[serde(default, skip_serializing_if = "Option::is_none")]
599    pub measurand: Option<Measurand>,
600    /// The `phase` member.
601    #[serde(default, skip_serializing_if = "Option::is_none")]
602    pub phase: Option<Phase>,
603    /// The `location` member.
604    #[serde(default, skip_serializing_if = "Option::is_none")]
605    pub location: Option<Location>,
606    /// The `unit` member.
607    #[serde(default, skip_serializing_if = "Option::is_none")]
608    pub unit: Option<UnitOfMeasure>,
609}
610
611impl SampledValue {
612    /// Creates a `SampledValue` from its required fields.
613    #[must_use]
614    pub fn new(value: impl Into<String>) -> Self {
615        Self {
616            value: value.into(),
617            context: None,
618            format: None,
619            measurand: None,
620            phase: None,
621            location: None,
622            unit: None,
623        }
624    }
625
626    /// Sets the optional `context` field.
627    #[must_use]
628    pub fn with_context(mut self, value: ReadingContext) -> Self {
629        self.context = Some(value);
630        self
631    }
632
633    /// Sets the optional `format` field.
634    #[must_use]
635    pub fn with_format(mut self, value: ValueFormat) -> Self {
636        self.format = Some(value);
637        self
638    }
639
640    /// Sets the optional `measurand` field.
641    #[must_use]
642    pub fn with_measurand(mut self, value: Measurand) -> Self {
643        self.measurand = Some(value);
644        self
645    }
646
647    /// Sets the optional `phase` field.
648    #[must_use]
649    pub fn with_phase(mut self, value: Phase) -> Self {
650        self.phase = Some(value);
651        self
652    }
653
654    /// Sets the optional `location` field.
655    #[must_use]
656    pub fn with_location(mut self, value: Location) -> Self {
657        self.location = Some(value);
658        self
659    }
660
661    /// Sets the optional `unit` field.
662    #[must_use]
663    pub fn with_unit(mut self, value: UnitOfMeasure) -> Self {
664        self.unit = Some(value);
665        self
666    }
667}
668
669impl Validate for SampledValue {
670    fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
671        path.push_key("context");
672        if let Some(value) = &self.context {
673            Validate::validate_at(value, path, out);
674        }
675        path.pop();
676        path.push_key("format");
677        if let Some(value) = &self.format {
678            Validate::validate_at(value, path, out);
679        }
680        path.pop();
681        path.push_key("measurand");
682        if let Some(value) = &self.measurand {
683            Validate::validate_at(value, path, out);
684        }
685        path.pop();
686        path.push_key("phase");
687        if let Some(value) = &self.phase {
688            Validate::validate_at(value, path, out);
689        }
690        path.pop();
691        path.push_key("location");
692        if let Some(value) = &self.location {
693            Validate::validate_at(value, path, out);
694        }
695        path.pop();
696        path.push_key("unit");
697        if let Some(value) = &self.unit {
698            Validate::validate_at(value, path, out);
699        }
700        path.pop();
701    }
702}