Converts the raw bytes into the structure. Supported only for structures with simple types and no GC objects. The structure type. The data bytes. The structure.
(byte[] bytes)
| 479 | /// <param name="bytes">The data bytes.</param> |
| 480 | /// <returns>The structure.</returns> |
| 481 | public static T ByteArrayToStructure<T>(byte[] bytes) where T : struct |
| 482 | { |
| 483 | // #stupid c# |
| 484 | GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); |
| 485 | T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); |
| 486 | handle.Free(); |
| 487 | return stuff; |
| 488 | } |
| 489 | |
| 490 | /// <summary> |
| 491 | /// Converts the raw bytes into the structure. Supported only for structures with simple types and no GC objects. |