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

changes from review

parent ef4af57b
......@@ -13,8 +13,7 @@ enum EnumOptions {
THREE = 2;
}
message TestXmlChild
{
message TestXmlChild {
repeated EnumOptions options = 3;
optional bytes binary = 4;
}
......@@ -35,13 +34,12 @@ message TestXmlMessage {
optional bool valid = 5;
optional TestXmlChild child = 1;
repeated group Children = 401
{
repeated group Children = 401 {
repeated EnumOptions options = 3;
optional bytes binary = 4;
}
extensions 100 to 199;
extensions 100 to 199;
}
message TestXmlExtension {
......
......@@ -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)
......
......@@ -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;
......
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