Пример #1
0
        /// <inheritdoc />
        public override TObjectType[] Read(IWireStreamReaderStrategy source)
        {
            byte[] bytes = source.ReadAllBytes();
            FixedBufferWireReaderStrategy fixedStrategy = new FixedBufferWireReaderStrategy(bytes, 0, bytes.Length);

            QuickList <TObjectType> objects = new QuickList <TObjectType>(4);

            //Read until the fixed buffer is empty. This iwll give us all objects without read exceptions when end is reached.
            while (!fixedStrategy.isFinished)
            {
                objects.Add(ElementSerializer.Read(fixedStrategy));
            }

            //We can avoid some copies like this
            return(objects.Count == objects._items.Length ? objects._items : objects.ToArray());
        }
Пример #2
0
        public static void Test_Buffered_Peeking_Can_Peek_Bytes()
        {
            //arrange
            DefaultStreamReaderStrategy reader = new DefaultStreamReaderStrategy(new byte[] { 5, 6, 7, 5 });

            //act
            IWireStreamReaderStrategy peekedBufferReader = reader.PeekWithBuffering();

            //assert
            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(5, peekedBufferReader.PeekByte());
            }

            Assert.AreEqual(5, peekedBufferReader.ReadByte());
            Assert.AreEqual(6, peekedBufferReader.ReadByte());

            byte[] readBytes = peekedBufferReader.ReadAllBytes();

            Assert.AreEqual(7, readBytes[0]);
            Assert.AreEqual(5, readBytes[1]);

            Assert.Throws <InvalidOperationException>(() => peekedBufferReader.ReadByte());
        }
Пример #3
0
 public override byte[] Read(IWireStreamReaderStrategy source)
 {
     return(source.ReadAllBytes());
 }