BitsetsNET.RLEBitset.Deserialize C# (CSharp) Method

Deserialize() public static method

Read a binary serialization of a RLE bitset, as written by the Serialize method.
public static Deserialize ( System.Stream stream ) : RLEBitset
stream System.Stream The stream to read from.
return RLEBitset
        public static RLEBitset Deserialize(Stream stream)
        {
            RLEBitset bitset = new RLEBitset();

            //We don't care about the encoding, but we have to specify something to be able to set the stream as leave open.
            using (BinaryReader reader = new BinaryReader(stream, Encoding.Default, true))
            {
                bitset.length = reader.ReadInt32();
                while (stream.Position < stream.Length - 1)
                {
                    Run currRun = new Run();
                    currRun.StartIndex = reader.ReadInt32();
                    currRun.EndIndex = reader.ReadInt32();
                    bitset.runArray.Add(currRun);
                }
            }
            return bitset;
        }