An abstract class for reading/writing to a little endian stream.
Inheritance: IDisposable
 /// <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>
 /// 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="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();
             var 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.");
     }
 }
 /// <summary>
 /// Writes the provided data to the BinaryWriter
 /// </summary>
 /// <param name="stream"></param>
 public abstract void Write(BinaryStreamBase stream);
 /// <summary>
 /// Reads the provided key from the stream.
 /// </summary>
 /// <param name="stream"></param>
 public abstract void Read(BinaryStreamBase stream);
 public void Save(BinaryStreamBase stream)
 {
     stream.Write((byte)1);
     stream.Write(DatabaseName);
     stream.Write(KeyTypeID);
     stream.Write(ValueTypeID);
     stream.Write(SupportedStreamingModes.Count);
     foreach (var encoding in SupportedStreamingModes)
     {
         encoding.Save(stream);
     }
 }
 /// <summary>
 /// Creates a <see cref="Stream"/> wrapper around a <see cref="BinaryStreamBase"/>.
 /// </summary>
 /// <param name="baseStream"></param>
 internal BinaryStreamStream(BinaryStreamBase baseStream)
 {
     BaseStream = baseStream;
 }
 /// <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 <see cref="Stream"/> wrapper around a <see cref="BinaryStreamBase"/>.
 /// </summary>
 /// <param name="baseStream"></param>
 internal BinaryStreamStream(BinaryStreamBase baseStream)
 {
     BaseStream = baseStream;
 }
        /// <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;
        }