private static byte[] ReadBytesFromPtr(IntPtr intPtr, int bufferLength)
{
var result = new byte[bufferLength];
var count = bufferLength;
for (var i = ; i < bufferLength; i++)
{
result[i] = Marshal.ReadByte(intPtr, i);
if (result[i] == )
{
count = i;
break;
}
}
return result.Take(count).ToArray();
}
private static void WriteBytesToPtr(IntPtr intPtr, byte[] bytes)
{
int j;
for (j = ; j < bytes.Length; j++)
{
Marshal.WriteByte(intPtr, j, bytes[j]);
}
Marshal.WriteByte(intPtr, j, );
}