Ejemplo n.º 1
0
        /// <summary>
        /// Loads the header.
        /// </summary>
        public void LoadHeader(BinaryStreamBase stream)
        {
            stream.Position = 0;
            byte version = stream.ReadUInt8();

            if (version == 109)
            {
                stream.Position = 0;
                if (EncodingDefinition.FixedSizeCombinedEncoding != new EncodingDefinition(stream.ReadGuid()))
                {
                    throw new Exception("Header Corrupt");
                }
                if (TreeNodeType != new EncodingDefinition(stream.ReadGuid()))
                {
                    throw new Exception("Header Corrupt");
                }
                if (BlockSize != stream.ReadInt32())
                {
                    throw new Exception("Header Corrupt");
                }
                if (stream.ReadUInt8() != 0)
                {
                    throw new Exception("Header Corrupt");
                }
                LastAllocatedBlock   = stream.ReadUInt32();
                RootNodeIndexAddress = stream.ReadUInt32();
                RootNodeLevel        = stream.ReadUInt8();
            }
            else if (version == 1)
            {
                if (BlockSize != stream.ReadInt32())
                {
                    throw new Exception("Header Corrupt");
                }
                if (TreeNodeType != new EncodingDefinition(stream))
                {
                    throw new Exception("Header Corrupt");
                }
                LastAllocatedBlock   = stream.ReadUInt32();
                RootNodeIndexAddress = stream.ReadUInt32();
                RootNodeLevel        = stream.ReadUInt8();
            }
            else
            {
                throw new VersionNotFoundException();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new filter backed by a <see cref="BitArray"/>.
 /// </summary>
 /// <param name="stream">The the stream to load from.</param>
 /// <param name="pointCount">the number of points in the stream.</param>
 /// <param name="maxValue">the maximum value stored in the bit array. Cannot be larger than int.MaxValue-1</param>
 public UIntHashSet(BinaryStreamBase stream, int pointCount, ulong maxValue)
 {
     m_maxValue = maxValue;
     m_points   = new HashSet <uint>();
     while (pointCount > 0)
     {
         m_points.Add(stream.ReadUInt32());
         pointCount--;
     }
 }
Ejemplo n.º 3
0
            /// <summary>
            /// Creates a new filter backed by a <see cref="BitArray"/>.
            /// </summary>
            /// <param name="stream">The the stream to load from.</param>
            /// <param name="pointCount">the number of points in the stream.</param>
            /// <param name="maxValue">the maximum value stored in the bit array. Cannot be larger than int.MaxValue-1</param>
            public BitArrayFilter(BinaryStreamBase stream, int pointCount, ulong maxValue)
            {
                if (maxValue >= int.MaxValue)
                {
                    throw new ArgumentOutOfRangeException("maxValue", "Cannot be larger than int.MaxValue-1");
                }

                MaxValue = maxValue;
                m_points = new BitArray(false, (int)maxValue + 1);
                while (pointCount > 0)
                {
                    //Since a bitarray cannot have more than 32bit
                    m_points.SetBit((int)stream.ReadUInt32());
                    pointCount--;
                }

                foreach (int point in m_points.GetAllSetBits())
                {
                    MinValue = (ulong)point;
                    break;
                }
            }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
 public override void Read(BinaryStreamBase stream)
 {
     Value = stream.ReadUInt32();
 }
        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;
        }