public void PackedParsingOfUnpackedInput()
        {
            byte[]          bytes   = TestUnpackedTypes.ParseFrom(TestUtil.GetPackedSet().ToByteArray()).ToByteArray();
            TestPackedTypes message = TestPackedTypes.ParseFrom(bytes);

            TestUtil.AssertPackedFieldsSet(message);
        }
        public void PackedParsing()
        {
            AbstractMessageWrapper.Builder builder = new AbstractMessageWrapper.Builder(TestPackedTypes.CreateBuilder());
            AbstractMessageWrapper         message = builder.MergeFrom(TestUtil.GetPackedSet().ToByteString()).Build();

            TestUtil.AssertPackedFieldsSet((TestPackedTypes)message.WrappedMessage);
        }
        public void PackedSerialization()
        {
            IMessage abstractMessage = new AbstractMessageWrapper(TestUtil.GetPackedSet());

            TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseFrom(abstractMessage.ToByteString()));
            Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), abstractMessage.ToByteString());
        }
Exemplo n.º 4
0
        public void SerializationPacked()
        {
            TestPackedTypes message  = TestUtil.GetPackedSet();
            ByteString      rawBytes = message.ToByteString();

            Assert.AreEqual(rawBytes.Length, message.SerializedSize);
            TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes);

            TestUtil.AssertPackedFieldsSet(message2);
        }
Exemplo n.º 5
0
        public void DynamicMessagePackedSerialization()
        {
            IBuilder builder = DynamicMessage.CreateBuilder(TestPackedTypes.Descriptor);

            packedReflectionTester.SetPackedFieldsViaReflection(builder);
            IMessage message = builder.WeakBuild();

            ByteString      rawBytes = message.ToByteString();
            TestPackedTypes message2 = TestPackedTypes.ParseFrom(rawBytes);

            TestUtil.AssertPackedFieldsSet(message2);

            // In fact, the serialized forms should be exactly the same, byte-for-byte.
            Assert.AreEqual(TestUtil.GetPackedSet().ToByteString(), rawBytes);
        }
Exemplo n.º 6
0
        public void SerializeDelimited()
        {
            MemoryStream stream = new MemoryStream();

            TestUtil.GetAllSet().WriteDelimitedTo(stream);
            stream.WriteByte(12);
            TestUtil.GetPackedSet().WriteDelimitedTo(stream);
            stream.WriteByte(34);

            stream.Position = 0;

            TestUtil.AssertAllFieldsSet(TestAllTypes.ParseDelimitedFrom(stream));
            Assert.AreEqual(12, stream.ReadByte());
            TestUtil.AssertPackedFieldsSet(TestPackedTypes.ParseDelimitedFrom(stream));
            Assert.AreEqual(34, stream.ReadByte());
            Assert.AreEqual(-1, stream.ReadByte());
        }