feat: u8
This commit is contained in:
parent
33fee5b3e0
commit
52523516fe
|
@ -12,6 +12,14 @@ impl Encode for bool {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for u8 {
|
||||
fn encode(&self, e: &mut Encoder) -> Result<(), String> {
|
||||
e.u8(*self)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, K> Encode for (T, K)
|
||||
where
|
||||
T: Encode,
|
||||
|
|
|
@ -30,9 +30,16 @@ impl Encoder {
|
|||
}
|
||||
|
||||
pub fn u8(&mut self, x: u8) -> Result<&mut Self, String> {
|
||||
if self.used_bits == 0 {
|
||||
self.current_byte = x;
|
||||
self.next_word();
|
||||
} else {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Encode a `bool` value.
|
||||
pub fn bool(&mut self, x: bool) -> &mut Self {
|
||||
if x {
|
||||
|
|
|
@ -30,4 +30,11 @@ mod test {
|
|||
|
||||
assert_eq!(bytes, vec![0b00000001]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn encode_u8() {
|
||||
let bytes = super::encode(3_u8).unwrap();
|
||||
|
||||
assert_eq!(bytes, vec![0b00000011, 0b00000001]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue