Skip to main content

FileStore

Struct FileStore 

Source
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

Source

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.

Source

pub fn path(&self) -> &Path

The journal’s path.

Source

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.

Trait Implementations§

Source§

impl Debug for FileStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MessageStore for FileStore

Source§

fn push(&mut self, entry: &QueuedCall) -> Result<Seq, StoreError>

Appends a message, returning its sequence number.
Source§

fn pending(&self) -> Result<Vec<(Seq, QueuedCall)>, StoreError>

Every un-acknowledged message, oldest first. Read more
Source§

fn ack(&mut self, seq: Seq) -> Result<(), StoreError>

Removes a message that has been delivered (or definitively abandoned).
Source§

fn set_attempts(&mut self, seq: Seq, attempts: u32) -> Result<(), StoreError>

Records a further transmission attempt for a message that is still queued.
Source§

fn len(&self) -> Result<usize, StoreError>

How many messages are waiting. Read more
Source§

fn is_empty(&self) -> Result<bool, StoreError>

Whether the store is empty.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.