Skip to content

Commit

Permalink
fix textraw and Any support
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Apr 7, 2024
1 parent 37917ad commit d81d791
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<R: Read> Deserializer<R> {

fn read_string(&mut self, header: Header) -> Result<String> {
match header.element_type {
ElementType::Text => {
ElementType::Text | ElementType::TextRaw => {
Ok(String::from_utf8(self.read_payload(header)?)?)
}
ElementType::TextJ => self.read_json_compatible_string(header),
Expand Down Expand Up @@ -311,7 +311,18 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
}
}
ElementType::Array => visitor.visit_seq(self),
e => todo!("deserialize any for {:?}", e),
ElementType::Object => visitor.visit_map(self),
ElementType::Text
| ElementType::TextJ
| ElementType::Text5
| ElementType::TextRaw => {
visitor.visit_string(self.read_string(header)?)
}
ElementType::Reserved13
| ElementType::Reserved14
| ElementType::Reserved15 => {
Err(Error::UnexpectedType(header.element_type))
}
}
}

Expand Down Expand Up @@ -556,18 +567,18 @@ impl<'de, 'a, R: Read> de::Deserializer<'de> for &'a mut Deserializer<R> {
visitor.visit_string(self.read_string(header)?)
}

fn deserialize_bytes<V>(self, _visitor: V) -> Result<V::Value>
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
{
todo!()
self.deserialize_seq(visitor)
}

fn deserialize_byte_buf<V>(self, _visitor: V) -> Result<V::Value>
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value>
where
V: Visitor<'de>,
{
todo!()
self.deserialize_seq(visitor)
}
}

Expand Down Expand Up @@ -769,10 +780,10 @@ mod tests {
use std::collections::HashMap;
let actual =
from_bytes::<HashMap<String, bool>>(b"\x6c\x17a\x02\x17b\x01")
.unwrap()
.into_iter()
.collect::<Vec<_>>();
let expected = [("a".into(), false), ("b".into(), true)];
.unwrap();
let expected = [("a".into(), false), ("b".into(), true)]
.into_iter()
.collect();
assert_eq!(actual, expected);
}

Expand Down

0 comments on commit d81d791

Please sign in to comment.