-
Notifications
You must be signed in to change notification settings - Fork 153
Closed
Description
Hi,
I want to deserialize stream of MessagePack structures with zero-copy.
But when I create ReadRefReader with:
let contents = std::fs::read(&path).unwrap();
let mut deserializer = Deserializer::from_read_ref(&contents);... and then deserialize a first struct:
let msg = Message::deserialize(&mut deserializer)?;I have no way of knowing where did the deserializer end.
However, if I would add this into the impl<'de, R> Deserializer<ReadRefReader<'de, R>>:
pub fn get_buf(&self) -> &'de [u8] {
self.rd.buf
}... and used it like this:
let mut buf = &contents[..];
let mut result = Vec::new();
loop {
let mut deserializer = Deserializer::from_read_ref(&buf[..]);
if let Ok(event) = Message::deserialize(&mut deserializer) {
result.push(event);
}
else {
break;
}
buf = deserializer.get_buf();
}It would work.
So the question is - am I missing something? Is there a way how to deserialize streaming MessagePack structs from buffer reference? If not - would it be possible to add the get_buf() method? And if not... could you think of a better way how to implement this?
Metadata
Metadata
Assignees
Labels
No labels