Skip to content

Commit

Permalink
feat: add support for deserializing strings as byte arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
laptou committed Dec 12, 2024
1 parent 19c20be commit c8a634a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ciborium/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ where
return match self.decoder.pull()? {
Header::Tag(..) => continue,

Header::Bytes(Some(len)) if len <= self.scratch.len() => {
Header::Text(Some(len)) | Header::Bytes(Some(len)) if len <= self.scratch.len() => {
self.decoder.read_exact(&mut self.scratch[..len])?;
visitor.visit_bytes(&self.scratch[..len])
}
Expand Down Expand Up @@ -428,6 +428,19 @@ where
visitor.visit_byte_buf(buffer)
}

Header::Text(len) => {
let mut buffer = String::new();

let mut segments = self.decoder.text(len);
while let Some(mut segment) = segments.pull()? {
while let Some(chunk) = segment.pull(self.scratch)? {
buffer.push_str(chunk);
}
}

visitor.visit_byte_buf(buffer.into_bytes())
}

Header::Array(len) => self.recurse(|me| {
let access = Access(me, len);
visitor.visit_seq(access)
Expand Down

0 comments on commit c8a634a

Please sign in to comment.