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; }
public UnknownFieldSetTest() { descriptor = TestAllTypes.Descriptor; allFields = TestUtil.GetAllSet(); allFieldsData = allFields.ToByteString(); emptyMessage = TestEmptyMessage.ParseFrom(allFieldsData); unknownFields = emptyMessage.UnknownFields; }
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); }
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); }
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); }
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); }
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); }