3Hren / 3Hren/msgpack-rust

Iterator support for serde deserialization

Open
#116 3 comments 0 reactions 0 assignees View on GitHub
C: decode C: highlevel P: normal T: enhancement
Dominant language
Rust
Stars
1.4k
Forks
162
PR merge metrics
No merged PRs in 30d

Description

I have a file that is a sequence of serialized structs and I want to read them, one by one. I believe this is quite common situation. This is currently a bit hard, I have the following code:

```rust
while let Ok(record) = from_read::<_, Record>(&mut reader) {
// Do stuff with record here
}
// Check that the above loop ended (errored) on eof, not something else
let mut ctl_buf = [0];
assert_eq!(0, reader.read(&mut ctl_buf).unwrap());
```

This checks first tries to repeatedly read a value from the reader until it fails and then checks that it reached the end of the file, not some other error. This, however, might also mean an EOF *in the middle* of the record, not only on the boundary (eg. if there's no more record).

There could be two ways to allow handling the situation in a better way:
* Have an error type that can distinguish the situations (eg. an EOF before we read any data, an EOF in the middle of the record…).
* Have an iterator reader, similar to `serde-json` has in [`StreamDeserializer`](https://docs.rs/serde_json/0.9.9/serde_json/de/struct.StreamDeserializer.html).

Would it be hard to add either of these?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.