pub struct Client<T, P, const N: usize = 1024> { /* private fields */ }Expand description
A blocking DLMS client over a Transport.
N is the session’s request buffer: the largest request it builds before block
transfer takes over. Single-value reads accept at most 64 KiB of encoded A-XDR data
by default. Set the limit with Client::with_response_capacity or supply a smaller
output slice to Client::get_into. Transport framing and protection use separate
workspace.
Call Client::release to release the association before dropping the client.
Implementations§
Source§impl<T: Transport, P: CryptoProvider, const N: usize> Client<T, P, N>
impl<T: Transport, P: CryptoProvider, const N: usize> Client<T, P, N>
Sourcepub fn connect(
transport: T,
config: ClientConfig,
provider: P,
) -> Result<Self, ClientError>
pub fn connect( transport: T, config: ClientConfig, provider: P, ) -> Result<Self, ClientError>
Associate over transport, running every pass the mechanism needs.
Returns only once the association is established — for high-level security, after the meter has proven it holds the key, not merely after it accepted ours.
§Errors
ClientError::Rejected or ClientError::Exception when the meter refuses;
ClientError::Protocol when its proof does not verify; ClientError::Io.
Sourcepub fn with_response_capacity(self, bytes: usize) -> Self
pub fn with_response_capacity(self, bytes: usize) -> Self
Set the maximum encoded value size for a GET, including its A-XDR type tag.
The default is 64 KiB. The limit also bounds the encoded result list for a
list GET and the encoded return value of an ACTION. A smaller caller buffer
further limits a get_into call.
The configured receive PDU determines the frame size independently of this limit. GBT may stage up to the effective limit plus one receive frame for the protected APDU envelope. Set transport timeouts and wire budgets separately.
Sourcepub fn get(
&mut self,
attribute: AttributeDescriptor,
) -> Result<DataBuf, ClientError>
pub fn get( &mut self, attribute: AttributeDescriptor, ) -> Result<DataBuf, ClientError>
Read an attribute.
§Errors
ClientError::Refused with the meter’s reason, ClientError::ResponseTooLarge
with the effective limit and recovery status, or a transport or protocol error.
Sourcepub fn get_selected(
&mut self,
attribute: AttributeDescriptor,
access: SelectiveAccess<'_>,
) -> Result<DataBuf, ClientError>
pub fn get_selected( &mut self, attribute: AttributeDescriptor, access: SelectiveAccess<'_>, ) -> Result<DataBuf, ClientError>
Sourcepub fn get_into<'a>(
&mut self,
attribute: AttributeDescriptor,
access: Option<SelectiveAccess<'_>>,
out: &'a mut [u8],
) -> Result<Data<'a>, ClientError>
pub fn get_into<'a>( &mut self, attribute: AttributeDescriptor, access: Option<SelectiveAccess<'_>>, out: &'a mut [u8], ) -> Result<Data<'a>, ClientError>
Read one attribute, optionally selected, into caller-owned storage.
The result borrows only out; the client can issue another request while the
value is in use. The slice must fit the entire encoded value including its tag.
On error its contents are unspecified.
§Errors
ClientError::ResponseTooLarge reports the effective limit. A completed,
verified response leaves the association usable. If reconnect_required is
true, the session is closed locally. ClientError::Refused preserves the
meter’s access result.
Sourcepub fn get_list(
&mut self,
attributes: &[AttributeDescriptor],
) -> Result<Vec<Result<DataBuf, DataAccessResult>>, ClientError>
pub fn get_list( &mut self, attributes: &[AttributeDescriptor], ) -> Result<Vec<Result<DataBuf, DataAccessResult>>, ClientError>
Read several attributes in one round trip, one result each.
A refused attribute does not fail the call: its slot holds the reason.
§Errors
When the whole request fails.
Sourcepub fn read_scaled(
&mut self,
class_id: u16,
logical_name: Obis,
) -> Result<ScaledValue, ClientError>
pub fn read_scaled( &mut self, class_id: u16, logical_name: Obis, ) -> Result<ScaledValue, ClientError>
Read a register’s value with its scaler and unit — the attribute pair a register, an extended register and a demand register (classes 3, 4, 5) all carry as 2 and 3 — in one round trip.
§Errors
When either attribute is refused, or is not the shape a register’s is.
Sourcepub fn set(
&mut self,
attribute: AttributeDescriptor,
value: &Data<'_>,
) -> Result<(), ClientError>
pub fn set( &mut self, attribute: AttributeDescriptor, value: &Data<'_>, ) -> Result<(), ClientError>
Write an attribute. A value too large for one APDU is sent in blocks.
§Errors
ClientError::Refused with the meter’s reason; any transport or protocol error.
Sourcepub fn action(
&mut self,
method: MethodDescriptor,
parameter: Option<&Data<'_>>,
) -> Result<Option<DataBuf>, ClientError>
pub fn action( &mut self, method: MethodDescriptor, parameter: Option<&Data<'_>>, ) -> Result<Option<DataBuf>, ClientError>
Invoke a method, returning what it returned. A parameter too large for one APDU is sent in blocks, and so is a return value too large for one.
§Errors
ClientError::ActionFailed with the method’s result; any transport or protocol
error.
Sourcepub fn release(self) -> Result<T, ClientError>
pub fn release(self) -> Result<T, ClientError>
Release the association, close the link and hand the transport back — only once the meter has confirmed the release.
Success means a release response arrived and released: commit what the association read on it. The link is closed on every path.
§Errors
ClientError::ReleaseRefused with the meter’s reason;
ClientError::NotAssociated after a transfer that ended the association (use
Client::disconnect); ClientError::Io when the link fails or the meter
closes it before answering; ClientError::Exception or a protocol error.
Sourcepub fn disconnect(self) -> Result<T, ClientError>
pub fn disconnect(self) -> Result<T, ClientError>
Close the link without releasing the association, handing the transport back.
For a session that has already ended, or a meter that ends associations by dropping the link.
fn read_once<T: Transport, P: CryptoProvider>(
mut meter: Client<T, P>,
profile: AttributeDescriptor,
) -> Result<T, ClientError> {
match meter.get(profile) {
// The transfer was abandoned and the association is gone: nothing to release.
Err(ClientError::ResponseTooLarge { reconnect_required: true, .. }) => meter.disconnect(),
Err(e) => Err(e),
Ok(_rows) => meter.release(), // commit `_rows` once this succeeds
}
}§Errors
When closing the link fails.
Sourcepub const fn invocation_counter(&self) -> u32
pub const fn invocation_counter(&self) -> u32
The invocation counter this client will use next.
Persist it before the process ends and pass it back as
ClientConfig::invocation_counter next time: restarting from an old value under
an unchanged key repeats GCM nonces, and a repeated nonce leaks the key’s
authentication subkey.
Sourcepub const fn negotiated(&self) -> Option<&InitiateResponse>
pub const fn negotiated(&self) -> Option<&InitiateResponse>
What the meter agreed to.
Sourcepub const fn session(&self) -> &ClientSession<P, N>
pub const fn session(&self) -> &ClientSession<P, N>
The session underneath, for anything this layer does not wrap.
Sourcepub const fn session_mut(&mut self) -> &mut ClientSession<P, N>
pub const fn session_mut(&mut self) -> &mut ClientSession<P, N>
The session underneath, mutably.
Sourcepub const fn transport_mut(&mut self) -> &mut T
pub const fn transport_mut(&mut self) -> &mut T
The transport underneath.