sunspec/models/
model14.rs1#[derive(Debug)]
6#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
7pub struct Model14 {
8 pub nam: Option<String>,
12 pub cap: Cap,
16 pub cfg: u16,
20 pub typ: Typ,
24 pub addr: String,
28 pub port: u16,
32 pub user: Option<String>,
36 pub pw: Option<String>,
40}
41#[allow(missing_docs)]
42impl Model14 {
43 pub const NAM: crate::Point<Self, Option<String>> = crate::Point::new(0, 4, true);
44 pub const CAP: crate::Point<Self, Cap> = crate::Point::new(4, 1, true);
45 pub const CFG: crate::Point<Self, u16> = crate::Point::new(5, 1, true);
46 pub const TYP: crate::Point<Self, Typ> = crate::Point::new(6, 1, true);
47 pub const ADDR: crate::Point<Self, String> = crate::Point::new(7, 20, true);
48 pub const PORT: crate::Point<Self, u16> = crate::Point::new(27, 1, true);
49 pub const USER: crate::Point<Self, Option<String>> = crate::Point::new(28, 12, true);
50 pub const PW: crate::Point<Self, Option<String>> = crate::Point::new(40, 12, true);
51}
52impl crate::Group for Model14 {
53 const LEN: u16 = 52;
54}
55impl Model14 {
56 fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
57 let nested_data = data
58 .get(usize::from(<Self as crate::Group>::LEN)..)
59 .unwrap_or(&[]);
60 Ok((
61 nested_data,
62 Self {
63 nam: Self::NAM.from_data(data)?,
64 cap: Self::CAP.from_data(data)?,
65 cfg: Self::CFG.from_data(data)?,
66 typ: Self::TYP.from_data(data)?,
67 addr: Self::ADDR.from_data(data)?,
68 port: Self::PORT.from_data(data)?,
69 user: Self::USER.from_data(data)?,
70 pw: Self::PW.from_data(data)?,
71 },
72 ))
73 }
74}
75bitflags::bitflags! {
76 #[doc = " Capabilities"] #[doc = " "] #[doc =
77 " Bitmask value. Proxy configuration capabilities"] #[derive(Copy, Clone, Debug, Eq,
78 PartialEq)] #[cfg_attr(feature = "serde", derive(::serde::Serialize,
79 ::serde::Deserialize))] pub struct Cap : u16 { #[allow(missing_docs)] const NoProxy =
80 1; #[allow(missing_docs)] const Ipv4Proxy = 2; #[allow(missing_docs)] const Ipv6Proxy
81 = 4; }
82}
83impl crate::Value for Cap {
84 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
85 let value = u16::decode(data)?;
86 Ok(Self::from_bits_retain(value))
87 }
88 fn encode(self) -> Box<[u16]> {
89 self.bits().encode()
90 }
91}
92impl crate::FixedSize for Cap {
93 const SIZE: u16 = 1u16;
94 const INVALID: Self = Self::from_bits_retain(65535u16);
95 fn is_invalid(&self) -> bool {
96 self.bits() == 65535u16
97 }
98}
99bitflags::bitflags! {
100 #[doc = " Type"] #[doc = " "] #[doc = " Enumerate value. Proxy server type"]
101 #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
102 derive(::serde::Serialize, ::serde::Deserialize))] pub struct Typ : u16 {}
103}
104impl crate::Value for Typ {
105 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
106 let value = u16::decode(data)?;
107 Ok(Self::from_bits_retain(value))
108 }
109 fn encode(self) -> Box<[u16]> {
110 self.bits().encode()
111 }
112}
113impl crate::FixedSize for Typ {
114 const SIZE: u16 = 1u16;
115 const INVALID: Self = Self::from_bits_retain(65535u16);
116 fn is_invalid(&self) -> bool {
117 self.bits() == 65535u16
118 }
119}
120impl crate::Model for Model14 {
121 const ID: u16 = 14;
122 fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
123 models.m14
124 }
125 fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
126 let (_, model) = Self::parse_group(data)?;
127 Ok(model)
128 }
129}