public void ManyMessagesShouldNotTriggerSizeAlert() { int messageSize = TestUtil.GetAllSet().SerializedSize; // Enough messages to trigger the alert unless we've reset the size // Note that currently we need to make this big enough to copy two whole buffers, // as otherwise when we refill the buffer the second type, the alert triggers instantly. int correctCount = (CodedInputStream.BufferSize * 2) / messageSize + 1; using (MemoryStream stream = new MemoryStream()) { MessageStreamWriter <TestAllTypes> writer = new MessageStreamWriter <TestAllTypes>(stream); for (int i = 0; i < correctCount; i++) { writer.Write(TestUtil.GetAllSet()); } writer.Flush(); stream.Position = 0; int count = 0; foreach (var message in MessageStreamIterator <TestAllTypes> .FromStreamProvider(() => stream) .WithSizeLimit(CodedInputStream.BufferSize * 2)) { count++; TestUtil.AssertAllFieldsSet(message); } Assert.AreEqual(correctCount, count); } }
public void ThreeMessages() { NestedMessage message1 = new NestedMessage.Builder { Bb = 5 }.Build(); NestedMessage message2 = new NestedMessage.Builder { Bb = 1500 }.Build(); NestedMessage message3 = new NestedMessage.Builder().Build(); byte[] data; using (MemoryStream stream = new MemoryStream()) { MessageStreamWriter <NestedMessage> writer = new MessageStreamWriter <NestedMessage>(stream); writer.Write(message1); writer.Write(message2); writer.Write(message3); writer.Flush(); data = stream.ToArray(); } TestUtil.AssertEqualBytes(ThreeMessageData, data); }