Example #1
0
            public void Bool()
            {
                var writer = new FastMemoryWriter();

                writer.Write(true);
                writer.Write(false);
                var result = writer.ToArray();

                Assert.True(result[0] == 1);
                Assert.True(result[1] == 0);
            }
Example #2
0
            public void Char()
            {
                var writer = new FastMemoryWriter();

                writer.Write('a');
                var result = writer.ToArray();

                Assert.True(result[0] == (byte)'a');
            }
Example #3
0
        public void SeekToBegin()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            Assert.Equal(0, stream.Position);
        }
Example #4
0
            public void Byte()
            {
                byte digit = 10;

                var writer = new FastMemoryWriter();

                writer.Write(digit);
                var result = writer.ToArray();

                Assert.True(result.First() == digit);
            }
Example #5
0
        public void SeekWithCurrent()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            var result = stream.Position;

            stream.Seek(-1, System.IO.SeekOrigin.Current);

            Assert.Equal(result - 1, stream.Position);
        }
Example #6
0
            public void Bytesv2()
            {
                var bytes = new byte[] { 10, 10, 11, 12 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes, 0, bytes.Length);
                var result = writer.ToArray();

                Assert.True(bytes.SequenceEqual(result));
            }
Example #7
0
        public void UInteger()
        {
            const int count = 10_000;

            using (var stream = new FastMemoryWriter(count * 5))
            {
                for (int i = 0; i < 10_000; i++)
                {
                    stream.Write((uint)257);
                }
            }
        }
Example #8
0
        public void SeekToEnd()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");

            var result = stream.Position;

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            stream.Seek(0, System.IO.SeekOrigin.End);

            Assert.Equal(result, stream.Position);
        }
Example #9
0
        public void SetLength()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJJonnoJJonnoJJonnoJ");

            var newLength = 10;

            stream.SetLength(newLength);

            Assert.Equal(newLength, stream.Length);
            Assert.Equal(newLength, stream.Position);
        }
Example #10
0
        public void ReadString()
        {
            var text   = "hello";
            var memory = new FastMemoryWriter();

            memory.Write(text);
            memory.Seek(0, SeekOrigin.Begin);

            var reader = new FastReader(memory);
            var result = reader.ReadString();

            Assert.Equal(text, result);
        }
Example #11
0
            public void Int64()
            {
                long digit = 10;

                var writer = new FastMemoryWriter();

                writer.Write(digit);
                var result = writer.ToArray();

                var value = BitConverter.GetBytes(digit);

                Assert.True(value.SequenceEqual(result));
            }
Example #12
0
            public void Merge()
            {
                var bytes = new byte[] { 10, 10 };

                var writer1 = new FastMemoryWriter();

                writer1.Write(bytes);

                var writer2 = new FastMemoryWriter();
                var result  = writer2.Merge(writer1);

                Assert.Equal(bytes, result);
            }
Example #13
0
        public void TwoSeeks()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            var initilPoisition = stream.Position;

            stream.Seek(-2, System.IO.SeekOrigin.Current);
            Assert.Equal(initilPoisition - 2, stream.Position);

            stream.Seek(-2, System.IO.SeekOrigin.Current);
            Assert.Equal(initilPoisition - 4, stream.Position);
            Assert.Equal(initilPoisition, stream.Length);
        }
Example #14
0
        public void OnlyFastMemoryWriter()
        {
            for (int j = 0; j < 10; j++)
            {
                using (var memory = new FastMemoryWriter(this._hugeArrayPool))
                {
                    for (int i = 0; i < this.ItemCount; i++)
                    {
                        memory.Write(1.0);
                    }

                    var bytes = memory.ToArray();
                }
            }
        }
Example #15
0
            public void String()
            {
                var text = "lorem te ipsum";

                var writer = new FastMemoryWriter();

                writer.Write(text);
                var result = writer.ToArray();

                var bytes = BitConverter.GetBytes(text.Length);

                bytes = bytes.Concat(Encoding.UTF8.GetBytes(text)).ToArray();

                Assert.True(bytes.SequenceEqual(result));
            }
Example #16
0
            public void Bytes()
            {
                var bytes = new byte[] { 10, 10, 11, 12 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes);
                writer.Seek(0, SeekOrigin.Begin);

                var result = new byte[4];

                writer.Read(result);

                Assert.True(bytes.SequenceEqual(result));
            }
Example #17
0
            public void AbleToProcess(int size)
            {
                var count = 100;
                var bytes = new byte[size];

                using (var writer = new FastMemoryWriter())
                {
                    for (int i = 0; i < count; i++)
                    {
                        writer.Write(bytes);
                    }

                    var result = writer.ToArray();
                    Assert.True(Enumerable.Repeat(bytes, count).SelectMany(o => o).SequenceEqual(result));
                }
            }
Example #18
0
            public async Task CopyToAsync()
            {
                var bytes = new byte[] { 10, 10 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes);
                writer.Seek(0, SeekOrigin.Begin);

                var stream = new MemoryStream();
                await writer.CopyToAsync(stream);

                var result = stream.ToArray();

                Assert.Equal(bytes, result);
            }
Example #19
0
            public void WriteToStream()
            {
                var bytes = new byte[] { 10, 10 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes);

                var stream = new MemoryStream();

                writer.FastCopyTo(stream);

                var result = stream.ToArray();

                Assert.Equal(bytes, result);
            }
Example #20
0
        public void FastBytes()
        {
            var data = new byte[this.Size];

            for (int j = 0; j < 10; j++)
            {
                using (var memory = new FastMemoryWriter(this._hugeArrayPool))
                {
                    for (int i = 0; i < this.ItemCount; i++)
                    {
                        memory.Write(data, 0, data.Length);
                    }

                    var bytes = memory.ToArray();
                }
            }
        }
Example #21
0
        public void Read()
        {
            var text      = "JonnoJ";
            var textBytes = Encoding.UTF8.GetBytes(text);

            var stream = new FastMemoryWriter();

            stream.Write(text);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            var result = new byte[stream.Length];

            stream.Read(result, 0, result.Length);

            // skip string length
            Assert.True(textBytes.SequenceEqual(result.Skip(4)));
        }
Example #22
0
        public void ReadOnEmpty()
        {
            var text = "JonnoJ";

            var stream = new FastMemoryWriter();

            stream.Write(text);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            var result = new byte[stream.Length];
            var read   = stream.Read(result, 0, result.Length);

            Assert.Equal(result.Length, read);

            read = stream.Read(result, 0, result.Length);
            Assert.Equal(0, read);
        }