diff --git a/protos/extest/unittest_extras_xmltest.proto b/protos/extest/unittest_extras_xmltest.proto index 7fc4e3a2e9..ab8088a76b 100644 --- a/protos/extest/unittest_extras_xmltest.proto +++ b/protos/extest/unittest_extras_xmltest.proto @@ -8,46 +8,44 @@ package protobuf_unittest_extra; option optimize_for = SPEED; enum EnumOptions { - ONE = 0; - TWO = 1; - THREE = 2; + ONE = 0; + TWO = 1; + THREE = 2; } -message TestXmlChild -{ - repeated EnumOptions options = 3; - optional bytes binary = 4; +message TestXmlChild { + repeated EnumOptions options = 3; + optional bytes binary = 4; } message TestXmlNoFields { } message TestXmlRescursive { - optional TestXmlRescursive child = 1; + optional TestXmlRescursive child = 1; } message TestXmlMessage { - optional int64 number = 6; - repeated int32 numbers = 2; - optional string text = 3; - repeated string textlines = 700; - optional bool valid = 5; - - optional TestXmlChild child = 1; - repeated group Children = 401 - { - repeated EnumOptions options = 3; - optional bytes binary = 4; - } - - extensions 100 to 199; + optional int64 number = 6; + repeated int32 numbers = 2; + optional string text = 3; + repeated string textlines = 700; + optional bool valid = 5; + + optional TestXmlChild child = 1; + repeated group Children = 401 { + repeated EnumOptions options = 3; + optional bytes binary = 4; + } + +extensions 100 to 199; } message TestXmlExtension { required int32 number = 1; } - + extend TestXmlMessage { optional EnumOptions extension_enum = 101; optional string extension_text = 102; diff --git a/src/ProtocolBuffers.Test/SerializableTest.cs b/src/ProtocolBuffers.Test/SerializableTest.cs index 701cfc6b0f..f1073c1e45 100644 --- a/src/ProtocolBuffers.Test/SerializableTest.cs +++ b/src/ProtocolBuffers.Test/SerializableTest.cs @@ -31,9 +31,15 @@ namespace Google.ProtocolBuffers .AddNumbers(1) .AddNumbers(2) .AddNumbers(3) - .SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) + .SetChild(TestXmlChild.CreateBuilder() + .AddOptions(EnumOptions.ONE) + .SetBinary(ByteString.CopyFrom(new byte[1]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.TWO) + .SetBinary(ByteString.CopyFrom(new byte[2]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.THREE) + .SetBinary(ByteString.CopyFrom(new byte[3]))) .Build(); MemoryStream ms = new MemoryStream(); @@ -58,9 +64,15 @@ namespace Google.ProtocolBuffers .AddNumbers(1) .AddNumbers(2) .AddNumbers(3) - .SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) + .SetChild(TestXmlChild.CreateBuilder() + .AddOptions(EnumOptions.ONE) + .SetBinary(ByteString.CopyFrom(new byte[1]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.TWO) + .SetBinary(ByteString.CopyFrom(new byte[2]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.THREE) + .SetBinary(ByteString.CopyFrom(new byte[3]))) .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) @@ -97,9 +109,15 @@ namespace Google.ProtocolBuffers .AddNumbers(1) .AddNumbers(2) .AddNumbers(3) - .SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) + .SetChild(TestXmlChild.CreateBuilder() + .AddOptions(EnumOptions.ONE) + .SetBinary(ByteString.CopyFrom(new byte[1]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.TWO) + .SetBinary(ByteString.CopyFrom(new byte[2]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.THREE) + .SetBinary(ByteString.CopyFrom(new byte[3]))) ; MemoryStream ms = new MemoryStream(); @@ -124,9 +142,15 @@ namespace Google.ProtocolBuffers .AddNumbers(1) .AddNumbers(2) .AddNumbers(3) - .SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) - .AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) + .SetChild(TestXmlChild.CreateBuilder() + .AddOptions(EnumOptions.ONE) + .SetBinary(ByteString.CopyFrom(new byte[1]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.TWO) + .SetBinary(ByteString.CopyFrom(new byte[2]))) + .AddChildren(TestXmlMessage.Types.Children.CreateBuilder() + .AddOptions(EnumOptions.THREE) + .SetBinary(ByteString.CopyFrom(new byte[3]))) .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionText, " extension text value ! ") .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) diff --git a/src/ProtocolBuffers/CustomSerialization.cs b/src/ProtocolBuffers/CustomSerialization.cs index 940d3c80d1..5af673add8 100644 --- a/src/ProtocolBuffers/CustomSerialization.cs +++ b/src/ProtocolBuffers/CustomSerialization.cs @@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers { /* * Specialized handing of *all* message types. Messages are serialized into a byte[] and stored - * into the SerializationInfo, they are then reconstituded by an IObjectReference class after + * into the SerializationInfo, and are then reconstituted by an IObjectReference class after * deserialization. IDeserializationCallback is supported on both the Builder and Message. */ [Serializable] @@ -71,22 +71,23 @@ namespace Google.ProtocolBuffers _initialized = info.GetBoolean("initialized"); } - Object IObjectReference.GetRealObject(StreamingContext context) + object IObjectReference.GetRealObject(StreamingContext context) { ExtensionRegistry registry = context.Context as ExtensionRegistry; TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType(); builder.MergeFrom(_message, registry ?? ExtensionRegistry.Empty); - if (builder is IDeserializationCallback) + IDeserializationCallback callback = builder as IDeserializationCallback; + if(callback != null) { - ((IDeserializationCallback) builder).OnDeserialization(context); + callback.OnDeserialization(context); } TMessage message = _initialized ? builder.Build() : builder.BuildPartial(); - - if (message is IDeserializationCallback) + callback = message as IDeserializationCallback; + if (callback != null) { - ((IDeserializationCallback) message).OnDeserialization(context); + callback.OnDeserialization(context); } return message; @@ -119,15 +120,16 @@ namespace Google.ProtocolBuffers _message = (byte[])info.GetValue("message", typeof(byte[])); } - Object IObjectReference.GetRealObject(StreamingContext context) + object IObjectReference.GetRealObject(StreamingContext context) { ExtensionRegistry registry = context.Context as ExtensionRegistry; TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType(); builder.MergeFrom(_message, registry ?? ExtensionRegistry.Empty); - if (builder is IDeserializationCallback) + IDeserializationCallback callback = builder as IDeserializationCallback; + if(callback != null) { - ((IDeserializationCallback) builder).OnDeserialization(context); + callback.OnDeserialization(context); } return builder;