Skip to main content

Client

Struct Client 

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub fn get_selected( &mut self, attribute: AttributeDescriptor, access: SelectiveAccess<'_>, ) -> Result<DataBuf, ClientError>

Read part of an attribute — a range of a profile, by entry or by date.

§Errors

As Client::get.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn negotiated(&self) -> Option<&InitiateResponse>

What the meter agreed to.

Source

pub const fn session(&self) -> &ClientSession<P, N>

The session underneath, for anything this layer does not wrap.

Source

pub const fn session_mut(&mut self) -> &mut ClientSession<P, N>

The session underneath, mutably.

Source

pub const fn transport_mut(&mut self) -> &mut T

The transport underneath.

Trait Implementations§

Source§

impl<T, P: CryptoProvider, const N: usize> Debug for Client<T, P, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The session’s state and counters only: never the provider, whose keys these are, and never a buffer, which may hold a decrypted response.

Auto Trait Implementations§

§

impl<T, P, const N: usize> Forget for Client<T, P, N>

§

impl<T, P, const N: usize> Freeze for Client<T, P, N>
where InternalBitFlags: Freeze, P: Freeze, T: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl<T, P, const N: usize> Move for Client<T, P, N>

§

impl<T, P, const N: usize> RefUnwindSafe for Client<T, P, N>
where InternalBitFlags: RefUnwindSafe, P: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, P, const N: usize> Send for Client<T, P, N>
where P: Send, T: Send, InternalBitFlags: Send, RawVecInner: Send,

§

impl<T, P, const N: usize> Sync for Client<T, P, N>
where P: Sync, T: Sync, InternalBitFlags: Sync, RawVecInner: Sync,

§

impl<T, P, const N: usize> Unpin for Client<T, P, N>
where P: Unpin, T: Unpin, InternalBitFlags: Unpin, *const u8 is !null: Unpin,

§

impl<T, P, const N: usize> UnsafeUnpin for Client<T, P, N>
where InternalBitFlags: UnsafeUnpin, P: UnsafeUnpin, T: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

§

impl<T, P, const N: usize> UnwindSafe for Client<T, P, N>
where InternalBitFlags: UnwindSafe, P: UnwindSafe, T: UnwindSafe, RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.