public void TestInt32() { var rnd = new System.Random(); for (var c = 0; c < count; c++) { var mem = new byte[sizeof(Int32) * writeRepeatCount]; var span1 = new MemoryStreamer(mem); var span2 = new MemoryStreamer(mem); var a = new Int32[writeRepeatCount]; for (var i = 0; i < writeRepeatCount; i++) { var n = rnd.NextInt32(); a[i] = n; span1.Write(n); } for (var i = 0; i < writeRepeatCount; i++) { var r = span2.ReadInt32(); Assert.Equal(a[i], r); } } }
public void TestSizedReadWriteSpan() { var rnd = new Random(); for (var c = 0; c < count; c++) { var memSize = rnd.Next(1, 10_000); var mem = new byte[(memSize + 4) * writeRepeatCount]; var answer = new byte[memSize * writeRepeatCount]; rnd.NextBytes(answer); var span1 = new MemoryStreamer(mem); var span2 = new MemoryStreamer(mem); span1.WriteSized(new Span <byte>(answer)); span1.Write(1234); var bytes = span2.ReadSizedBytes(out var length); Assert.Equal(answer, bytes); Assert.Equal(1234, span2.ReadInt32()); } }