public async Task DeserializeAsync_ResultBufferMatchesExpected(int totItems, int totThreads, int maxQueuedItems) { var cfg = GetConfig(totThreads, maxQueuedItems); TestItemPB[] originalArray = new TestItemPB[totItems]; for (int f = 0; f < totItems; f++) { originalArray[f] = new TestItemPB() { f = (byte)(f % 32) } } ; MemoryStream msOrig = new MemoryStream(); for (int i = 0; i < originalArray.Length; i++) { TestItemPB item = originalArray[i]; Serializer.SerializeWithLengthPrefix(msOrig, item, ProtoBuf.PrefixStyle.Base128, 1); } List <TestItemPB> newArray = new List <TestItemPB>(); var msPB = new MemoryStream(msOrig.ToArray()); using (var ds = new CollectionDeserializerAsync <TestItemPB>(cfg)) await foreach (TestItemPB item in ds.DeserializeAsync(msPB)) { newArray.Add(item); } Assert.AreEqual(originalArray.Select(t => t.f).ToArray(), newArray.Select(t => t.f).ToArray()); }
public async Task SerializeAsync_ResultBufferMatchesExpected(int totItems, int totThreads, int maxQueuedItems) { var cfg = GetConfig(totThreads, maxQueuedItems); TestItemPB[] originalArray = new TestItemPB[totItems]; List <TestItemPB> deserializedArray = new List <TestItemPB>(); for (int f = 0; f < totItems; f++) { originalArray[f] = new TestItemPB() { f = (byte)(1 + f % 32) } } ; MemoryStream ms = new MemoryStream(); await using (var ser = new CollectionSerializerAsync <TestItemPB>(ms, cfg)) foreach (var item in originalArray) { await ser.SerializeAsync(item, CancellationToken.None); } using (var msPB = new MemoryStream(ms.ToArray())) { while (true) { var obj = ProtoBuf.Serializer.DeserializeWithLengthPrefix <TestItemPB>(msPB, ProtoBuf.PrefixStyle.Base128, 1); if (obj is null) { break; } deserializedArray.Add(obj); } } Assert.AreEqual(originalArray.Select(f => f.f).ToArray(), deserializedArray.Select(t => t.f).ToArray()); }