Skip to content

Commit fdf0baa

Browse files
implemented decode for u8
1 parent 15fa1ff commit fdf0baa

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

amqp-type/src/fixed_width/ubyte.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::error::AppError;
12
use crate::serde::encode::{Encode, Encoded};
23
use crate::serde::decode::Decode;
34

@@ -17,10 +18,16 @@ impl Decode for u8 {
1718
}
1819
}
1920

20-
fn try_decode(data: impl Iterator<Item = u8>) -> Result<Self, crate::error::AppError>
21+
fn try_decode(mut iter: impl Iterator<Item = u8>) -> Result<Self, crate::error::AppError>
2122
where
2223
Self: Sized {
23-
todo!()
24+
let con = iter.next();
25+
let val = iter.next();
26+
match (con, val) {
27+
(Some(0x50), Some(x)) => Ok(x),
28+
(Some(_), _) => Err(AppError::DeserializationError("ubyte (u8)".to_string(), "Wrong constructor".to_string())),
29+
(_, _) => Err(AppError::DeserializationError("ubyte (u8)".to_string(), "Iterator was empty".to_string()))
30+
}
2431
}
2532

2633
}

amqp-type/src/serde/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::error::AppError;
55
pub struct Constructor(u8);
66

77
pub trait Decode {
8-
fn can_decode(data: impl Iterator<Item = u8>) -> bool;
9-
fn try_decode(data: impl Iterator<Item = u8>) -> Result<Self, AppError>
8+
fn can_decode(iter: impl Iterator<Item = u8>) -> bool;
9+
fn try_decode(iter: impl Iterator<Item = u8>) -> Result<Self, AppError>
1010
where
1111
Self: Sized;
1212
}

0 commit comments

Comments
 (0)