Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization results differ between Unity and .Net with using LayoutKind.Auto #191

Closed
AwaharaFujihiro opened this issue Oct 25, 2023 · 1 comment

Comments

@AwaharaFujihiro
Copy link

[MemoryPackable]
[StructLayout(LayoutKind.Auto)]
public partial struct StructAB
{
    public int A;
    public int B;
}

[MemoryPackable]
[StructLayout(LayoutKind.Auto)]
public partial struct StructABC
{
    public StructAB AB;
    public int C;
}

public static class MemoryPackTest
{
    public static void Test()
    {
        var abc = new StructABC { AB = new StructAB { A = 1, B = 2 }, C = 3 };
        var bytes = MemoryPackSerializer.Serialize(abc);
#if UNITY_EDITOR
        UnityEngine.Debug.Log(string.Join("", bytes.Select(b => $"{b:X2}")));
#else
        Console.WriteLine(string.Join("", bytes.Select(b => $"{b:X2}")));
#endif
    }
}

.Net (7.0)

03000000000000000100000002000000

Unity (2022.3.10f)

010000000200000003000000
@neuecc
Copy link
Member

neuecc commented Oct 25, 2023

already discussed in here. #107
Auto behavior has undergone a breaking change in .NET 7.
You should make it Sequential whenever possible or be aware of the changes and control Auto.

NOTE: MagicOnion plans to include special measures.

@neuecc neuecc closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants