use core::marker::PhantomData;
use bytes::{Buf, BufMut};
use crate::{
Error,
protocol::{
Address,
codec::{BitSize, Decode, Encode},
function::{IntoValue, size_argument::SizeArgument},
},
};
pub struct Args<A, V, S>(
A,
V,
PhantomData<S>,
);
impl<A, V, S> Args<A, V, S> {
pub const fn new(address: A, value: V) -> Self {
Self(address, value, PhantomData)
}
}
impl<A: Address, V: BitSize + Encode, S: SizeArgument> Encode for Args<A, V, S> {
fn encode_to(&self, buf: &mut impl BufMut) {
S::assert_valid_size::<V, 246>();
self.0.encode_to(buf);
buf.put_u16(S::quantity_for::<V>());
buf.put_u8(V::N_BYTES);
self.1.encode_to(buf);
}
}
pub struct Output {
pub starting_address: u16,
pub count: u16,
}
impl IntoValue for Output {
type Value = Self;
fn into_value(self) -> Self::Value {
self
}
}
impl Decode for Output {
fn decode_from(buf: &mut impl Buf) -> Result<Self, Error> {
Ok(Self { starting_address: u16::decode_from(buf)?, count: u16::decode_from(buf)? })
}
}