1use bytes::{Buf, BufMut};
4
5use crate::{
6 Error,
7 protocol::codec::{BitSize, Decode, Encode},
8};
9
10pub mod mq2200;
11
12macro_rules! impl_new_type {
14 ($target:ident => $inner:ty) => {
15 impl BitSize for $target<$inner> {
16 const N_BITS: u16 = <$inner as BitSize>::N_BITS;
17 }
18
19 impl Decode for $target<$inner> {
20 fn decode(from: &mut impl Buf) -> Result<Self, Error> {
21 <$inner>::decode(from).map(Self)
22 }
23 }
24
25 impl Encode for $target<$inner> {
26 fn encode(&self, to: &mut impl BufMut) {
27 self.0.encode(to);
28 }
29 }
30 };
31}
32
33#[derive(Copy, Clone, Debug, Eq, PartialEq)]
34pub struct Percentage<T>(pub T);
35
36impl_new_type!(Percentage => u16);
37
38#[derive(Copy, Clone, Debug, Eq, PartialEq)]
39pub struct DecawattHours<T>(pub T);
40
41impl_new_type!(DecawattHours => u16);
42
43#[derive(Copy, Clone, Debug, Eq, PartialEq)]
44pub struct Watts<T>(pub T);
45
46impl_new_type!(Watts => u16);
47impl_new_type!(Watts => i32);