ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
533 stars 82 forks source link

mpack_writer should not set flag to mpack_error_io when buffer to small #27

Closed xor-gate closed 8 years ago

xor-gate commented 8 years ago

I think current behaviour is a bit weird when a static buffer is not big enough and more is tried to be written and the context is destroyed. The error flag is expected to be mpack_error_too_big but it is stated in the documentation (and emitted) currently as mpack_error_io.

ludocode commented 8 years ago

Huh, you're right. I thought I had done this already but it turns out I was only handling this case differently in the reader, not the writer (and the reader flags mpack_reader_invalid without a fill function since the buffer should contain a whole MessagePack object.)

https://github.com/ludocode/mpack/blob/develop/src/mpack/mpack-reader.c#L167-L175 https://github.com/ludocode/mpack/blob/develop/src/mpack/mpack-writer.c#L249-L253

ludocode commented 8 years ago

As an aside, do you ever write messages into a buffer shorter than 9 bytes? I made a performance and code size change on develop which requires that the minimum buffer size is 9 bytes, even if you intend to write less data than that. Let me know if this is a problem; if so I'll put in a workaround.

xor-gate commented 8 years ago

Currently I do not write messages in buffers of 9 bytes or less. So this means mpack needs a minimal buffer size of 9 bytes, but less can be written ? I think this should be no problem, hence this should be well documented :-)

xor-gate commented 8 years ago

Thanks for fixing this!

ludocode commented 8 years ago

I'm removing the minimum buffer size; it's actually quite broken. So don't use develop right now until I have it fixed!

ludocode commented 8 years ago

It's fixed.