public void WriteWholePackedFieldsMessage()
        {
            TestPackedTypes message = TestUtil.GetPackedSet();

            byte[] rawBytes = message.ToByteArray();
            TestUtil.AssertEqualBytes(TestUtil.GetGoldenPackedFieldsMessage().ToByteArray(),
                                      rawBytes);
        }
        public void WriteWholeMessage()
        {
            TestAllTypes message = TestUtil.GetAllSet();

            byte[] rawBytes = message.ToByteArray();
            TestUtil.AssertEqualBytes(TestUtil.GoldenMessage.ToByteArray(), rawBytes);

            // Try different block sizes.
            for (int blockSize = 1; blockSize < 256; blockSize *= 2)
            {
                MemoryStream      rawOutput = new MemoryStream();
                CodedOutputStream output    =
                    CodedOutputStream.CreateInstance(rawOutput, blockSize);
                message.WriteTo(output);
                output.Flush();
                TestUtil.AssertEqualBytes(rawBytes, rawOutput.ToArray());
            }
        }
        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);
        }