I'm not aware of any method that lets you go from a managed byte array to
struct. Marshal.PtrToStructure takes an unmanaged pointer and changes it to
struct. You could possibly try casting your byte[] as byte* (unsafe
required) and seeing if Marshal.PtrToStructure will handle it.
Other than that your stuck with something like this:
BinaryReader:
byte[] buffer = new byte[size];
s.Receive(buffer, size, 0);
MemoryStream bin = new MemoryStream(buffer);
BinaryReader din = new BinaryReader(bin);
/* Read each field using the reader's methods */
You could probably implement this generically using reflection. If you do,
post us a copy :)
Cole
> I have a huge byte array from another API that contains structs of differing
> sizes. I'd like to create n structs based on data in the byte array. But
[quoted text clipped - 5 lines]
>
> Amil