Commit aeb30d83 authored by csharptest's avatar csharptest Committed by rogerk

changes from review

parent ef4af57b
...@@ -8,46 +8,44 @@ package protobuf_unittest_extra; ...@@ -8,46 +8,44 @@ package protobuf_unittest_extra;
option optimize_for = SPEED; option optimize_for = SPEED;
enum EnumOptions { enum EnumOptions {
ONE = 0; ONE = 0;
TWO = 1; TWO = 1;
THREE = 2; THREE = 2;
} }
message TestXmlChild message TestXmlChild {
{ repeated EnumOptions options = 3;
repeated EnumOptions options = 3; optional bytes binary = 4;
optional bytes binary = 4;
} }
message TestXmlNoFields { message TestXmlNoFields {
} }
message TestXmlRescursive { message TestXmlRescursive {
optional TestXmlRescursive child = 1; optional TestXmlRescursive child = 1;
} }
message TestXmlMessage { message TestXmlMessage {
optional int64 number = 6; optional int64 number = 6;
repeated int32 numbers = 2; repeated int32 numbers = 2;
optional string text = 3; optional string text = 3;
repeated string textlines = 700; repeated string textlines = 700;
optional bool valid = 5; optional bool valid = 5;
optional TestXmlChild child = 1; optional TestXmlChild child = 1;
repeated group Children = 401 repeated group Children = 401 {
{ repeated EnumOptions options = 3;
repeated EnumOptions options = 3; optional bytes binary = 4;
optional bytes binary = 4; }
}
extensions 100 to 199;
extensions 100 to 199;
} }
message TestXmlExtension { message TestXmlExtension {
required int32 number = 1; required int32 number = 1;
} }
extend TestXmlMessage { extend TestXmlMessage {
optional EnumOptions extension_enum = 101; optional EnumOptions extension_enum = 101;
optional string extension_text = 102; optional string extension_text = 102;
......
...@@ -31,9 +31,15 @@ namespace Google.ProtocolBuffers ...@@ -31,9 +31,15 @@ namespace Google.ProtocolBuffers
.AddNumbers(1) .AddNumbers(1)
.AddNumbers(2) .AddNumbers(2)
.AddNumbers(3) .AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) .SetChild(TestXmlChild.CreateBuilder()
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) .AddOptions(EnumOptions.ONE)
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) .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(); .Build();
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
...@@ -58,9 +64,15 @@ namespace Google.ProtocolBuffers ...@@ -58,9 +64,15 @@ namespace Google.ProtocolBuffers
.AddNumbers(1) .AddNumbers(1)
.AddNumbers(2) .AddNumbers(2)
.AddNumbers(3) .AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) .SetChild(TestXmlChild.CreateBuilder()
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) .AddOptions(EnumOptions.ONE)
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) .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.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
...@@ -97,9 +109,15 @@ namespace Google.ProtocolBuffers ...@@ -97,9 +109,15 @@ namespace Google.ProtocolBuffers
.AddNumbers(1) .AddNumbers(1)
.AddNumbers(2) .AddNumbers(2)
.AddNumbers(3) .AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) .SetChild(TestXmlChild.CreateBuilder()
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) .AddOptions(EnumOptions.ONE)
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) .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(); MemoryStream ms = new MemoryStream();
...@@ -124,9 +142,15 @@ namespace Google.ProtocolBuffers ...@@ -124,9 +142,15 @@ namespace Google.ProtocolBuffers
.AddNumbers(1) .AddNumbers(1)
.AddNumbers(2) .AddNumbers(2)
.AddNumbers(3) .AddNumbers(3)
.SetChild(TestXmlChild.CreateBuilder().AddOptions(EnumOptions.ONE).SetBinary(ByteString.CopyFrom(new byte[1]))) .SetChild(TestXmlChild.CreateBuilder()
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.TWO).SetBinary(ByteString.CopyFrom(new byte[2]))) .AddOptions(EnumOptions.ONE)
.AddChildren(TestXmlMessage.Types.Children.CreateBuilder().AddOptions(EnumOptions.THREE).SetBinary(ByteString.CopyFrom(new byte[3]))) .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.ExtensionText, " extension text value ! ")
.SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build()) .SetExtension(UnitTestXmlSerializerTestProtoFile.ExtensionMessage, new TestXmlExtension.Builder().SetNumber(42).Build())
.AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100) .AddExtension(UnitTestXmlSerializerTestProtoFile.ExtensionNumber, 100)
......
...@@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers ...@@ -45,7 +45,7 @@ namespace Google.ProtocolBuffers
{ {
/* /*
* Specialized handing of *all* message types. Messages are serialized into a byte[] and stored * 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. * deserialization. IDeserializationCallback is supported on both the Builder and Message.
*/ */
[Serializable] [Serializable]
...@@ -71,22 +71,23 @@ namespace Google.ProtocolBuffers ...@@ -71,22 +71,23 @@ namespace Google.ProtocolBuffers
_initialized = info.GetBoolean("initialized"); _initialized = info.GetBoolean("initialized");
} }
Object IObjectReference.GetRealObject(StreamingContext context) object IObjectReference.GetRealObject(StreamingContext context)
{ {
ExtensionRegistry registry = context.Context as ExtensionRegistry; ExtensionRegistry registry = context.Context as ExtensionRegistry;
TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType(); TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType();
builder.MergeFrom(_message, registry ?? ExtensionRegistry.Empty); 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(); TMessage message = _initialized ? builder.Build() : builder.BuildPartial();
callback = message as IDeserializationCallback;
if (message is IDeserializationCallback) if (callback != null)
{ {
((IDeserializationCallback) message).OnDeserialization(context); callback.OnDeserialization(context);
} }
return message; return message;
...@@ -119,15 +120,16 @@ namespace Google.ProtocolBuffers ...@@ -119,15 +120,16 @@ namespace Google.ProtocolBuffers
_message = (byte[])info.GetValue("message", typeof(byte[])); _message = (byte[])info.GetValue("message", typeof(byte[]));
} }
Object IObjectReference.GetRealObject(StreamingContext context) object IObjectReference.GetRealObject(StreamingContext context)
{ {
ExtensionRegistry registry = context.Context as ExtensionRegistry; ExtensionRegistry registry = context.Context as ExtensionRegistry;
TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType(); TBuilder builder = TemplateInstance.DefaultInstanceForType.CreateBuilderForType();
builder.MergeFrom(_message, registry ?? ExtensionRegistry.Empty); 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; return builder;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment