Example #1
0
 public static TValue ReadValue <TValue>(this Stream stream, int bufferSize = 655360)
 {
     using (var ebr = new ExaStreamReader <TValue>(bufferSize))
     {
         return(ebr.Read(stream));
     }
 }
Example #2
0
 public static IEnumerable <TValue> EnumerateValues <TValue>(this Stream stream, int bufferSize = 655360)
 {
     using (var ebr = new ExaStreamReader <IEnumerable <TValue> >(bufferSize))
     {
         var enumerable = ebr.Read(stream);
         if (enumerable != null)
         {
             foreach (var value in enumerable)
             {
                 yield return(value);
             }
         }
     }
 }
Example #3
0
        private static void ExaDeserializer <T>(T[] values)
            where T : new()
        {
            using (var ms = new MemoryStream())
            {
                using (var bw = new ExaStreamWriter <T>())
                {
                    bw.Write(ms, values[0]);
                }

                using (var br = new ExaStreamReader <T>())
                {
                    foreach (var value in values)
                    {
                        ms.Position = 0;
                        var retreive = br.Read(ms);
                    }
                }
            }
        }
Example #4
0
        private void EnumerableTestMethod <TValue>()
        {
            var arrayValue = TestDataGenerator <TValue> .TestData;

            using (var ms = new MemoryStream(new byte[]
            {
                0x45, 0x23, 0x01, 0x00,
            }.
                                             Concat(TestDataGenerator <TValue> .TestDataBytes).
                                             ToArray()))
            {
                foreach (var entry in ms.EnumerateValues <TValue>().
                         Select((sav, index) => new { sav, index }).
                         Zip(arrayValue, (entry, arv) => new { entry.index, entry.sav, arv }))
                {
                    Assert.AreEqual(entry.sav, entry.arv);
                    Assert.AreEqual(ms.Position, (entry.index + 1) * TestDataGenerator <TValue> .ElementSize + 4);
                }

                Assert.AreEqual(ms.Length, ms.Position);
            }

            using (var ms = new MemoryStream(new byte[]
            {
                0x00, 0x00, 0x00, 0x00
            }))
            {
                var enumerable = ms.EnumerateValues <TValue>();

                Assert.IsNotNull(enumerable);
                Assert.IsFalse(enumerable.Any());
                Assert.AreEqual(ms.Length, ms.Position);
            }

            using (var ms = new MemoryStream(new byte[]
            {
                0xfe, 0xff, 0xff, 0xff,
            }.
                                             Concat(TestDataGenerator <TValue> .TestDataBytesWithFlags).
                                             ToArray()))
            {
                foreach (var entry in ms.EnumerateValues <TValue>().
                         Select((sav, index) => new { sav, index }).
                         Zip(arrayValue, (entry, arv) => new { entry.index, entry.sav, arv }))
                {
                    Assert.AreEqual(entry.sav, entry.arv);
                    Assert.AreEqual(ms.Position, (entry.index + 1) * (TestDataGenerator <TValue> .ElementSize + 1) + 4);
                }

                Assert.AreEqual(ms.Length, ms.Position);
            }

            using (var ms = new MemoryStream(new byte[]
            {
                0xfe, 0xff, 0xff, 0xff,
                0x00
            }))
            {
                var enumerable = ms.EnumerateValues <TValue>();

                Assert.IsNotNull(enumerable);
                Assert.IsFalse(enumerable.Any());
                Assert.AreEqual(ms.Length, ms.Position);
            }

            using (var ms = new MemoryStream(new byte[]
            {
                0xff, 0xff, 0xff, 0xff,
            }))
            {
                var enumerable = ms.EnumerateValues <TValue>();

                Assert.IsNotNull(enumerable);
                Assert.IsFalse(enumerable.Any());
                Assert.AreEqual(ms.Length, ms.Position);
            }

            using (var ms = new MemoryStream(new byte[]
            {
                0xff, 0xff, 0xff, 0xff,
            }))
            {
                using (var sr = new ExaStreamReader <IEnumerable <TValue> >())
                {
                    var enumerable = sr.Read(ms);

                    Assert.IsNull(enumerable);
                    Assert.AreEqual(ms.Length, ms.Position);
                }
            }
        }