コード例 #1
0
        public void ReadHugeBlob()
        {
            // Allocate and initialize a 1MB blob.
            byte[] blob = new byte[1 << 20];
            for (int i = 0; i < blob.Length; i++)
            {
                blob[i] = (byte)i;
            }

            // Make a message containing it.
            TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
            TestUtil.SetAllFields(builder);
            builder.SetOptionalBytes(ByteString.CopyFrom(blob));
            TestAllTypes message = builder.Build();

            // Serialize and parse it.  Make sure to parse from an InputStream, not
            // directly from a ByteString, so that CodedInputStream uses buffered
            // reading.
            TestAllTypes message2 = TestAllTypes.ParseFrom(message.ToByteString().CreateCodedInput());

            Assert.AreEqual(message.OptionalBytes, message2.OptionalBytes);

            // Make sure all the other fields were parsed correctly.
            TestAllTypes message3 = TestAllTypes.CreateBuilder(message2)
                                    .SetOptionalBytes(TestUtil.GetAllSet().OptionalBytes)
                                    .Build();

            TestUtil.AssertAllFieldsSet(message3);
        }
 public void SetUp()
 {
     descriptor    = TestAllTypes.Descriptor;
     allFields     = TestUtil.GetAllSet();
     allFieldsData = allFields.ToByteString();
     emptyMessage  = TestEmptyMessage.ParseFrom(allFieldsData);
     unknownFields = emptyMessage.UnknownFields;
 }
コード例 #3
0
 public UnknownFieldSetTest()
 {
     descriptor = TestAllTypes.Descriptor;
     allFields = TestUtil.GetAllSet();
     allFieldsData = allFields.ToByteString();
     emptyMessage = TestEmptyMessage.ParseFrom(allFieldsData);
     unknownFields = emptyMessage.UnknownFields;
 }
コード例 #4
0
        public void DynamicMessageParsing()
        {
            TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
            TestUtil.SetAllFields(builder);
            TestAllTypes message = builder.Build();

            ByteString rawBytes = message.ToByteString();

            IMessage message2 = DynamicMessage.ParseFrom(TestAllTypes.Descriptor, rawBytes);

            reflectionTester.AssertAllFieldsSetViaReflection(message2);
        }
コード例 #5
0
        public void Serialization()
        {
            TestAllTypes message = TestUtil.GetAllSet();

            ByteString rawBytes = message.ToByteString();

            Assert.AreEqual(rawBytes.Length, message.SerializedSize);

            TestAllTypes message2 = TestAllTypes.ParseFrom(rawBytes);

            TestUtil.AssertAllFieldsSet(message2);
        }
コード例 #6
0
        public void ParseExtensions()
        {
            // TestAllTypes and TestAllExtensions should have compatible wire formats,
            // so if we serealize a TestAllTypes then parse it as TestAllExtensions
            // it should work.

            TestAllTypes message  = TestUtil.GetAllSet();
            ByteString   rawBytes = message.ToByteString();

            ExtensionRegistry registry = ExtensionRegistry.CreateInstance();

            TestUtil.RegisterAllExtensions(registry);
            registry = registry.AsReadOnly();

            TestAllExtensions message2 = TestAllExtensions.ParseFrom(rawBytes, registry);

            TestUtil.AssertAllExtensionsSet(message2);
        }
コード例 #7
0
        public void ReadHugeBlob()
        {
            // Allocate and initialize a 1MB blob.
            byte[] blob = new byte[1 << 20];
            for (int i = 0; i < blob.Length; i++)
            {
                blob[i] = (byte)i;
            }

            // Make a message containing it.
            var message = new TestAllTypes {
                SingleBytes = ByteString.CopyFrom(blob)
            };

            // Serialize and parse it.  Make sure to parse from an InputStream, not
            // directly from a ByteString, so that CodedInputStream uses buffered
            // reading.
            TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(message.ToByteString());

            Assert.AreEqual(message, message2);
        }
コード例 #8
0
        public void ReadHugeBlob()
        {
            // Allocate and initialize a 1MB blob.
            byte[] blob = new byte[1 << 20];
            for (int i = 0; i < blob.Length; i++)
            {
                blob[i] = (byte) i;
            }

            // Make a message containing it.
            var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) };

            // Serialize and parse it.  Make sure to parse from an InputStream, not
            // directly from a ByteString, so that CodedInputStream uses buffered
            // reading.
            TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(message.ToByteString());

            Assert.AreEqual(message, message2);
        }