codetics-ocpp-core 0.1.0

Codetics OCPP: version-independent OCPP-J building blocks (RPC framing, error codes, RFC 3339 date-time, validation, subprotocol negotiation, message ids)
Documentation
  • Coverage
  • 33.33%
    44 out of 132 items documented0 out of 60 items with examples
  • Size
  • Source code size: 65.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 946.7 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 6s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kevinvavelin

codetics-ocpp-core

Version-independent building blocks of OCPP-J, the JSON-over-WebSocket transport of OCPP 1.6, 2.0.1 and 2.1:

  • RPC framing: CALL, CALLRESULT, CALLERROR, and the OCPP 2.1 CALLRESULTERROR and SEND message types;
  • RPC error codes, including the historic OCPP 1.6 spellings (FormationViolation, OccurenceConstraintViolation);
  • version negotiation through the Sec-WebSocket-Protocol subprotocol (ocpp1.6, ocpp2.0.1, ocpp2.1);
  • an RFC 3339 DateTime, schema-constraint validation (Validate) and unique message ids.
use codetics_ocpp_core::rpc::{self, Frame};
use codetics_ocpp_core::version::negotiate;
use codetics_ocpp_core::{ErrorCode, ErrorDialect, OcppVersion, RpcError};

// The client lists versions by preference; the server picks the first acceptable one.
let (version, token) = negotiate(["ocpp2.1, ocpp1.6"], &[OcppVersion::V16]).unwrap();
assert_eq!((version, token), (OcppVersion::V16, "ocpp1.6"));

match Frame::parse(r#"[2,"19223201","Heartbeat",{}]"#).unwrap() {
    Frame::Call { id, action, .. } => {
        assert_eq!(action, "Heartbeat");
        let reply = rpc::encode_result(&id, &serde_json::json!({ "currentTime": "2025-01-01T00:00:00Z" })).unwrap();
        assert!(reply.starts_with(r#"[3,"19223201""#));
    }
    _ => unreachable!(),
}

let err = RpcError::new(ErrorCode::FormatViolation, "bad payload");
assert_eq!(rpc::encode_error("1", &err, ErrorDialect::Ocpp16, false), r#"[4,"1","FormationViolation","bad payload",{}]"#);

Part of Codetics OCPP

This crate belongs to Codetics OCPP, a complete OCPP 1.6J / 2.0.1 / 2.1 implementation in Rust written by Kevin Vavelin (Codetics). It can be used as is; contributions are welcome.

License and credit

Licensed under the Apache License, Version 2.0.

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 file crediting Kevin Vavelin / Codetics as the origin of the work.