Exemplo n.º 1
0
        public unsafe override void Decode(BinaryStreamBase stream, HistorianKey prevKey, HistorianValue prevValue, HistorianKey key, HistorianValue value, out bool isEndOfStream)
        {
            isEndOfStream = false;
            uint code = stream.ReadUInt8();
            byte b1;
            byte b2;
            byte b3;

            //Compression Stages:
            //  Stage 1: Big Positive Float.
            //  Stage 2: Big Negative Float.
            //  Stage 3: Zero
            //  Stage 4: 32 bit
            //  Stage 5: Catch all

            if (code < 0x80)
            {
                b1 = stream.ReadUInt8();
                b2 = stream.ReadUInt8();
                b3 = stream.ReadUInt8();

                //If stage 1 (50% success)
                key.Timestamp   = prevKey.Timestamp;
                key.PointID     = prevKey.PointID + 1 + ((code >> 4) & 0x7);
                key.EntryNumber = 0;
                value.Value1    = (4u << 28) | (code & 0xF) << 24 | (uint)b1 << 16 | (uint)b2 << 8 | (uint)b3 << 0;
                value.Value2    = 0;
                value.Value3    = 0;
                return;
            }
            if (code < 0xC0)
            {
                b1 = stream.ReadUInt8();
                b2 = stream.ReadUInt8();
                b3 = stream.ReadUInt8();

                //If stage 2 (16% success)
                key.Timestamp   = prevKey.Timestamp;
                key.PointID     = prevKey.PointID + 1 + ((code >> 4) & 0x3);
                key.EntryNumber = 0;
                value.Value1    = (12u << 28) | (code & 0xF) << 24 | (uint)b1 << 16 | (uint)b2 << 8 | (uint)b3 << 0;
                value.Value2    = 0;
                value.Value3    = 0;
                return;
            }
            if (code < 0xD0)
            {
                //If stage 3 (28% success)
                key.Timestamp   = prevKey.Timestamp;
                key.PointID     = prevKey.PointID + 1 + (code & 0xF);
                key.EntryNumber = 0;
                value.Value1    = 0;
                value.Value2    = 0;
                value.Value3    = 0;
                return;
            }
            if (code < 0xE0)
            {
                //If stage 4 (3% success)
                key.Timestamp   = prevKey.Timestamp;
                key.PointID     = prevKey.PointID + 1 + (code & 0xF);
                key.EntryNumber = 0;
                value.Value1    = stream.ReadUInt32();
                value.Value2    = 0;
                value.Value3    = 0;
                return;
            }

            //Stage 5: 2%
            //Stage 5: Catch All
            if ((code & 16) != 0) //T is set
            {
                key.Timestamp = prevKey.Timestamp + stream.Read7BitUInt64();
                key.PointID   = stream.Read7BitUInt64();
            }
            else
            {
                key.Timestamp = prevKey.Timestamp;
                key.PointID   = prevKey.PointID + stream.Read7BitUInt64();
            }


            if ((code & 8) != 0) //E is set)
            {
                key.EntryNumber = stream.Read7BitUInt64();
            }
            else
            {
                key.EntryNumber = 0;
            }

            if ((code & 4) != 0) //V1 is set)
            {
                value.Value1 = stream.ReadUInt64();
            }
            else
            {
                value.Value1 = stream.ReadUInt32();
            }

            if ((code & 2) != 0) //V2 is set)
            {
                value.Value2 = stream.Read7BitUInt64();
            }
            else
            {
                value.Value2 = 0;
            }

            if ((code & 1) != 0) //V3 is set)
            {
                value.Value3 = stream.Read7BitUInt64();
            }
            else
            {
                value.Value3 = 0;
            }
        }
        public override void Decode(BinaryStreamBase stream, HistorianKey prevKey, HistorianValue prevValue, HistorianKey key, HistorianValue value, out bool isEndOfStream)
        {
            isEndOfStream = false;
            byte code = stream.ReadUInt8();

            if (code == 255)
            {
                isEndOfStream = true;
                return;
            }

            if (code < 128)
            {
                if (code < 64)
                {
                    key.Timestamp   = prevKey.Timestamp;
                    key.PointID     = prevKey.PointID ^ code;
                    key.EntryNumber = 0;
                    value.Value1    = 0;
                    value.Value2    = 0;
                    value.Value3    = 0;
                }
                else
                {
                    key.Timestamp   = prevKey.Timestamp;
                    key.PointID     = prevKey.PointID ^ code ^ 64;
                    key.EntryNumber = 0;
                    value.Value1    = stream.ReadUInt32();
                    value.Value2    = 0;
                    value.Value3    = 0;
                }

                return;
            }

            if ((code & 64) != 0) //T is set
            {
                key.Timestamp = prevKey.Timestamp ^ stream.Read7BitUInt64();
            }
            else
            {
                key.Timestamp = prevKey.Timestamp;
            }

            key.PointID = prevKey.PointID ^ stream.Read7BitUInt64();

            if ((code & 32) != 0) //E is set)
            {
                key.EntryNumber = stream.Read7BitUInt64();
            }
            else
            {
                key.EntryNumber = 0;
            }

            if ((code & 16) != 0) //V1 High is set)
            {
                value.Value1 = stream.ReadUInt64();
            }
            else if ((code & 8) != 0) //V1 low is set)
            {
                value.Value1 = stream.ReadUInt32();
            }
            else
            {
                value.Value1 = 0;
            }

            if ((code & 4) != 0) //V2 is set)
            {
                value.Value2 = stream.ReadUInt64();
            }
            else
            {
                value.Value2 = 0;
            }

            if ((code & 2) != 0) //V1 High is set)
            {
                value.Value3 = stream.ReadUInt64();
            }
            else if ((code & 1) != 0) //V1 low is set)
            {
                value.Value3 = stream.ReadUInt32();
            }
            else
            {
                value.Value3 = 0;
            }

            return;
        }