This commit is contained in:
rvcas 2022-05-22 12:56:28 -04:00
parent 33fee5b3e0
commit 52523516fe
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
3 changed files with 23 additions and 1 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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]);
}
}