Skip to content

Commit 766f3fd

Browse files
committed
fix: endianness issue
1 parent 5f1619d commit 766f3fd

File tree

7 files changed

+44
-77
lines changed

7 files changed

+44
-77
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "Intouch2-MQTT"
22
description: "A bridge between intouch2, used in spa systems, and MQTT 3.3"
3-
version: "0.1.259"
3+
version: "0.1.260"
44
slug: "intouch2-mqtt"
55
init: false
66
arch:

intouch2-mqtt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "intouch2-mqtt"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

intouch2/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "intouch2"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

intouch2/src/object.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ impl ToStatic for StatusChange<'_> {
2626
}
2727
}
2828

29-
impl ToStatic for ReminderInfo {
30-
type Static = ReminderInfo;
31-
32-
fn to_static(&self) -> Self::Static {
33-
self.clone()
34-
}
35-
}
36-
3729
#[derive(
3830
Clone,
3931
Copy,
@@ -59,12 +51,14 @@ pub enum ReminderIndex {
5951

6052
pub type ReminderData = i16;
6153

62-
#[derive(Debug, Clone, PartialEq, Eq)]
63-
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
64-
pub struct ReminderInfo {
65-
pub index: ReminderIndex,
66-
pub data: ReminderData,
67-
pub valid: bool,
54+
crate::gen_packages! {
55+
#[derive(Debug, Clone, PartialEq, Eq)]
56+
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
57+
pub struct ReminderInfo {
58+
pub index: ReminderIndex,
59+
pub data: ReminderData,
60+
pub valid: bool,
61+
}
6862
}
6963

7064
crate::gen_packages! {
@@ -133,6 +127,10 @@ impl ActualType for WatercareInfo {
133127
}
134128

135129
macro_rules! simple_type {
130+
($ty:ty: Transmute $(,$($rest:tt)*)?) => {
131+
impl TransmutedArray for $ty {}
132+
simple_type!{ $ty $(,$($rest)*)? }
133+
};
136134
($ty:ty $(,$($rest:tt)*)?) => {
137135
impl ActualType for $ty {
138136
type Type = $ty;
@@ -143,20 +141,19 @@ macro_rules! simple_type {
143141
*self
144142
}
145143
}
146-
impl TransmutedArray for $ty {}
147144
simple_type!{ $($($rest)*)? }
148145
};
149146
() => {};
150147
}
151148
simple_type!(
152-
u8,
149+
u8: Transmute,
153150
u16,
154151
i16,
155-
bool,
156-
WatercareType,
157-
Weekday,
158-
Time,
159-
ReminderIndex
152+
bool: Transmute,
153+
WatercareType: Transmute,
154+
Weekday: Transmute,
155+
Time: Transmute,
156+
ReminderIndex: Transmute
160157
);
161158

162159
pub mod package_data {

intouch2/src/object_macro.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,6 @@ macro_rules! gen_packages {
358358
};
359359
($(#[$meta:meta])* pub struct $parse:ident { $($rest:tt)* }) => {
360360
$(#[$meta])* pub struct $parse { $($rest)* }
361-
mod fuck_you {
362-
use super::*;
363-
$crate::gen_packages!{ BUILD_STRUCT_IMPLS $parse b"" [] [] [] {[] [] $($rest)*} => $($rest)*}
364-
}
361+
$crate::gen_packages!{ BUILD_STRUCT_IMPLS $parse b"" [] [] [] {[] [] $($rest)*} => $($rest)*}
365362
};
366363
}

intouch2/src/parser.rs

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ fn parse_addressed_package<'a>(input: &'a [u8]) -> IResult<&'a [u8], NetworkPack
6767
))
6868
}
6969

70+
impl<'a> DatasContent<'a> for u16 {
71+
fn parse(input: &'a [u8]) -> nom::IResult<&'a [u8], Self> {
72+
nom::number::complete::be_u16(input)
73+
}
74+
75+
fn compose(&self) -> Cow<'a, [u8]> {
76+
Cow::Owned(self.to_be_bytes().into())
77+
}
78+
}
79+
80+
impl<'a> DatasContent<'a> for i16 {
81+
fn parse(input: &'a [u8]) -> nom::IResult<&'a [u8], Self> {
82+
nom::number::complete::be_i16(input)
83+
}
84+
85+
fn compose(&self) -> Cow<'a, [u8]> {
86+
Cow::Owned(self.to_be_bytes().into())
87+
}
88+
}
89+
7090
impl<'a, T1: DatasContent<'a>, T2: DatasContent<'a>> DatasContent<'a> for (T1, T2) {
7191
fn parse(input: &'a [u8]) -> nom::IResult<&'a [u8], Self> {
7292
let (input, t1) = T1::parse(input)?;
@@ -148,53 +168,6 @@ impl<'a> DatasContent<'a> for StatusChange<'a> {
148168
}
149169
}
150170

151-
impl<'a> DatasContent<'a> for ReminderInfo {
152-
fn parse(input: &'a [u8]) -> nom::IResult<&'a [u8], Self> {
153-
let (new_input, index) = u8::parse(input)?;
154-
let (input, index) = (
155-
new_input,
156-
ReminderIndex::from_repr(index).ok_or_else(|| {
157-
nom::Err::Failure(nom::error::make_error(
158-
new_input,
159-
nom::error::ErrorKind::OneOf,
160-
))
161-
})?,
162-
);
163-
164-
let Some((data, input)) = input.split_first_chunk::<2>() else {
165-
return Err(nom::Err::Failure(nom::error::make_error(
166-
input,
167-
nom::error::ErrorKind::Eof,
168-
)));
169-
};
170-
let data = i16::from_le_bytes(*data);
171-
let before_valid = input;
172-
let (input, valid) = <u8 as DatasContent>::parse(input)?;
173-
let valid = match valid {
174-
0 => false,
175-
1 => true,
176-
_ => {
177-
return Err(nom::Err::Failure(nom::error::make_error(
178-
before_valid,
179-
nom::error::ErrorKind::OneOf,
180-
)))?
181-
}
182-
};
183-
Ok((input, Self { index, data, valid }))
184-
}
185-
186-
fn compose(&self) -> Cow<'a, [u8]> {
187-
Cow::Owned(
188-
[
189-
&[self.index as u8],
190-
self.data.to_le_bytes().as_ref(),
191-
if self.valid { b"\x01" } else { b"\x00" },
192-
][..]
193-
.concat(),
194-
)
195-
}
196-
}
197-
198171
impl<'a, T: DatasContent<'a> + Clone> DatasContent<'a> for Cow<'a, [T]>
199172
where
200173
[T]: ToOwned,

0 commit comments

Comments
 (0)