sml-kit 0.1.0

SML (Smart Message Language) for Rust: German smart meter readout with a sans-I/O, no_std, allocation-free core
Documentation
#![no_std]
#![forbid(unsafe_code)]
#![deny(missing_docs)]
// Every byte this crate reads comes from a meter before anything about it is known, so
// the ways a decoder can abort the process are denied outright rather than reviewed.
#![deny(
    clippy::panic,
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::todo,
    clippy::unimplemented,
    clippy::indexing_slicing,
    clippy::exit
)]
#![warn(clippy::pedantic)]
// A test is allowed to abort: that is what a failing assertion is.
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::panic, clippy::expect_used, clippy::indexing_slicing))]
#![allow(clippy::module_name_repetitions, clippy::must_use_candidate, clippy::missing_errors_doc)]
// The crate docs are the README: prose with manufacturer names, not identifiers.
#![allow(clippy::doc_markdown)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]

#[cfg(feature = "std")]
extern crate std;

pub mod attention;
pub mod crc;
mod error;
mod file;
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub mod io;
pub mod message;
mod obis;
mod profile;
mod seq;
mod server_id;
pub mod sim;
mod status;
pub mod tl;
pub mod transport;
mod tree;
mod value;

pub use crc::CrcCheck;
pub use error::{Error, Result};
pub use file::SmlFile;
pub use message::{
    Attention, Body, CloseRequest, CloseResponse, GetListRequest, GetListResponse, GetProcParameterRequest,
    GetProcParameterResponse, GetProfileListResponse, GetProfileRequest, ListEntries, ListEntry, Message,
    Messages, OpenRequest, OpenResponse, ParseOptions, SetProcParameterRequest, readout_with,
};
pub use obis::Obis;
pub use profile::{
    GetProfilePackResponse, ProfileColumn, ProfileColumns, ProfilePeriod, ProfilePeriods, ProfileValue,
    ProfileValues,
};
pub use seq::{Element, Seq, SeqIter};
pub use server_id::ServerId;
pub use status::{Direction, StatusWord};
pub use tl::{Kind, Reader, Writer};
pub use transport::{Decoder, encode_frame};
pub use tree::{NameList, PeriodEntries, PeriodEntry, ProcParValue, Register, Tree, Trees, TupelEntry};
pub use value::{Quantity, SmlValue, Time, Unit};

/// Parse every SML message in one unescaped transport payload (one SML file), with the
/// default, strict options.
///
/// The payload is what [`Decoder`] hands out for each frame.
pub fn messages(payload: &[u8]) -> Messages<'_> {
    Messages::new(payload, ParseOptions::default())
}

/// The readings in one transport payload, strictly: every message must parse, and the
/// first `GetListResponse` is returned. [`Error::NoReadings`] if there is none.
///
/// For a meter that deviates from the specification, use [`readout_with`].
pub fn readout(payload: &[u8]) -> Result<GetListResponse<'_>> {
    readout_with(payload, ParseOptions::default())
}

/// Every public data type can cross threads (Rust API Guidelines C-SEND-SYNC); generic
/// ones when their parameter can.
const _: () = {
    const fn send_sync<T: Send + Sync>() {}
    send_sync::<Error>();
    send_sync::<SmlFile<'static>>();
    send_sync::<Message<'static>>();
    send_sync::<Messages<'static>>();
    send_sync::<GetListResponse<'static>>();
    send_sync::<ListEntries<'static>>();
    send_sync::<Tree<'static>>();
    send_sync::<Decoder<[u8; 8]>>();
    send_sync::<Reader<'static>>();
    send_sync::<Writer<'static>>();
    send_sync::<ParseOptions>();
    send_sync::<Quantity>();
    send_sync::<ServerId<'static>>();
};