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
Decoder iterator returns next() when can't decode full object #6
Comments
It returns none if there's no more data to decode IIRC. It returns an error if there was a problem decoding. I'm not sure what specifically is going wrong in your case because I don't see enough details to be able to reproduce your problem. Could you please provide a minimal code sample that I can run that demonstrates your problem? Thanks. |
Okay, the problem is two-fold. Here is the code: use std::io::Write;
extern crate bytes;
extern crate cbor;
extern crate rustc_serialize;
use cbor::{Encoder, Decoder};
#[derive(RustcDecodable, RustcEncodable, Debug)]
struct Test {
value: String,
}
fn main() {
let mut buf = bytes::ByteBuf::mut_with_capacity(16);
{
let mut enc = Encoder::from_writer(&mut buf);
enc.encode(&[Test {
value: "hello world hello world hello world".to_string()
}]).unwrap();
}
println!("RESULT len: {}, contents: {:?}", buf.bytes().len(), buf.bytes());
let mut reader = buf.flip();
let mut dec = Decoder::from_reader(&mut reader);
println!("Decoded: {:?}", dec.decode::<Test>().next());
} For small buffer size it returns:
When I change
(If you wonder if |
Nice find! I've fixed this and uploaded a new release of CBOR to crates.io ( |
Great! Thanks for quick response. Still in this example encoding silently truncates value. Should I file a separate issue for this? |
The example where you set the capacity to If you replace your buffer with |
No, the buffer is intentionally not growable. But when I try to
Which I expect to be propagated by encoder. |
I use the following code to unpack a packet from network:
And
next()
returnsNone
when packet was truncated by some reason. Is it works as intended? I would like to have some more explicit error.I use cbor 0.3.14 if that matters.
Is there a better interface? Should this behavior be documented?
The text was updated successfully, but these errors were encountered: