pub struct SmlFile<'a> {
pub file_id: &'a [u8],
pub messages: &'a [Body<'a>],
}Expand description
An SML file: an open, the requests (or responses) and a close, sharing one file ID.
write gives every message a transaction ID unique in the file (the
file ID’s first seven bytes and the message number) and its own CRC. A meter repeats a
request’s transaction ID in its answer, which is how a client matches the two.
use sml_kit::{Body, CloseRequest, GetListRequest, OpenRequest, SmlFile, encode_frame};
let bodies = [
Body::OpenRequest(OpenRequest {
codepage: None,
client_id: b"gw-1",
req_file_id: b"F42",
server_id: None,
username: None,
password: None,
sml_version: None,
}),
Body::GetListRequest(GetListRequest {
client_id: b"gw-1",
server_id: None,
username: None,
password: None,
list_name: None,
}),
Body::CloseRequest(CloseRequest { global_signature: None }),
];
let mut payload = [0u8; 128];
let n = SmlFile { file_id: b"F42", messages: &bodies }.write(&mut payload)?;
let mut wire = [0u8; 300];
let len = encode_frame(&payload[..n], &mut wire)?; // send &wire[..len]The shape is checked, not the direction: a file must start with an OpenRequest or
OpenResponse, end with a CloseRequest or CloseResponse, and have at most 256
messages; anything else is Error::InvalidFile. Every message is written with
group_no 0 and abort_on_error 0; for other values write Messages one by one.
Debug shows each body through its own Debug, which prints passwords as
<redacted>.
Fields§
§file_id: &'a [u8]The file ID, also the prefix of every transaction ID.
messages: &'a [Body<'a>]The messages, in order.