MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ByteArrayToStructure

Method ByteArrayToStructure

Source/Editor/Utilities/Utils.cs:481–488  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 3

LoadMethod · 0.80
LoadTrackMethod · 0.80
LoadTrackMethod · 0.80

Calls 3

MarshalToManagedMethod · 0.80
AllocMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected