public override void Write(BinaryStreamBase stream) { stream.Write(Timestamp); stream.Write(PointID); stream.Write(TableId); stream.Write(CollectedTime); }
public override void Write(BinaryStreamBase stream) { stream.Write(CollectedTime); stream.Write(TableId); stream.Write(DataLength); stream.Write(Data, 0, Data.Length); }
public override void Read(BinaryStreamBase stream) { CollectedTime = stream.ReadUInt64(); TableId = stream.ReadInt32(); DataLength = stream.ReadUInt8(); stream.Read(Data, 0, Data.Length); }
/// <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 unsafe override void Encode(BinaryStreamBase stream, HistorianKey prevKey, HistorianValue prevValue, HistorianKey key, HistorianValue value) { byte *ptr = stackalloc byte[MaxCompressionSize]; int length = Encode(ptr, prevKey, prevValue, key, value); stream.Write(ptr, length); }
private static void SelfTest() { UnmanagedMemoryStream ms1 = new UnmanagedMemoryStream(); BinaryStreamBase ms = ms1.CreateBinaryStream(); Random rand = new Random(); int seed = rand.Next(); rand = new Random(seed); byte[] data = new byte[255]; rand.NextBytes(data); while (ms.Position < 1000000) { ms.Write(data, 0, rand.Next(256)); } byte[] data2 = new byte[255]; rand = new Random(seed); rand.NextBytes(data2); ms.Position = 0; Compare(data, data2, 255); while (ms.Position < 1000000) { int length = rand.Next(256); ms.ReadAll(data2, 0, length); Compare(data, data2, length); } ms.Dispose(); ms1.Dispose(); }
public override void Read(BinaryStreamBase stream) { Timestamp = stream.ReadUInt64(); PointID = stream.ReadUInt64(); TableId = stream.ReadInt32(); CollectedTime = stream.ReadUInt64(); }
/// <summary> /// Writes this data to the <see cref="stream"/>. /// </summary> /// <param name="stream">the stream to write data to</param> public void Save(BinaryStreamBase stream) { stream.Write((byte)0); stream.Write(Timeout.Ticks); stream.Write(MaxReturnedCount); stream.Write(MaxScanCount); stream.Write(MaxSeekCount); }
/// <summary> /// Creates a filter by reading from the stream. /// </summary> /// <param name="stream">the stream to read from</param> public SeekToKey(BinaryStreamBase stream) : this() { m_keyToFind.Timestamp = stream.ReadUInt64(); m_keyToFind.PointID = stream.ReadUInt64(); m_keyToFind.CopyTo(StartOfRange); m_keyToFind.CopyTo(EndOfRange); }
public override SeekFilterBase <TKey> Create <TKey>(BinaryStreamBase stream) { MethodInfo method = typeof(TimestampSeekFilter).GetMethod("CreateFromStream", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo generic = method.MakeGenericMethod(typeof(TKey)); var rv = generic.Invoke(null, new[] { stream }); return((SeekFilterBase <TKey>)rv); }
public override MatchFilterBase <TKey, TValue> Create <TKey, TValue>(BinaryStreamBase stream) { MethodInfo method = typeof(PointIdMatchFilter).GetMethod("CreateFromStream", BindingFlags.NonPublic | BindingFlags.Static); MethodInfo generic = method.MakeGenericMethod(typeof(TKey), typeof(TValue)); object rv = generic.Invoke(null, new[] { stream }); return((MatchFilterBase <TKey, TValue>)rv); }
/// <summary> /// Decodes <see cref="key"/> and <see cref="value"/> from the provided <see cref="stream"/>. /// </summary> /// <param name="stream">where to read the data</param> /// <param name="prevKey">the previous key if required by <see cref="PairEncodingBase{TKey,TValue}.UsesPreviousKey"/>. Otherwise null.</param> /// <param name="prevValue">the previous value if required by <see cref="PairEncodingBase{TKey,TValue}.UsesPreviousValue"/>. Otherwise null.</param> /// <param name="key">the place to store the decoded key</param> /// <param name="value">the place to store the decoded value</param> /// <param name="isEndOfStream">outputs true if the end of the stream symbol is detected. Not all encoding methods have an end of stream symbol and therefore will always return false.</param> /// <returns>the number of bytes necessary to decode the next key/value.</returns> public override void Decode(BinaryStreamBase stream, TKey prevKey, TValue prevValue, TKey key, TValue value, out bool isEndOfStream) { m_keyEncoding.Decode(stream, prevKey, key, out isEndOfStream); if (isEndOfStream) { return; } m_valueEncoding.Decode(stream, prevValue, value, out isEndOfStream); }
public unsafe override void Encode(BinaryStreamBase stream, AmiKey prevKey, AmiValue prevValue, AmiKey key, AmiValue value) { stream.Write(key.Timestamp); stream.Write(key.PointID); stream.Write(value.CollectedTime); stream.Write(value.TableId); stream.Write(value.DataLength); stream.Write(value.Data, 0, value.DataLength); }
/// <summary> /// Serializes the filter to a stream /// </summary> /// <param name="stream">the stream to write to</param> public override void Save(BinaryStreamBase stream) { stream.Write((byte)2); //Stored with interval data stream.Write(m_start); stream.Write(m_stop); stream.Write(m_mainInterval); stream.Write(m_subInterval); stream.Write(m_tolerance); }
public override void Save(BinaryStreamBase stream) { stream.Write((byte)1); //Stored as array of uint[] stream.Write(m_maxValue); stream.Write(m_points.Count); foreach (uint x in m_points) { stream.Write(x); } }
public override void Save(BinaryStreamBase stream) { stream.Write((byte)1); //Stored as array of uint[] stream.Write(MaxValue); stream.Write(m_points.SetCount); foreach (int x in m_points.GetAllSetBits()) { stream.Write((uint)x); } }
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> /// Creates a filter by reading from the stream. /// </summary> /// <param name="stream">the stream to read from</param> public FixedRange(BinaryStreamBase stream) : this() { m_start = stream.ReadUInt64(); m_stop = stream.ReadUInt64(); StartOfRange.SetMin(); StartOfRange.Timestamp = m_start; EndOfRange.SetMax(); EndOfRange.Timestamp = m_stop; }
/// <summary> /// Encodes the current key/value to the stream. /// </summary> /// <param name="stream">the stream to write to</param> /// <param name="currentKey">the key to write</param> /// <param name="currentValue">the value to write</param> public override void Encode(BinaryStreamBase stream, TKey currentKey, TValue currentValue) { if (!m_encoding.ContainsEndOfStreamSymbol) { stream.Write((byte)1); } m_encoding.Encode(stream, m_prevKey, m_prevValue, currentKey, currentValue); currentKey.CopyTo(m_prevKey); currentValue.CopyTo(m_prevValue); }
/// <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--; } }
/// <summary> /// Writes the end of the stream symbol to the <see cref="stream"/>. /// </summary> /// <param name="stream">the stream to write to</param> public override void WriteEndOfStream(BinaryStreamBase stream) { if (m_encoding.ContainsEndOfStreamSymbol) { stream.Write(m_encoding.EndOfStreamSymbol); } else { stream.Write((byte)0); } }
/// <summary> /// Creates a filter by reading from the stream. /// </summary> /// <param name="stream">the stream to read from</param> public IntervalRanges(BinaryStreamBase stream) : this() { ulong start = stream.ReadUInt64(); ulong stop = stream.ReadUInt64(); ulong mainInterval = stream.ReadUInt64(); ulong subInterval = stream.ReadUInt64(); ulong tolerance = stream.ReadUInt64(); Initialize(start, stop, mainInterval, subInterval, tolerance); }
public void Save(BinaryStreamBase stream) { stream.Write((byte)1); stream.Write(DatabaseName); stream.Write(KeyTypeID); stream.Write(ValueTypeID); stream.Write(SupportedStreamingModes.Count); foreach (EncodingDefinition encoding in SupportedStreamingModes) { encoding.Save(stream); } }
/// <summary> /// Serializes the <see cref="EncodingDefinition"/> to the provided <see cref="stream"/> /// </summary> /// <param name="stream">the stream to write to</param> public void Save(BinaryStreamBase stream) { if (IsKeyValueEncoded) { stream.Write((byte)1); stream.Write(KeyValueEncodingMethod); } else { stream.Write((byte)2); stream.Write(KeyEncodingMethod); stream.Write(ValueEncodingMethod); } }
/// <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> /// 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(); } }
/// <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"); } }
/// <summary> /// Writes the first page of the SortedTree as long as the <see cref="IsDirty"/> flag is set. /// After returning, the IsDirty flag is cleared. /// </summary> public void SaveHeader(BinaryStreamBase stream) { if (!IsDirty) { return; } long oldPosotion = stream.Position; stream.Position = 0; stream.Write((byte)1); stream.Write(BlockSize); TreeNodeType.Save(stream); stream.Write(LastAllocatedBlock); stream.Write(RootNodeIndexAddress); //Root Index stream.Write(RootNodeLevel); //Root Index stream.Position = oldPosotion; m_isDirty = false; }
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> /// 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; } }