@@ -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+
7090impl < ' 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-
198171impl < ' a , T : DatasContent < ' a > + Clone > DatasContent < ' a > for Cow < ' a , [ T ] >
199172where
200173 [ T ] : ToOwned ,
0 commit comments