pub struct FileStore { /* private fields */ }Expand description
A MessageStore that survives a power cut, for the station side.
An append-only journal, one line of JSON per change. A Charging Station must replay the
transaction messages an outage interrupted (E04.FR.01–03, E08.FR.05–07, E12.FR.01–02),
which MemStore cannot.
use ocpp_kit::Version;
use ocpp_kit::engine::{Engine, EngineConfig, FileStore, Role};
// Whatever the outage interrupted is back in the queue by the time this returns.
let store = FileStore::open("/var/lib/ocpp/queue.jsonl")?;
let engine = Engine::with_store(
EngineConfig::new(Role::ChargingStation, Version::V2_1),
store,
)?;§Guarantees
push returns only once the record has reached the device
(sync_data). A crash mid-append leaves a partial final line, discarded on the next open:
it described a message that was never reported as queued.
One process, one file — checked, not assumed. A second writer produces a sequence number
twice, which one forward-only counter cannot, and open refuses the journal
and names the cause. Refused rather than repaired: the interleaved records are each
well-formed, so a repair would be a guess about whose queue is real.
No defence against a corrupt filesystem. For anything else, implement MessageStore; it
is four synchronous methods.
Implementations§
Source§impl FileStore
impl FileStore
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, StoreError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, StoreError>
Opens (or creates) the journal at path, replaying whatever an outage left behind.
The parent directory must exist. Replaying compacts: the file that comes back holds exactly the messages that are still queued.
Sourcepub fn compact(&mut self) -> Result<(), StoreError>
pub fn compact(&mut self) -> Result<(), StoreError>
Rewrites the journal so it holds only what is still queued.
Called on open and whenever the dead records outnumber the live ones; exposed because a long-running station may want to schedule it rather than pay for it mid-transaction.