msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

Way to determine that stream (Byte[]) does not contain completed data for unpacking?

Open OniversalTyrant opened this issue 10 years ago • 1 comments

As expected, I do get an exception when I try to unpack Stream (which is spitting out data - Byte[] in chunks) which does not contain complete packed message.

I handle this by try{}..catch{} and store incomplete packed message. When I get new Byte[] data I append to my previous incomplete packed message and unpack the message. Works great but it has an overhead on performance i.e. time is wasted in handling the exception.

Would it be possible to let me know if I could determine from IMessagePackSingleObjectSerializer object whether data I am trying to unpack is complete or not? or Could you suggest any other way to determine?

OniversalTyrant avatar Oct 28 '15 14:10 OniversalTyrant

Umm, it is hard, but there is a solution which might help you. You can utilize MessagePackObject.IsList, IsDictionary, AsList(), AsDictionary(), and Count to detecte incomplete stream. If you use Array method serializer (it is default), root object's IsList should be true and AsList() should succeed, and then call Count of the list and compare it to member count. If the last member is complex type, check members count recursively. Note that array items order is lexical order unless you explicitly specify order with [MessagePackMember] or [DataMember].

yfakariya avatar Nov 06 '15 17:11 yfakariya