コード例 #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);
            }
        }
コード例 #2
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;
            }
        }