Skip to main content

sml_kit/
lib.rs

1#![no_std]
2#![forbid(unsafe_code)]
3#![deny(missing_docs)]
4// Every byte this crate reads comes from a meter before anything about it is known, so
5// the ways a decoder can abort the process are denied outright rather than reviewed.
6#![deny(
7    clippy::panic,
8    clippy::unwrap_used,
9    clippy::expect_used,
10    clippy::todo,
11    clippy::unimplemented,
12    clippy::indexing_slicing,
13    clippy::exit
14)]
15#![warn(clippy::pedantic)]
16// A test is allowed to abort: that is what a failing assertion is.
17#![cfg_attr(test, allow(clippy::unwrap_used, clippy::panic, clippy::expect_used, clippy::indexing_slicing))]
18#![allow(clippy::module_name_repetitions, clippy::must_use_candidate, clippy::missing_errors_doc)]
19// The crate docs are the README: prose with manufacturer names, not identifiers.
20#![allow(clippy::doc_markdown)]
21#![cfg_attr(docsrs, feature(doc_cfg))]
22#![doc = include_str!("../README.md")]
23
24#[cfg(feature = "std")]
25extern crate std;
26
27pub mod attention;
28pub mod crc;
29mod error;
30mod file;
31#[cfg(feature = "std")]
32#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
33pub mod io;
34pub mod message;
35mod obis;
36mod profile;
37mod seq;
38mod server_id;
39pub mod sim;
40mod status;
41pub mod tl;
42pub mod transport;
43mod tree;
44mod value;
45
46pub use crc::CrcCheck;
47pub use error::{Error, Result};
48pub use file::SmlFile;
49pub use message::{
50    Attention, Body, CloseRequest, CloseResponse, GetListRequest, GetListResponse, GetProcParameterRequest,
51    GetProcParameterResponse, GetProfileListResponse, GetProfileRequest, ListEntries, ListEntry, Message,
52    Messages, OpenRequest, OpenResponse, ParseOptions, SetProcParameterRequest, readout_with,
53};
54pub use obis::Obis;
55pub use profile::{
56    GetProfilePackResponse, ProfileColumn, ProfileColumns, ProfilePeriod, ProfilePeriods, ProfileValue,
57    ProfileValues,
58};
59pub use seq::{Element, Seq, SeqIter};
60pub use server_id::ServerId;
61pub use status::{Direction, StatusWord};
62pub use tl::{Kind, Reader, Writer};
63pub use transport::{Decoder, encode_frame};
64pub use tree::{NameList, PeriodEntries, PeriodEntry, ProcParValue, Register, Tree, Trees, TupelEntry};
65pub use value::{Quantity, SmlValue, Time, Unit};
66
67/// Parse every SML message in one unescaped transport payload (one SML file), with the
68/// default, strict options.
69///
70/// The payload is what [`Decoder`] hands out for each frame.
71pub fn messages(payload: &[u8]) -> Messages<'_> {
72    Messages::new(payload, ParseOptions::default())
73}
74
75/// The readings in one transport payload, strictly: every message must parse, and the
76/// first `GetListResponse` is returned. [`Error::NoReadings`] if there is none.
77///
78/// For a meter that deviates from the specification, use [`readout_with`].
79pub fn readout(payload: &[u8]) -> Result<GetListResponse<'_>> {
80    readout_with(payload, ParseOptions::default())
81}
82
83/// Every public data type can cross threads (Rust API Guidelines C-SEND-SYNC); generic
84/// ones when their parameter can.
85const _: () = {
86    const fn send_sync<T: Send + Sync>() {}
87    send_sync::<Error>();
88    send_sync::<SmlFile<'static>>();
89    send_sync::<Message<'static>>();
90    send_sync::<Messages<'static>>();
91    send_sync::<GetListResponse<'static>>();
92    send_sync::<ListEntries<'static>>();
93    send_sync::<Tree<'static>>();
94    send_sync::<Decoder<[u8; 8]>>();
95    send_sync::<Reader<'static>>();
96    send_sync::<Writer<'static>>();
97    send_sync::<ParseOptions>();
98    send_sync::<Quantity>();
99    send_sync::<ServerId<'static>>();
100};