use core::marker::PhantomData;
use bytes::{Buf, BufMut};
use crate::{
Error,
protocol::{
Address,
codec::{BitSize, Decode, Encode},
function::{IntoValue, size_argument},
},
};
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> Encode for Args<A, V, size_argument::Words> {
fn encode(&self, to: &mut impl BufMut) {
V::assert_valid::<246>();
self.0.encode(to);
to.put_u16(V::N_WORDS);
to.put_u8(V::N_BYTES);
self.1.encode(to);
}
}
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: &mut impl Buf) -> Result<Self, Error> {
Ok(Self { starting_address: u16::decode(from)?, count: u16::decode(from)? })
}
}