示例#1
0
        public static RealtimeStatus Deserialize(byte[] bytes)
        {
            if (bytes == null || bytes.Length < statusSize)
            {
                return(null);
            }

            byte[] b1 = bytes.Take(statusSize).ToArray();
            RealtimeStatusWithoutSwitches status = BigEndianStructHelper <RealtimeStatusWithoutSwitches> .BytesToStruct(b1, MsgConsts.MsgEncoding);

            if (status.NoSwitch > 0 && status.NoSwitch * switchSize + switchSize <= bytes.Length)
            {
                SecuritySwitch[] switches = new SecuritySwitch[status.NoSwitch];


                for (int i = 0; i < status.NoSwitch; i++)
                {
                    int            offset = statusSize + switchSize * i;
                    byte[]         b2     = bytes.Skip(offset).Take(switchSize).ToArray();
                    SecuritySwitch s      = BigEndianStructHelper <SecuritySwitch> .BytesToStruct(b2, MsgConsts.MsgEncoding);

                    switches[i] = s;
                }
                RealtimeStatus rtn = new RealtimeStatus()
                {
                    Status   = status,
                    Switches = switches
                };
                return(rtn);
            }
            else
            {
                return(null);
            }
        }
        protected override QuotSnapExtInfo300611 deserialize(byte[] bytes)
        {
            if (bytes == null || bytes.Length < 4)
            {
                return(null);
            }
            QuotSnapExtInfo300611 rtn = new QuotSnapExtInfo300611();

            Array.Reverse(bytes, 0, 4);
            rtn.NoMDEntries = BitConverter.ToUInt32(bytes, 0);
            if (rtn.NoMDEntries > 0)
            {
                rtn.MDEntries = new MDEntry[rtn.NoMDEntries];
                int startIndex = 4;

                for (int entryIndex = 0; entryIndex < rtn.NoMDEntries; entryIndex++)
                {
                    if (bytes.Length - startIndex >= mdEntrySize)
                    {
                        var     mdEntryBytes = bytes.Skip(startIndex).Take(mdEntrySize).ToArray();
                        MDEntry mdEntry      = BigEndianStructHelper <MDEntry> .BytesToStruct(mdEntryBytes, MsgConsts.MsgEncoding);

                        startIndex += mdEntrySize;
                        rtn.MDEntries[entryIndex] = mdEntry;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(rtn);
        }
        protected override QuotSnapExtInfo300111 deserialize(byte[] bytes)
        {
            if (bytes == null || bytes.Length < 4)
            {
                return(null);
            }
            QuotSnapExtInfo300111 rtn = new QuotSnapExtInfo300111();

            Array.Reverse(bytes, 0, 4);
            rtn.NoMDEntries = BitConverter.ToUInt32(bytes, 0);
            if (rtn.NoMDEntries > 0)
            {
                rtn.MDEntries = new MDEntry[rtn.NoMDEntries];
                int startIndex = 4;

                for (int entryIndex = 0; entryIndex < rtn.NoMDEntries; entryIndex++)
                {
                    if (bytes.Length - startIndex >= mdEntrySize)
                    {
                        var     mdEntryBytes = bytes.Skip(startIndex).Take(mdEntrySize).ToArray();
                        MDEntry mdEntry      = new MDEntry();
                        mdEntry.Entry = BigEndianStructHelper <MDEntryWithoutOrders> .BytesToStruct(mdEntryBytes, MsgConsts.MsgEncoding);

                        startIndex += mdEntrySize;
                        if (mdEntry.Entry.NoOrders > 0)
                        {
                            if (bytes.Length - startIndex >= orderSize * mdEntry.Entry.NoOrders)
                            {
                                mdEntry.Orders = new Order[mdEntry.Entry.NoOrders];
                                for (int orderIndex = 0; orderIndex < mdEntry.Entry.NoOrders; orderIndex++)
                                {
                                    var   orderBytes = bytes.Skip(startIndex).Take(orderSize).ToArray();
                                    Order order      = BigEndianStructHelper <Order> .BytesToStruct(orderBytes, MsgConsts.MsgEncoding);

                                    mdEntry.Orders[orderIndex] = order;
                                    startIndex += orderSize;
                                }
                            }
                            else
                            {
                                return(null);
                            }
                        }

                        rtn.MDEntries[entryIndex] = mdEntry;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(rtn);
        }
        /// <summary>
        /// 接收登录应答
        /// </summary>
        /// <returns></returns>
        protected Logout?ReceiveLogoutAnswer()
        {
            var ans = ReceiveMessage();


            if (ans != null && ans.Header.Type == (UInt32)MsgType.Logout)
            {
                var logout = BigEndianStructHelper <Logout> .BytesToStruct(ans.BodyData, MsgConsts.MsgEncoding);

                this.logHelper.LogErrMsg("登出成功:{0}", logout.Text);
                return(null);
            }
            else
            {
                return(null);
            }
        }
        public static TQuotSnap Deserialize(byte[] bytes)
        {
            if (bytes == null || bytes.Length < commonInfoSize)
            {
                return(null);
            }
            else
            {
                //for (int i = 0; i < bytes.Length; i++)
                //{
                //    Debug .WriteLine("bytes[{0}] =\t{1}",i,bytes[i]);
                //}

                ObjectCreator <TQuotSnap> objCreator = ObjectCreator <TQuotSnap> .Instance;
                var       commonInfoBytes            = bytes.Take(commonInfoSize).ToArray();
                TQuotSnap rtn = objCreator.Create(Type.EmptyTypes);
                rtn.CommonInfo = BigEndianStructHelper <QuotSnapCommonInfo> .BytesToStruct(commonInfoBytes, MsgConsts.MsgEncoding);

                var extInfoBytes = bytes.Skip(commonInfoSize).ToArray();
                rtn.ExtInfo = QuotSnapExtInfoBase <TExtInfo> .Deserialize(extInfoBytes);

                return(rtn);
            }
        }
示例#6
0
 public MessagePack(byte[] headerBytes)
 {
     this.HeaderData = headerBytes;
     Header          = BigEndianStructHelper <StandardHeader> .BytesToStruct(headerBytes, MsgConsts.MsgEncoding);
 }
示例#7
0
 public static ChannelHeartbeat Deserialize(byte[] bytes)
 {
     return(BigEndianStructHelper <ChannelHeartbeat> .BytesToStruct(bytes, MsgConsts.MsgEncoding));
 }
示例#8
0
 public static Order300192 Deserialize(byte[] bytes)
 {
     return(BigEndianStructHelper <Order300192> .BytesToStruct(bytes, MsgConsts.MsgEncoding));
 }