Skip to content

Commit

Permalink
deserialize_bytes: accept arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Sep 13, 2024
1 parent 4f465fa commit b4dec88
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,23 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
where
V: Visitor<'de>,
{
// major type 2: "byte string"
let length = self.raw_deserialize_u32(MAJOR_BYTES)? as usize;
let bytes: &'de [u8] = self.try_take_n(length)?;
visitor.visit_borrowed_bytes(bytes)
let major = self.peek_major()?;
match major {
MAJOR_ARRAY => {
let len = self.raw_deserialize_u32(MAJOR_ARRAY)?;
visitor.visit_seq(SeqAccess {
deserializer: self,
len: len as usize,
})
}
MAJOR_BYTES => {
// major type 2: "byte string"
let length = self.raw_deserialize_u32(MAJOR_BYTES)? as usize;
let bytes: &'de [u8] = self.try_take_n(length)?;
visitor.visit_borrowed_bytes(bytes)
}
_ => Err(Error::DeserializeBadMajor),
}
}

fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>
Expand Down

0 comments on commit b4dec88

Please sign in to comment.