Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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;
 }