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

[MemoryPackIgnore] for field in unmanaged struct does not wok. #325

Open
vrecluse opened this issue Aug 20, 2024 · 1 comment
Open

[MemoryPackIgnore] for field in unmanaged struct does not wok. #325

vrecluse opened this issue Aug 20, 2024 · 1 comment

Comments

@vrecluse
Copy link

It seems unmanaged struct always serialize all data as-is.

[MemoryPackable]
public partial struct MyUnmanagedStruct
{
    [MemoryPackIgnore]
    public int Value1;
    public int Value2;
}

public class MyTest {
    [Fact]
    public void IgnoredField_ShouldNotBeSerialized()
    {
        // Arrange
        var data = new MyUnmanagedStruct() { Value1 = 1, Value2 = 2 };
        var bytes = MemoryPackSerializer.Serialize(data);
        
        // Act
        var deserialized = MemoryPackSerializer.Deserialize<MyUnmanagedStruct>(bytes);
        
        // Assert
        Assert.Equal(0, deserialized.Value1);     // failed here
        Assert.Equal(data.Value2, deserialized.Value2);
    }
}
@neuecc
Copy link
Member

neuecc commented Sep 10, 2024

Yes, unmanaged structs ignore all configurations.
It may be detected and changed to a compile error.

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