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); }
public void Char() { var writer = new FastMemoryWriter(); writer.Write('a'); var result = writer.ToArray(); Assert.True(result[0] == (byte)'a'); }
public void SeekToBegin() { var stream = new FastMemoryWriter(); stream.Write("JonnoJ"); stream.Seek(0, System.IO.SeekOrigin.Begin); Assert.Equal(0, stream.Position); }
public void Byte() { byte digit = 10; var writer = new FastMemoryWriter(); writer.Write(digit); var result = writer.ToArray(); Assert.True(result.First() == digit); }
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); }
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)); }
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); } } }
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); }
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); }
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); }
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)); }
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); }
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); }
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(); } } }
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)); }
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)); }
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)); } }
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); }
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); }
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(); } } }
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))); }
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); }