public static MessageHead FromBytes(byte[] buf) { MessageHead head = new MessageHead(); int size = Marshal.SizeOf(head); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(buf, 0, ptr, 4); head = (MessageHead)Marshal.PtrToStructure(ptr, head.GetType()); Marshal.FreeHGlobal(ptr); return head; }
public static MessageHead FromBytes(byte[] buf) { MessageHead head = new MessageHead(); int size = Marshal.SizeOf(head); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(buf, 0, ptr, 4); head = (MessageHead)Marshal.PtrToStructure(ptr, head.GetType()); Marshal.FreeHGlobal(ptr); return(head); }
public static byte[] ToByteArray(MessageHead req) { int size = Marshal.SizeOf(req); byte[] buf = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(req, ptr, true); Marshal.Copy(ptr, buf, 0, buf.Length); Marshal.FreeHGlobal(ptr); return(buf); }
public static byte[] ToByteArray(MessageHead req) { int size = Marshal.SizeOf(req); byte[] buf = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(req, ptr, true); Marshal.Copy(ptr, buf, 0, buf.Length); Marshal.FreeHGlobal(ptr); return buf; }