/// <summary> /// Loads a <see cref="DatabaseInfo"/> from stream. /// </summary> /// <param name="stream"></param> public DatabaseInfo(BinaryStreamBase stream) { byte version = stream.ReadUInt8(); switch (version) { case 1: DatabaseName = stream.ReadString(); KeyTypeID = stream.ReadGuid(); ValueTypeID = stream.ReadGuid(); int count = stream.ReadInt32(); EncodingDefinition[] definitions = new EncodingDefinition[count]; for (int x = 0; x < count; x++) { definitions[x] = new EncodingDefinition(stream); } SupportedStreamingModes = new ReadOnlyCollection <EncodingDefinition>(definitions); KeyType = Library.GetSortedTreeType(KeyTypeID); ValueType = Library.GetSortedTreeType(ValueTypeID); break; default: throw new VersionNotFoundException("Unknown version code."); } }
public override void Read(BinaryStreamBase stream) { CollectedTime = stream.ReadUInt64(); TableId = stream.ReadInt32(); DataLength = stream.ReadUInt8(); stream.Read(Data, 0, Data.Length); }
/// <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(); } }
public unsafe override void Decode(BinaryStreamBase stream, AmiKey prevKey, AmiValue prevValue, AmiKey key, AmiValue value, out bool isEndOfStream) { isEndOfStream = false; key.Timestamp = stream.ReadUInt64(); key.PointID = stream.ReadUInt64(); value.CollectedTime = stream.ReadUInt64(); value.TableId = stream.ReadInt32(); value.DataLength = stream.ReadUInt8(); stream.Read(value.Data, 0, value.DataLength); }
/// <summary> /// Attempts to read the next point from the stream. /// </summary> /// <param name="stream">The stream to read from</param> /// <param name="key">the key to store the value to</param> /// <param name="value">the value to store to</param> /// <returns>True if successful. False if end of the stream has been reached.</returns> public override bool TryDecode(BinaryStreamBase stream, TKey key, TValue value) { if (!m_encoding.ContainsEndOfStreamSymbol) { if (stream.ReadUInt8() == 0) { return(false); } } m_encoding.Decode(stream, m_prevKey, m_prevValue, key, value, out bool endOfStream); key.CopyTo(m_prevKey); value.CopyTo(m_prevValue); return(!endOfStream); }
/// <summary> /// Creates a new <see cref="SortedTreeEngineReaderOptions"/> from a stream /// </summary> /// <param name="stream">the stream to read from</param> public SortedTreeEngineReaderOptions(BinaryStreamBase stream) { byte version = stream.ReadUInt8(); switch (version) { case 0: Timeout = new TimeSpan(stream.ReadInt64()); MaxReturnedCount = stream.ReadInt64(); MaxScanCount = stream.ReadInt64(); MaxSeekCount = stream.ReadInt64(); break; default: throw new VersionNotFoundException("Unknown Version"); } }
private static SeekFilterBase <TKey> CreateFromStream <TKey>(BinaryStreamBase stream) where TKey : TimestampPointIDBase <TKey>, new() { byte version = stream.ReadUInt8(); switch (version) { case 0: return(null); case 1: return(new FixedRange <TKey>(stream)); case 2: return(new IntervalRanges <TKey>(stream)); default: throw new VersionNotFoundException("Unknown Version"); } }
/// <summary> /// Reads the header data. /// </summary> /// <param name="stream"></param> /// <param name="treeNodeType"></param> /// <param name="blockSize"></param> internal static void ReadHeader(BinaryStreamBase stream, out EncodingDefinition treeNodeType, out int blockSize) { stream.Position = 0; byte version = stream.ReadUInt8(); if (version == 109) { stream.Position = 0; stream.ReadGuid(); treeNodeType = new EncodingDefinition(stream.ReadGuid()); blockSize = stream.ReadInt32(); } else if (version == 1) { blockSize = stream.ReadInt32(); treeNodeType = new EncodingDefinition(stream); } else { throw new VersionNotFoundException(); } }
/// <summary> /// Loads a <see cref="EncodingDefinition"/> from a stream /// </summary> /// <param name="stream">the stream to load from.</param> public EncodingDefinition(BinaryStreamBase stream) { byte code = stream.ReadUInt8(); if (code == 1) { m_keyEncodingMethod = Guid.Empty; m_valueEncodingMethod = Guid.Empty; m_keyValueEncodingMethod = stream.ReadGuid(); IsKeyValueEncoded = true; } else if (code == 2) { m_keyEncodingMethod = stream.ReadGuid(); m_valueEncodingMethod = stream.ReadGuid(); m_keyValueEncodingMethod = Guid.Empty; IsKeyValueEncoded = false; } m_hashCode = ComputeHashCode(); m_isFixedSizeEncoding = this == FixedSizeCombinedEncoding || this == FixedSizeIndividualEncoding; }
private static MatchFilterBase <TKey, TValue> CreateFromStream <TKey, TValue>(BinaryStreamBase stream) where TKey : TimestampPointIDBase <TKey>, new() { MatchFilterBase <TKey, TValue> filter; byte version = stream.ReadUInt8(); ulong maxValue; int count; switch (version) { case 0: return(null); case 1: maxValue = stream.ReadUInt64(); count = stream.ReadInt32(); if (maxValue < 8 * 1024 * 64) //64KB of space, 524288 { filter = new BitArrayFilter <TKey, TValue>(stream, count, maxValue); } else { filter = new UIntHashSet <TKey, TValue>(stream, count, maxValue); } break; case 2: maxValue = stream.ReadUInt64(); count = stream.ReadInt32(); filter = new ULongHashSet <TKey, TValue>(stream, count, maxValue); break; default: throw new VersionNotFoundException("Unknown Version"); } return(filter); }
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; }