Struct Serialization using Unsafe Field
There's a safe way to do that using System.Runtime.InteropServices.Marshal (link).
[StructLayout(LayoutKind.Sequential, Size = 8, Pack = 4)]
struct DataPacketStruct
{
    public byte Header { get; set; }
    public int Size { get; set; }

    public void Serialize(byte[] buffer, int startIndex)
    {
        int size = SizeOf();
        IntPtr ptr = Marshal.AllocHGlobal(size);
        Marshal.StructureToPtr(this, ptr, true);
        Marshal.Copy(ptr, buffer, startIndex, size);
        Marshal.FreeHGlobal(ptr);
    }

    public static DataPacketStruct Deserialize(byte[] buffer, int startIndex)
    {
        var result = new DataPacketStruct();
        int size = result.SizeOf();
        IntPtr ptr = Marshal.AllocHGlobal(size);
        Marshal.Copy(buffer, startIndex, ptr, size);
        result = (DataPacketStruct)Marshal.PtrToStructure(ptr, typeof(DataPacketStruct));
        Marshal.FreeHGlobal(ptr);
        return result;
    }

    public int SizeOf() =&gt; Marshal.SizeOf(this);
}

Also I used public properties and followed the Naming Guidelines in the example.
static void Main(string[] args)
{
    var data = new DataPacketStruct() { Header = byte.MaxValue, Size = int.MaxValue };
    byte[] a = new byte[8];
    data.Serialize(a, 0);
    Console.WriteLine(string.Join(&quot; &quot;, a.Select(x =&gt; x.ToString(&quot;X2&quot;))));
    var data2 = DataPacketStruct.Deserialize(a, 0);
    Console.WriteLine(JsonSerializer.Serialize(data2, new JsonSerializerOptions { WriteIndented = true }));
    Console.ReadKey();
}

Output:
FF 00 00 00 FF FF FF 7F
{
  &quot;Header&quot;: 255,
  &quot;Size&quot;: 2147483647
}