Skip to content

Commit

Permalink
feat: deserialize bytes from Value Array
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Perlaki <[email protected]>
  • Loading branch information
lperlaki authored and rjzak committed Jul 5, 2024
1 parent 7a9dd8f commit bb03b26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ciborium/src/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl<'a, 'de> de::Deserializer<'de> for Deserializer<&'a Value> {

match value {
Value::Bytes(x) => visitor.visit_bytes(x),
Value::Array(x) => visitor.visit_seq(Deserializer(x.iter())),
_ => Err(de::Error::invalid_type(value.into(), &"bytes")),
}
}
Expand Down Expand Up @@ -641,3 +642,18 @@ impl Value {
T::deserialize(Deserializer(self))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn deserialize_bytes_from_array() {
let value = Value::serialized(&[1, 2, 3, 4]).unwrap();
assert!(value.is_array());

let bytes = value.deserialized::<serde_bytes::ByteArray<4>>().unwrap();

assert_eq!(bytes, &[1, 2, 3, 4]);
}
}

0 comments on commit bb03b26

Please sign in to comment.