deniszykov / msgpack-unity3d

MessagePack and JSON serializer for Unity3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'Unexpected token readed 'EndOfStream' while 'BeginObject' is expected.' ?

Orhonbey opened this issue · comments

Hi
I am use your library first time
but I get this error.
Can you help me ?
Thank you.
'Unexpected token readed 'EndOfStream' while 'BeginObject' is expected.'
image

private T ByteConverter<T>(byte[] value) { var stream = new MemoryStream(); stream.Write(value, 0, value.Length); T result = (T)MsgPack.Deserialize(typeof(T), stream); return result; }

Hi @sunal. You need to rewind back stream after Write().

stream.Position = 0;

and better to use special non-copying constructor of MemoryStream:

var stream = new MemoryStream(value, 0, value.Length, writable: false);
// no rewind required

Thank you .
I tried . But this error back.
image

Does T and all deserialized types has parameter-less constructor defined?
Example:

class MyClass
{
    public MyClass() { /* this is parameter-less constructor */ }
}

This is required for deserialization. Because deserializer need to create instances of your types.

Thank you my problem solved .