<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>6f1ded55-bde3-41f6-8ef0-5c172345de41</UserSecretsId>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0-rc.1.21451.13" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.2" />
</ItemGroup>
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
</ItemGroup>
</Project>
Регистрируй свое приложение
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="http_proxy" value="http://proxy:1111" />
<add key="http_proxy.user" value="user" />
<add key="http_proxy.password" value="AQAAANC==password" />
<add key="https_proxy" value="https://proxy:1111" />
<add key="https_proxy.user" value="user" />
<add key="https_proxy.password" value="password" />
</config>
</configuration>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public class TestClass {
[MarshalAs(UnmanagedType.I4)]
public Int32 _int32;
[MarshalAs(UnmanagedType.U4)]
public UInt32 _uint32;
[MarshalAs(UnmanagedType.I8)]
public Int64 _int64;
[MarshalAs(UnmanagedType.U8)]
public UInt64 _uint64;
public void func_testMarshal(Random rnd){
for(int i=0; i<10000000; i++){
TestClass test = new TestClass(){
_int32 = rnd.Next(1, 65535),
_int64 = rnd.Next(1, 65535),
_uint32 = (uint)rnd.Next(1, 65535),
_uint64 = (ulong)rnd.Next(1, 65535)
};
byte[] b = MarshalUtils.StructureToByteArray(test);
// имитация бурной деятельности
b[0] = 1;
}
}
public static byte[] StructureToByteArray(object data){
var size = Marshal.SizeOf(data);
var bytes = new byte[size];
var ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(data, ptr, false);
Marshal.Copy(ptr, bytes, 0, size);
Marshal.FreeHGlobal(ptr);
return bytes;
}
for(int i=0; i<10000000; i++){
TestClass test = new TestClass(){
_int32 = rnd.Next(1, 65535),
_int64 = rnd.Next(1, 65535),
_uint32 = (uint)rnd.Next(1, 65535),
_uint64 = (ulong)rnd.Next(1, 65535)
};
byte[] b = test.Export1();
b[0] = 1;
}
public byte[] Export1(){
byte[] b = new byte[192];
byte[] b_int32 = BitConverter.GetBytes(_int32);
byte[] b_int64 = BitConverter.GetBytes(_int64);
byte[] b_uint32 = BitConverter.GetBytes(_uint32);
byte[] b_uint64 = BitConverter.GetBytes(_uint64);
Buffer.BlockCopy(b_int32, 0, b, 0, b_int32.Length);
Buffer.BlockCopy(b_int64, 0, b, b_int32.Length, b_int32.Length);
Buffer.BlockCopy(b_uint32, 0, b, b_int32.Length + b_int32.Length, b_uint32.Length);
Buffer.BlockCopy(b_uint64, 0, b, b_int32.Length + b_int32.Length + b_uint32.Length, b_uint64.Length);
return b;
}