deniszykov / msgpack-unity3d

MessagePack and JSON serializer for Unity3D
MIT License
102 stars 14 forks source link

Compatability with the MessagePack-CSharp library #27

Open 253153 opened 3 days ago

253153 commented 3 days ago

Hi Denis,

I am writing a Unity WebGL multiplayer game. My server is in .NET and is using the MessagePack-CSharp library. My client is in Unity (WebGL) and is using your msgpack-unity3d library.

The MessagePack-CSharp library has 2 ways to put keys into the messagepack objects:


[MessagePackObject]
public class MyClass
{
    [Key(0)]
    public int Age { get; set; }
}

OR


[MessagePackObject(keyAsPropertyName: true)]
public class MyClass
{
    public int Age { get; set; }
}

Which way should I do it so it works with your msgpack-unity3d library? Can it be done both ways? I cannot find it in the documentation. My message pack message class definition looks like this when using your library, I am not even using getters and setters (should I be?):

public class MyClass
{
    public int Age;
}

Thank you!

deniszykov commented 2 days ago

Hi, The first option:


[MessagePackObject]
public class MyClass
{
    [Key(0)]
    public int Age { get; set; }
}

which writes objects as tuples, is not supported.

The second one:


[MessagePackObject(keyAsPropertyName: true)]
public class MyClass
{
    public int Age { get; set; }
}

is supported and is the only option for object serialization. It should work with both properties and fields from my side.

deniszykov commented 2 days ago

My library uses the rules of Data Contract serialization from the older .NET serializers. These rules are described in the README file.

253153 commented 1 day ago

Thank you very much for your prompt response! Do we need getters and setters? If they are present in one end and not present in the other is it ok? Do they affect anything?

deniszykov commented 1 day ago

Do they affect anything?

In this library - no.

253153 commented 1 day ago

And no constructor required either? Or any [] tags or anything like this?

deniszykov commented 23 hours ago

Empty constructor is required. It is created by default if no constructors are defined on type.