コード例 #1
0
            public void Char()
            {
                var writer = new FastMemoryWriter();

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

                Assert.True(result[0] == (byte)'a');
            }
コード例 #2
0
            public void Empty()
            {
                var writer = new FastMemoryWriter();
                var result = writer.ToArray();

                var empty = new byte[0];

                Assert.True(empty.SequenceEqual(result));
            }
コード例 #3
0
            public void Byte()
            {
                byte digit = 10;

                var writer = new FastMemoryWriter();

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

                Assert.True(result.First() == digit);
            }
コード例 #4
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);
            }
コード例 #5
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));
            }
コード例 #6
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));
            }
コード例 #7
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));
            }
コード例 #8
0
ファイル: Program.cs プロジェクト: byme8/faststream
        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();
                }
            }
        }
コード例 #9
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));
                }
            }
コード例 #10
0
ファイル: Program.cs プロジェクト: byme8/faststream
        public void FastMemoryWriterAndBinaryWriter()
        {
            for (int j = 0; j < 10; j++)
            {
                using (var memory = new FastMemoryWriter(this._hugeArrayPool))
                    using (var writer = new BinaryWriter(memory))
                    {
                        for (int i = 0; i < this.ItemCount; i++)
                        {
                            writer.Write(1.0);
                        }

                        var bytes = memory.ToArray();
                    }
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: byme8/faststream
        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();
                }
            }
        }