示例#1
0
            public override void Deserialize(ref byte[] data)
            {
                int headSize = HEADER.HeaderSize();
                int bodySize = data.Length - headSize;

                byte[] headBuf = new byte[headSize];
                Array.Copy(data, 0, headBuf, 0, headSize);
                HEADER head = new HEADER();

                head.Deserialize(ref headBuf);

                msgID   = head.msgID;
                msgSize = head.msgSize;
                msgSOF  = head.msgSOF;
                msgType = head.msgType;
                msgErr  = head.msgErr;
                msgUser = head.msgUser;
                msgTime = head.msgTime;
                ext1    = head.ext1;
                ext2    = head.ext2;

                byte[] bodyBuf = new byte[bodySize];
                Array.Copy(data, headSize, bodyBuf, 0, bodySize);
                BinaryFormatter bf = new BinaryFormatter();

                using (MemoryStream ms = new MemoryStream(bodyBuf))
                {
                    workHistory = (WorkHistory[])bf.Deserialize(ms);
                }
            }
示例#2
0
            public new void Deserialize(ref byte[] data)
            {
                msgSOF  = BitConverter.ToInt32(data, 0);
                msgID   = BitConverter.ToInt32(data, 4);
                msgSize = BitConverter.ToInt32(data, 8);
                msgType = BitConverter.ToInt32(data, 12);
                msgErr  = BitConverter.ToInt32(data, 16);

                msgUser = Encoding.ASCII.GetString(data, 20, 50).TrimEnd('\0');
                msgTime = Encoding.ASCII.GetString(data, 70, 50).TrimEnd('\0');
                ext1    = Encoding.ASCII.GetString(data, 120, 50).TrimEnd('\0');
                ext2    = Encoding.ASCII.GetString(data, 170, 50).TrimEnd('\0');

                int headLen = HEADER.HeaderSize();

                msgCount = BitConverter.ToInt32(data, headLen);
                msgs     = new ChatMsg[msgCount];
                for (int i = 0; i < msgCount; ++i)
                {
                    int    msgSize = Marshal.SizeOf(typeof(ChatMsg));
                    byte[] dest    = new byte[msgSize];
                    int    off     = headLen + 4 + (i * msgSize);
                    Array.Copy(data, off, dest, 0, msgSize);

                    msgs[i] = new ChatMsg();
                    var gch = GCHandle.Alloc(dest, GCHandleType.Pinned);
                    Marshal.PtrToStructure(gch.AddrOfPinnedObject(), msgs[i]);
                    gch.Free();
                }
            }