Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for deserializing strings as byte arrays #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading