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

Problem with unpack array packed with python server

Open HAkbariMoghadam opened this issue 10 years ago • 3 comments

hi I pack object like {"name":"test","sessions":["xxxxx","yyyyy"]} with message pack in python but when i unpack this object to object with your client get an object like {"name":"test","sessions":2} (it's give me number of item in array) i test with both unpack method and unpacksingleobject method but result is same can you help me please?

HAkbariMoghadam avatar Dec 01 '15 14:12 HAkbariMoghadam

Hi, do you say that you used Unpacker directly instead of MessagePackSerializer? If so, it is by design. An Unpacker returns a count of collection at first, then returns items in order. However, UnpackSingleObject should returns with unpacked nested arrays/maps, so it looks a bug. I recommend you to use MessagePackSerializer if you can use it.

yfakariya avatar Dec 01 '15 23:12 yfakariya

Hi Thanks for Reply i use code like this

private T DecodeData<T>(byte[] data) where T : class { var serializer = SerializationContext.Default.GetSerializer<T>(); Stream stream = new MemoryStream(data); var result = serializer.Unpack(stream); return result; }

Should i use MessagePackSerializer instead of SerializationContext.Default.GetSerializer<T>(); ?

HAkbariMoghadam avatar Dec 05 '15 05:12 HAkbariMoghadam

Thank you for reply. In your code, var serializer should be MessagePackSerializer<T>. So, could you also show me additional information? Specifically, the actual T when you face the problem, and the desereializing binary (in hex string, such as result of BitConverter.ToString).

yfakariya avatar Dec 05 '15 16:12 yfakariya