mediation 0.3.0

Telecom usage mediation as a pure Rust library: normalise, deduplicate, correlate and reconcile CDRs from mobile and fixed-line networks, with a conservation law that proves no record was lost. Zero I/O, no clock, integer quantities.
Documentation

๐Ÿ“ก mediation

Crates.io Docs.rs CI MSRV License

The arithmetic between a telecom network โ€” mobile or fixed โ€” and a billing system: normalising, validating, deduplicating and correlating usage records, and proving none was lost.

๐ŸงŠ Zero I/O ยท โฑ๏ธ no async ยท ๐Ÿ•ฐ๏ธ no clock ยท ๐Ÿ”ข exact integer quantities ยท ๐Ÿ”’ no unsafe

It computes usage, not money: octets, seconds and event counts, attributed to a charged party, a network and a service. Pricing belongs to the rating layer.

๐Ÿ“– Documentation ยท ๐Ÿฆ€ API reference

๐Ÿ“ฆ Install

cargo add mediation                  # or: --features serde

serde (off by default) adds Serialize/Deserialize in each type's canonical string form. MSRV is Rust 1.94 (edition 2024). Pre-1.0: breaking changes ship as minor releases.

๐Ÿš€ One pass over a batch

process deduplicates, reassembles, checks sequence gaps, validates and disposes every record, and returns a reconciliation that must balance:

carried_in + ingested == billable + suppressed + duplicate + rejected + held
use mediation::{Batch, DedupWindow, ProcessConfig, ProcessState, process};
use time::{Duration, macros::datetime};
# use mediation::{ChargedParty, ChargingId, CorrelationKeys, Octets, RecordType,
#                 SourceRef, SubscriberRef, UsageRecord, VolumePair};
# use std::net::Ipv4Addr;
# fn session(id: u32) -> UsageRecord {
#     UsageRecord::new(
#         RecordType::PduSession,
#         ChargedParty::Subscriber(SubscriberRef::new("imsi-262021234567890".parse().unwrap())),
#         "2026-07-28T10:00:00+02:00".parse().unwrap(),
#         SourceRef::new("pgw-fra-01".parse().unwrap(), 0).with_file_sequence(42),
#     )
#     .with_closed("2026-07-28T10:30:00+02:00".parse().unwrap())
#     .with_volume(VolumePair::new(Octets::new(4_096), Octets::new(65_536)))
#     .with_correlation(CorrelationKeys::default()
#         .with_charging_id(ChargingId::new(id))
#         .with_gateway(Ipv4Addr::new(10, 0, 0, 1).into()))
# }
let records: Vec<UsageRecord> = (1..=5).map(session).collect();

let mut state = ProcessState::new(DedupWindow::from_bound(Duration::days(7)).unwrap());
let outcome = process(
    &Batch::new(&records),
    &ProcessConfig::default(),
    datetime!(2026-07-28 12:00:00 UTC),
    &mut state,
);

assert!(outcome.reconciliation().balances());
assert_eq!(outcome.reconciliation().released(), 5);
assert!(outcome.is_releasable());

ProcessState (dedup keys, sequence high-water marks, held records) is owned by the caller and serialisable, so process stays a pure function of (batch, config, as_of, state) and a replay gives the same verdicts.

๐Ÿ“š Topics

Page Failure it prevents
Time Local CDR time read as UTC books events on the wrong day
Quantities Float volumes lose octets; MB means two things
Identity Malformed IMSI/MSISDN/IMEI reaching billing
Fixed-line voice Dial strings that are not E.164 numbers
Completeness A lost file leaves no trace except a sequence hole
Deduplication Retransmissions billed twice
Conservation A record lost between ingest and release
Validation The rule catalogue V01โ€“V21 and the release gate
Regulatory Jurisdiction, EU fair use, retention, itemised bills

๐Ÿšซ Out of scope

Collection and transport (GTPโ€ฒ, SFTP, Kafka, Diameter), rating and pricing, online charging (Ro/Nchf), scheduling and storage, and generated ASN.1 schemas. Decoding bytes already in memory is in scope; fetching them is not.

๐Ÿงช Development

just ci     # fmt, clippy, purity, no-floats, tests, docs, wasm, site check, package

Every Rust block in this README and on the documentation site runs as a doctest (ReadmeDoctests and site_doctests in src/lib.rs). New rules cite the clause they implement and come with a test.

๐Ÿ“„ License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

โ„น๏ธ Rules derived from published standards and regulations. Not legal advice; verify against the current text for your use case.