# codetics-ocpp21
Every OCPP 2.1 (Edition 2) message as plain Rust types, including the new functional areas (bidirectional
power transfer and DER control, dynamic and priority charging profiles, local cost calculation with tariffs,
battery swapping, periodic event streams) and the unconfirmed `SEND` message type.
- `serde` mappings matching the message definitions; `customData` extensions are preserved;
- `Validate` implementations for length, range and cardinality constraints, with violations mapped to OCPP-J error codes;
- `Action` with message direction, and typed dispatch: `StationCall`, `CsmsCall` and `StationSend`.
```rust
use codetics_ocpp21::{Action, Direction, StationSend};
assert_eq!(Action::BatterySwap.direction(), Direction::StationToCsms);
assert!(Action::NotifyPeriodicEventStream.is_send());
let p = r#"{"id":1,"pending":0,"basetime":"2025-01-01T00:00:00Z","data":[{"t":0,"v":"230.4"}]}"#;
let StationSend::NotifyPeriodicEventStream(stream) = StationSend::decode("NotifyPeriodicEventStream", p).unwrap();
assert_eq!(stream.data.len(), 1);
```
## Part of Codetics OCPP
This crate belongs to [Codetics OCPP](https://codetics.fr), a complete OCPP 1.6J / 2.0.1 / 2.1
implementation in Rust written by **Kevin Vavelin** ([Codetics](https://codetics.fr)).
It can be used as is; contributions are welcome.
## License and credit
Licensed under the [Apache License, Version 2.0](LICENSE).
Copyright 2026 Kevin Vavelin, Codetics. Any redistribution of this crate or of a work derived
from it (including forks and products embedding it) must keep the copyright notice and include
the [NOTICE](NOTICE) file crediting Kevin Vavelin / Codetics as the origin of the work.