Пример #1
0
        /// <summary>
        /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for streams.
        /// </summary>
        public static IBitStream Create(Stream stream)
        {
            #if BITSTREAMDEBUG
            byte[] data;
            using (var memstream = new MemoryStream(checked((int)stream.Length))) {
                stream.CopyTo(memstream);
                data = memstream.GetBuffer();
            }

            var bs1 = new BitArrayStream(data);
            var bs2 = new ManagedBitStream();
            bs2.Initialize(new MemoryStream(data));
            var bs3 = new UnsafeBitStream();
            bs3.Initialize(new MemoryStream(data));
            return new DebugBitStream(bs1, new DebugBitStream(bs2, bs3));
            #else

            #if YOLO
            var bs = new UnsafeBitStream();
            #else
            var bs = new ManagedBitStream();
            #endif

            bs.Initialize(stream);
            return bs;
            #endif
        }
Пример #2
0
		private IBitStream CreateBS(byte[] data)
		{
			IBitStream managed = new ManagedBitStream(), @unsafe = new UnsafeBitStream();
			managed.Initialize(new AwkwardStream(new MemoryStream(data), rng));
			@unsafe.Initialize(new AwkwardStream(new MemoryStream(data), rng));
			return new DebugBitStream(new BitArrayStream(data), new DebugBitStream(managed, @unsafe));
		}
Пример #3
0
        /// <summary>
        /// Creates an instance of the preferred <see cref="IBitStream"/> implementation for byte arrays.
        /// </summary>
        public static IBitStream Create(byte[] data)
        {
            #if BITSTREAMDEBUG
            var bs1 = new BitArrayStream(data);
            var bs2 = new ManagedBitStream();
            bs2.Initialize(new MemoryStream(data));
            var bs3 = new UnsafeBitStream();
            bs3.Initialize(new MemoryStream(data));
            return new DebugBitStream(bs1, new DebugBitStream(bs2, bs3));
            #else

            #if YOLO
            var bs = new UnsafeBitStream();
            #else
            var bs = new ManagedBitStream();
            #endif

            bs.Initialize(new MemoryStream(data));
            return bs;
            #endif
        }