Exemple #1
0
        public bool Read(CtpObject[] row)
        {
            if (row.Length != m_response.Columns.Count)
            {
                throw new ArgumentException("The number of elements in array does not match the number of columns in the response", nameof(row));
            }

            if (m_stream.IsEmpty)
            {
                //It's possible that this is not enough since items might eventually be stored with a few bits, so I need some kind of extra escape sequence.
                return(false);
            }

            for (int x = 0; x < row.Length; x++)
            {
                row[x] = m_stream.Read();
            }

            return(true);
        }
        private void Test(List <CtpObject> data)
        {
            var wr = new CtpObjectWriter();

            for (var x = 0; x < data.Count; x++)
            {
                var o = data[x];
                wr.Write(o);
            }

            var rd = new CtpObjectReader(wr.ToArray());

            for (var x = 0; x < data.Count; x++)
            {
                var o  = data[x];
                var oo = rd.Read();
                if (!o.Equals(oo))
                {
                    throw new Exception($"Not Equal {o} {oo} on record {x}");
                }
            }
        }
        public override bool Read(SttpDataPoint dataPoint)
        {
TryAgain:
            if (m_stream.IsEmpty)
            {
                return(false);
            }

            m_lastChannelID++;
            CtpObject value = m_stream.Read();

            if (value.ValueTypeCode == CtpTypeCode.Integer)
            {
                long code = value.IsInteger;
                if (0 <= code && code <= 15)
                {
                    bool channelIDChanged = (code & 1) != 0;
                    bool hasMetadata      = (code & 2) != 0;
                    bool qualityChanged   = (code & 4) != 0;
                    bool timeChanged      = (code & 8) != 0;

                    if (channelIDChanged)
                    {
                        m_lastChannelID = m_stream.Read().AsInt32;
                    }

                    if (hasMetadata)
                    {
                        Assign(new SttpDataPointID(m_stream.Read()), m_lastChannelID);
                    }

                    if (qualityChanged)
                    {
                        m_lastQuality = m_stream.Read().AsInt64;
                    }

                    if (timeChanged)
                    {
                        m_lastTimestamp = m_stream.Read().AsCtpTime;
                    }

                    value = m_stream.Read();
                }
                else
                {
                    value = code - 16;
                }
            }

            dataPoint.DataPoint = GetMetadata(m_lastChannelID);
            dataPoint.Quality   = m_lastQuality;
            dataPoint.Time      = m_lastTimestamp;
            dataPoint.Value     = value;

            if (dataPoint.DataPoint == null)
            {
                goto TryAgain;
            }

            return(true);
        }