static T ByteArrayToStructure<T>(byte[] bytes, int offset) where T : struct
{
var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
try
{
return Marshal.PtrToStructure<T>(IntPtr.Add(handle.AddrOfPinnedObject(), offset));
}
finally
{
handle.Free();
}
}