commit
adfdc00891
30 changed files with 7989 additions and 3026 deletions
Binary file not shown.
@ -0,0 +1,37 @@ |
||||
// Additional options required for C# generation. File from copyright |
||||
// line onwards is as per original distribution. |
||||
import "google/protobuf/csharp_options.proto"; |
||||
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; |
||||
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestExtrasProtoFile"; |
||||
option (google.protobuf.csharp_file_options).add_serializable = true; |
||||
|
||||
package protobuf_unittest_extra; |
||||
|
||||
option java_package = "com.google.protobuf"; |
||||
|
||||
message TestUnpackedExtensions { |
||||
extensions 1 to max; |
||||
} |
||||
|
||||
extend TestUnpackedExtensions { |
||||
repeated int32 unpacked_int32_extension = 90; |
||||
repeated int64 unpacked_int64_extension = 91; |
||||
repeated uint32 unpacked_uint32_extension = 92; |
||||
repeated uint64 unpacked_uint64_extension = 93; |
||||
repeated sint32 unpacked_sint32_extension = 94; |
||||
repeated sint64 unpacked_sint64_extension = 95; |
||||
repeated fixed32 unpacked_fixed32_extension = 96; |
||||
repeated fixed64 unpacked_fixed64_extension = 97; |
||||
repeated sfixed32 unpacked_sfixed32_extension = 98; |
||||
repeated sfixed64 unpacked_sfixed64_extension = 99; |
||||
repeated float unpacked_float_extension = 100; |
||||
repeated double unpacked_double_extension = 101; |
||||
repeated bool unpacked_bool_extension = 102; |
||||
repeated UnpackedExtensionsForeignEnum unpacked_enum_extension = 103; |
||||
} |
||||
|
||||
enum UnpackedExtensionsForeignEnum { |
||||
FOREIGN_FOO = 4; |
||||
FOREIGN_BAR = 5; |
||||
FOREIGN_BAZ = 6; |
||||
} |
@ -0,0 +1,35 @@ |
||||
// Additional options required for C# generation. File from copyright |
||||
// line onwards is as per original distribution. |
||||
import "google/protobuf/csharp_options.proto"; |
||||
option (google.protobuf.csharp_file_options).namespace = "Google.ProtocolBuffers.TestProtos"; |
||||
option (google.protobuf.csharp_file_options).umbrella_classname = "UnitTestRpcInteropLite"; |
||||
|
||||
option (google.protobuf.csharp_file_options).service_generator_type = IRPCDISPATCH; |
||||
|
||||
option optimize_for = LITE_RUNTIME; |
||||
package unittest_rpc_interop_lite; |
||||
|
||||
message SearchRequest { |
||||
repeated string Criteria = 1; |
||||
} |
||||
|
||||
message SearchResponse { |
||||
message ResultItem { |
||||
required string url = 1; |
||||
optional string name = 2; |
||||
} |
||||
|
||||
repeated ResultItem results = 1; |
||||
} |
||||
|
||||
message RefineSearchRequest { |
||||
repeated string Criteria = 1; |
||||
required SearchResponse previous_results = 2; |
||||
} |
||||
|
||||
service SearchService { |
||||
option (google.protobuf.csharp_service_options).interface_id = "{A65F0925-FD11-4f94-B166-89AC4F027205}"; |
||||
rpc Search (SearchRequest) returns (SearchResponse) { option (google.protobuf.csharp_method_options).dispatch_id = 5; }; |
||||
|
||||
rpc RefineSearch (RefineSearchRequest) returns (SearchResponse); |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,403 @@ |
||||
// Generated by ProtoGen, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48. DO NOT EDIT! |
||||
#pragma warning disable 1591, 0612 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.ProtocolBuffers; |
||||
using pbc = global::Google.ProtocolBuffers.Collections; |
||||
using pbd = global::Google.ProtocolBuffers.Descriptors; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Google.ProtocolBuffers.TestProtos { |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] |
||||
public static partial class UnitTestExtrasProtoFile { |
||||
|
||||
#region Extension registration |
||||
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) { |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedInt32Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedInt64Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedUint32Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedUint64Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSint32Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSint64Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFixed32Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFixed64Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSfixed32Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSfixed64Extension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFloatExtension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedDoubleExtension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedBoolExtension); |
||||
registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedEnumExtension); |
||||
} |
||||
#endregion |
||||
#region Extensions |
||||
public const int UnpackedInt32ExtensionFieldNumber = 90; |
||||
public static pb::GeneratedExtensionBase<scg::IList<int>> UnpackedInt32Extension; |
||||
public const int UnpackedInt64ExtensionFieldNumber = 91; |
||||
public static pb::GeneratedExtensionBase<scg::IList<long>> UnpackedInt64Extension; |
||||
public const int UnpackedUint32ExtensionFieldNumber = 92; |
||||
[global::System.CLSCompliant(false)] |
||||
public static pb::GeneratedExtensionBase<scg::IList<uint>> UnpackedUint32Extension; |
||||
public const int UnpackedUint64ExtensionFieldNumber = 93; |
||||
[global::System.CLSCompliant(false)] |
||||
public static pb::GeneratedExtensionBase<scg::IList<ulong>> UnpackedUint64Extension; |
||||
public const int UnpackedSint32ExtensionFieldNumber = 94; |
||||
public static pb::GeneratedExtensionBase<scg::IList<int>> UnpackedSint32Extension; |
||||
public const int UnpackedSint64ExtensionFieldNumber = 95; |
||||
public static pb::GeneratedExtensionBase<scg::IList<long>> UnpackedSint64Extension; |
||||
public const int UnpackedFixed32ExtensionFieldNumber = 96; |
||||
[global::System.CLSCompliant(false)] |
||||
public static pb::GeneratedExtensionBase<scg::IList<uint>> UnpackedFixed32Extension; |
||||
public const int UnpackedFixed64ExtensionFieldNumber = 97; |
||||
[global::System.CLSCompliant(false)] |
||||
public static pb::GeneratedExtensionBase<scg::IList<ulong>> UnpackedFixed64Extension; |
||||
public const int UnpackedSfixed32ExtensionFieldNumber = 98; |
||||
public static pb::GeneratedExtensionBase<scg::IList<int>> UnpackedSfixed32Extension; |
||||
public const int UnpackedSfixed64ExtensionFieldNumber = 99; |
||||
public static pb::GeneratedExtensionBase<scg::IList<long>> UnpackedSfixed64Extension; |
||||
public const int UnpackedFloatExtensionFieldNumber = 100; |
||||
public static pb::GeneratedExtensionBase<scg::IList<float>> UnpackedFloatExtension; |
||||
public const int UnpackedDoubleExtensionFieldNumber = 101; |
||||
public static pb::GeneratedExtensionBase<scg::IList<double>> UnpackedDoubleExtension; |
||||
public const int UnpackedBoolExtensionFieldNumber = 102; |
||||
public static pb::GeneratedExtensionBase<scg::IList<bool>> UnpackedBoolExtension; |
||||
public const int UnpackedEnumExtensionFieldNumber = 103; |
||||
public static pb::GeneratedExtensionBase<scg::IList<global::Google.ProtocolBuffers.TestProtos.UnpackedExtensionsForeignEnum>> UnpackedEnumExtension; |
||||
#endregion |
||||
|
||||
#region Static variables |
||||
internal static pbd::MessageDescriptor internal__static_protobuf_unittest_extra_TestUnpackedExtensions__Descriptor; |
||||
internal static pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions, global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.Builder> internal__static_protobuf_unittest_extra_TestUnpackedExtensions__FieldAccessorTable; |
||||
#endregion |
||||
#region Descriptor |
||||
public static pbd::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbd::FileDescriptor descriptor; |
||||
|
||||
static UnitTestExtrasProtoFile() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
"ChxleHRlc3QvdW5pdHRlc3RfZXh0cmFzLnByb3RvEhdwcm90b2J1Zl91bml0" + |
||||
"dGVzdF9leHRyYRokZ29vZ2xlL3Byb3RvYnVmL2NzaGFycF9vcHRpb25zLnBy" + |
||||
"b3RvIiIKFlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMqCAgBEICAgIACKlIKHVVu" + |
||||
"cGFja2VkRXh0ZW5zaW9uc0ZvcmVpZ25FbnVtEg8KC0ZPUkVJR05fRk9PEAQS" + |
||||
"DwoLRk9SRUlHTl9CQVIQBRIPCgtGT1JFSUdOX0JBWhAGOlEKGHVucGFja2Vk" + |
||||
"X2ludDMyX2V4dGVuc2lvbhIvLnByb3RvYnVmX3VuaXR0ZXN0X2V4dHJhLlRl" + |
||||
"c3RVbnBhY2tlZEV4dGVuc2lvbnMYWiADKAU6UQoYdW5wYWNrZWRfaW50NjRf" + |
||||
"ZXh0ZW5zaW9uEi8ucHJvdG9idWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVucGFj" + |
||||
"a2VkRXh0ZW5zaW9ucxhbIAMoAzpSChl1bnBhY2tlZF91aW50MzJfZXh0ZW5z" + |
||||
"aW9uEi8ucHJvdG9idWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVucGFja2VkRXh0" + |
||||
"ZW5zaW9ucxhcIAMoDTpSChl1bnBhY2tlZF91aW50NjRfZXh0ZW5zaW9uEi8u" + |
||||
"cHJvdG9idWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVucGFja2VkRXh0ZW5zaW9u" + |
||||
"cxhdIAMoBDpSChl1bnBhY2tlZF9zaW50MzJfZXh0ZW5zaW9uEi8ucHJvdG9i" + |
||||
"dWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxheIAMo" + |
||||
"ETpSChl1bnBhY2tlZF9zaW50NjRfZXh0ZW5zaW9uEi8ucHJvdG9idWZfdW5p" + |
||||
"dHRlc3RfZXh0cmEuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxhfIAMoEjpTChp1" + |
||||
"bnBhY2tlZF9maXhlZDMyX2V4dGVuc2lvbhIvLnByb3RvYnVmX3VuaXR0ZXN0" + |
||||
"X2V4dHJhLlRlc3RVbnBhY2tlZEV4dGVuc2lvbnMYYCADKAc6UwoadW5wYWNr" + |
||||
"ZWRfZml4ZWQ2NF9leHRlbnNpb24SLy5wcm90b2J1Zl91bml0dGVzdF9leHRy" + |
||||
"YS5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGGEgAygGOlQKG3VucGFja2VkX3Nm" + |
||||
"aXhlZDMyX2V4dGVuc2lvbhIvLnByb3RvYnVmX3VuaXR0ZXN0X2V4dHJhLlRl" + |
||||
"c3RVbnBhY2tlZEV4dGVuc2lvbnMYYiADKA86VAobdW5wYWNrZWRfc2ZpeGVk" + |
||||
"NjRfZXh0ZW5zaW9uEi8ucHJvdG9idWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVu" + |
||||
"cGFja2VkRXh0ZW5zaW9ucxhjIAMoEDpRChh1bnBhY2tlZF9mbG9hdF9leHRl" + |
||||
"bnNpb24SLy5wcm90b2J1Zl91bml0dGVzdF9leHRyYS5UZXN0VW5wYWNrZWRF" + |
||||
"eHRlbnNpb25zGGQgAygCOlIKGXVucGFja2VkX2RvdWJsZV9leHRlbnNpb24S" + |
||||
"Ly5wcm90b2J1Zl91bml0dGVzdF9leHRyYS5UZXN0VW5wYWNrZWRFeHRlbnNp" + |
||||
"b25zGGUgAygBOlAKF3VucGFja2VkX2Jvb2xfZXh0ZW5zaW9uEi8ucHJvdG9i" + |
||||
"dWZfdW5pdHRlc3RfZXh0cmEuVGVzdFVucGFja2VkRXh0ZW5zaW9ucxhmIAMo" + |
||||
"CDqIAQoXdW5wYWNrZWRfZW51bV9leHRlbnNpb24SLy5wcm90b2J1Zl91bml0" + |
||||
"dGVzdF9leHRyYS5UZXN0VW5wYWNrZWRFeHRlbnNpb25zGGcgAygOMjYucHJv" + |
||||
"dG9idWZfdW5pdHRlc3RfZXh0cmEuVW5wYWNrZWRFeHRlbnNpb25zRm9yZWln" + |
||||
"bkVudW1CVgoTY29tLmdvb2dsZS5wcm90b2J1ZsI+PgohR29vZ2xlLlByb3Rv" + |
||||
"Y29sQnVmZmVycy5UZXN0UHJvdG9zEhdVbml0VGVzdEV4dHJhc1Byb3RvRmls" + |
||||
"ZUgB"); |
||||
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { |
||||
descriptor = root; |
||||
internal__static_protobuf_unittest_extra_TestUnpackedExtensions__Descriptor = Descriptor.MessageTypes[0]; |
||||
internal__static_protobuf_unittest_extra_TestUnpackedExtensions__FieldAccessorTable = |
||||
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions, global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.Builder>(internal__static_protobuf_unittest_extra_TestUnpackedExtensions__Descriptor, |
||||
new string[] { }); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedInt32Extension = pb::GeneratedRepeatExtension<int>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[0]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedInt64Extension = pb::GeneratedRepeatExtension<long>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[1]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedUint32Extension = pb::GeneratedRepeatExtension<uint>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[2]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedUint64Extension = pb::GeneratedRepeatExtension<ulong>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[3]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSint32Extension = pb::GeneratedRepeatExtension<int>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[4]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSint64Extension = pb::GeneratedRepeatExtension<long>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[5]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFixed32Extension = pb::GeneratedRepeatExtension<uint>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[6]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFixed64Extension = pb::GeneratedRepeatExtension<ulong>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[7]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSfixed32Extension = pb::GeneratedRepeatExtension<int>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[8]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedSfixed64Extension = pb::GeneratedRepeatExtension<long>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[9]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedFloatExtension = pb::GeneratedRepeatExtension<float>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[10]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedDoubleExtension = pb::GeneratedRepeatExtension<double>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[11]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedBoolExtension = pb::GeneratedRepeatExtension<bool>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[12]); |
||||
global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.UnpackedEnumExtension = pb::GeneratedRepeatExtension<global::Google.ProtocolBuffers.TestProtos.UnpackedExtensionsForeignEnum>.CreateInstance(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor.Extensions[13]); |
||||
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance(); |
||||
RegisterAllExtensions(registry); |
||||
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry); |
||||
return registry; |
||||
}; |
||||
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, |
||||
new pbd::FileDescriptor[] { |
||||
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor, |
||||
}, assigner); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Enums |
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] |
||||
public enum UnpackedExtensionsForeignEnum { |
||||
FOREIGN_FOO = 4, |
||||
FOREIGN_BAR = 5, |
||||
FOREIGN_BAZ = 6, |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Messages |
||||
[global::System.SerializableAttribute()] |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] |
||||
public sealed partial class TestUnpackedExtensions : pb::ExtendableMessage<TestUnpackedExtensions, TestUnpackedExtensions.Builder> { |
||||
private TestUnpackedExtensions() { } |
||||
private static readonly TestUnpackedExtensions defaultInstance = new TestUnpackedExtensions().MakeReadOnly(); |
||||
private static readonly string[] _testUnpackedExtensionsFieldNames = new string[] { }; |
||||
private static readonly uint[] _testUnpackedExtensionsFieldTags = new uint[] { }; |
||||
public static TestUnpackedExtensions DefaultInstance { |
||||
get { return defaultInstance; } |
||||
} |
||||
|
||||
public override TestUnpackedExtensions DefaultInstanceForType { |
||||
get { return DefaultInstance; } |
||||
} |
||||
|
||||
protected override TestUnpackedExtensions ThisMessage { |
||||
get { return this; } |
||||
} |
||||
|
||||
public static pbd::MessageDescriptor Descriptor { |
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.internal__static_protobuf_unittest_extra_TestUnpackedExtensions__Descriptor; } |
||||
} |
||||
|
||||
protected override pb::FieldAccess.FieldAccessorTable<TestUnpackedExtensions, TestUnpackedExtensions.Builder> InternalFieldAccessors { |
||||
get { return global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.internal__static_protobuf_unittest_extra_TestUnpackedExtensions__FieldAccessorTable; } |
||||
} |
||||
|
||||
public override bool IsInitialized { |
||||
get { |
||||
if (!ExtensionsAreInitialized) return false; |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void WriteTo(pb::ICodedOutputStream output) { |
||||
int size = SerializedSize; |
||||
string[] field_names = _testUnpackedExtensionsFieldNames; |
||||
pb::ExtendableMessage<TestUnpackedExtensions, TestUnpackedExtensions.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this); |
||||
extensionWriter.WriteUntil(536870912, output); |
||||
UnknownFields.WriteTo(output); |
||||
} |
||||
|
||||
private int memoizedSerializedSize = -1; |
||||
public override int SerializedSize { |
||||
get { |
||||
int size = memoizedSerializedSize; |
||||
if (size != -1) return size; |
||||
|
||||
size = 0; |
||||
size += ExtensionsSerializedSize; |
||||
size += UnknownFields.SerializedSize; |
||||
memoizedSerializedSize = size; |
||||
return size; |
||||
} |
||||
} |
||||
|
||||
public static TestUnpackedExtensions ParseFrom(pb::ByteString data) { |
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { |
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(byte[] data) { |
||||
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { |
||||
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(global::System.IO.Stream input) { |
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { |
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseDelimitedFrom(global::System.IO.Stream input) { |
||||
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { |
||||
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(pb::ICodedInputStream input) { |
||||
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); |
||||
} |
||||
public static TestUnpackedExtensions ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { |
||||
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); |
||||
} |
||||
private TestUnpackedExtensions MakeReadOnly() { |
||||
return this; |
||||
} |
||||
|
||||
public static Builder CreateBuilder() { return new Builder(); } |
||||
public override Builder ToBuilder() { return CreateBuilder(this); } |
||||
public override Builder CreateBuilderForType() { return new Builder(); } |
||||
public static Builder CreateBuilder(TestUnpackedExtensions prototype) { |
||||
return new Builder(prototype); |
||||
} |
||||
|
||||
[global::System.SerializableAttribute()] |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] |
||||
public sealed partial class Builder : pb::ExtendableBuilder<TestUnpackedExtensions, Builder> { |
||||
protected override Builder ThisBuilder { |
||||
get { return this; } |
||||
} |
||||
public Builder() { |
||||
result = DefaultInstance; |
||||
resultIsReadOnly = true; |
||||
} |
||||
internal Builder(TestUnpackedExtensions cloneFrom) { |
||||
result = cloneFrom; |
||||
resultIsReadOnly = true; |
||||
} |
||||
|
||||
private bool resultIsReadOnly; |
||||
private TestUnpackedExtensions result; |
||||
|
||||
private TestUnpackedExtensions PrepareBuilder() { |
||||
if (resultIsReadOnly) { |
||||
TestUnpackedExtensions original = result; |
||||
result = new TestUnpackedExtensions(); |
||||
resultIsReadOnly = false; |
||||
MergeFrom(original); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
public override bool IsInitialized { |
||||
get { return result.IsInitialized; } |
||||
} |
||||
|
||||
protected override TestUnpackedExtensions MessageBeingBuilt { |
||||
get { return PrepareBuilder(); } |
||||
} |
||||
|
||||
public override Builder Clear() { |
||||
result = DefaultInstance; |
||||
resultIsReadOnly = true; |
||||
return this; |
||||
} |
||||
|
||||
public override Builder Clone() { |
||||
if (resultIsReadOnly) { |
||||
return new Builder(result); |
||||
} else { |
||||
return new Builder().MergeFrom(result); |
||||
} |
||||
} |
||||
|
||||
public override pbd::MessageDescriptor DescriptorForType { |
||||
get { return global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.Descriptor; } |
||||
} |
||||
|
||||
public override TestUnpackedExtensions DefaultInstanceForType { |
||||
get { return global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.DefaultInstance; } |
||||
} |
||||
|
||||
public override TestUnpackedExtensions BuildPartial() { |
||||
if (resultIsReadOnly) { |
||||
return result; |
||||
} |
||||
resultIsReadOnly = true; |
||||
return result.MakeReadOnly(); |
||||
} |
||||
|
||||
public override Builder MergeFrom(pb::IMessage other) { |
||||
if (other is TestUnpackedExtensions) { |
||||
return MergeFrom((TestUnpackedExtensions) other); |
||||
} else { |
||||
base.MergeFrom(other); |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
public override Builder MergeFrom(TestUnpackedExtensions other) { |
||||
if (other == global::Google.ProtocolBuffers.TestProtos.TestUnpackedExtensions.DefaultInstance) return this; |
||||
PrepareBuilder(); |
||||
this.MergeExtensionFields(other); |
||||
this.MergeUnknownFields(other.UnknownFields); |
||||
return this; |
||||
} |
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input) { |
||||
return MergeFrom(input, pb::ExtensionRegistry.Empty); |
||||
} |
||||
|
||||
public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { |
||||
PrepareBuilder(); |
||||
pb::UnknownFieldSet.Builder unknownFields = null; |
||||
uint tag; |
||||
string field_name; |
||||
while (input.ReadTag(out tag, out field_name)) { |
||||
if(tag == 0 && field_name != null) { |
||||
int field_ordinal = global::System.Array.BinarySearch(_testUnpackedExtensionsFieldNames, field_name, global::System.StringComparer.Ordinal); |
||||
if(field_ordinal >= 0) |
||||
tag = _testUnpackedExtensionsFieldTags[field_ordinal]; |
||||
else { |
||||
if (unknownFields == null) { |
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); |
||||
} |
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); |
||||
continue; |
||||
} |
||||
} |
||||
switch (tag) { |
||||
case 0: { |
||||
throw pb::InvalidProtocolBufferException.InvalidTag(); |
||||
} |
||||
default: { |
||||
if (pb::WireFormat.IsEndGroupTag(tag)) { |
||||
if (unknownFields != null) { |
||||
this.UnknownFields = unknownFields.Build(); |
||||
} |
||||
return this; |
||||
} |
||||
if (unknownFields == null) { |
||||
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); |
||||
} |
||||
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (unknownFields != null) { |
||||
this.UnknownFields = unknownFields.Build(); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
} |
||||
static TestUnpackedExtensions() { |
||||
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasProtoFile.Descriptor, null); |
||||
} |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,386 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// http://github.com/jskeet/dotnet-protobufs/ |
||||
// Original C++/Java/Python code: |
||||
// http://code.google.com/p/protobuf/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using Google.ProtocolBuffers; |
||||
using Google.ProtocolBuffers.Serialization.Http; |
||||
using Google.ProtocolBuffers.TestProtos; |
||||
using NUnit.Framework; |
||||
using System.IO; |
||||
using Google.ProtocolBuffers.Serialization; |
||||
using System.Text; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// This class verifies the correct code is generated from unittest_rpc_interop.proto and provides a small demonstration |
||||
/// of using the new IRpcDispatch to write a client/server |
||||
/// </summary> |
||||
[TestFixture] |
||||
public class TestRpcForMimeTypes |
||||
{ |
||||
/// <summary> |
||||
/// A sample implementation of the ISearchService for testing |
||||
/// </summary> |
||||
private class ExampleSearchImpl : ISearchService |
||||
{ |
||||
SearchResponse ISearchService.Search(SearchRequest searchRequest) |
||||
{ |
||||
if (searchRequest.CriteriaCount == 0) |
||||
{ |
||||
throw new ArgumentException("No criteria specified.", new InvalidOperationException()); |
||||
} |
||||
SearchResponse.Builder resp = SearchResponse.CreateBuilder(); |
||||
foreach (string criteria in searchRequest.CriteriaList) |
||||
{ |
||||
resp.AddResults( |
||||
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://search.com"). |
||||
Build()); |
||||
} |
||||
return resp.Build(); |
||||
} |
||||
|
||||
SearchResponse ISearchService.RefineSearch(RefineSearchRequest refineSearchRequest) |
||||
{ |
||||
SearchResponse.Builder resp = refineSearchRequest.PreviousResults.ToBuilder(); |
||||
foreach (string criteria in refineSearchRequest.CriteriaList) |
||||
{ |
||||
resp.AddResults( |
||||
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://refine.com"). |
||||
Build()); |
||||
} |
||||
return resp.Build(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example extraction of the wire protocol |
||||
/// </summary> |
||||
private interface IHttpTransfer |
||||
{ |
||||
void Execute(string method, string contentType, Stream input, string acceptType, Stream output); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example of a server responding to a web/http request |
||||
/// </summary> |
||||
private class ExampleHttpServer : IHttpTransfer |
||||
{ |
||||
public readonly MessageFormatOptions Options = |
||||
new MessageFormatOptions |
||||
{ |
||||
ExtensionRegistry = ExtensionRegistry.Empty, |
||||
FormattedOutput = true, |
||||
XmlReaderOptions = XmlReaderOptions.ReadNestedArrays, |
||||
XmlReaderRootElementName = "request", |
||||
XmlWriterOptions = XmlWriterOptions.OutputNestedArrays, |
||||
XmlWriterRootElementName = "response" |
||||
}; |
||||
|
||||
private readonly IRpcServerStub _stub; |
||||
|
||||
public ExampleHttpServer(ISearchService implementation) |
||||
{ |
||||
//on the server, we create a dispatch to call the appropriate method by name |
||||
IRpcDispatch dispatch = new SearchService.Dispatch(implementation); |
||||
//we then wrap that dispatch in a server stub which will deserialize the wire bytes to the message |
||||
//type appropriate for the method name being invoked. |
||||
_stub = new SearchService.ServerStub(dispatch); |
||||
} |
||||
|
||||
void IHttpTransfer.Execute(string method, string contentType, Stream input, string acceptType, Stream output) |
||||
{ |
||||
//Extension for: Google.ProtocolBuffers.Serialization.Http.ServiceExtensions.HttpCallMethod(_stub, |
||||
_stub.HttpCallMethod( |
||||
method, Options, |
||||
contentType, input, |
||||
acceptType, output |
||||
); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example of a client sending a wire request |
||||
/// </summary> |
||||
private class ExampleClient : IRpcDispatch |
||||
{ |
||||
public readonly MessageFormatOptions Options = |
||||
new MessageFormatOptions |
||||
{ |
||||
ExtensionRegistry = ExtensionRegistry.Empty, |
||||
FormattedOutput = true, |
||||
XmlReaderOptions = XmlReaderOptions.ReadNestedArrays, |
||||
XmlReaderRootElementName = "response", |
||||
XmlWriterOptions = XmlWriterOptions.OutputNestedArrays, |
||||
XmlWriterRootElementName = "request" |
||||
}; |
||||
|
||||
|
||||
private readonly IHttpTransfer _wire; |
||||
private readonly string _mimeType; |
||||
|
||||
public ExampleClient(IHttpTransfer wire, string mimeType) |
||||
{ |
||||
_wire = wire; |
||||
_mimeType = mimeType; |
||||
} |
||||
|
||||
TMessage IRpcDispatch.CallMethod<TMessage, TBuilder>(string method, IMessageLite request, |
||||
IBuilderLite<TMessage, TBuilder> response) |
||||
{ |
||||
MemoryStream input = new MemoryStream(); |
||||
MemoryStream output = new MemoryStream(); |
||||
|
||||
//Write to _mimeType format |
||||
request.WriteTo(Options, _mimeType, input); |
||||
|
||||
input.Position = 0; |
||||
_wire.Execute(method, _mimeType, input, _mimeType, output); |
||||
|
||||
//Read from _mimeType format |
||||
output.Position = 0; |
||||
response.MergeFrom(Options, _mimeType, output); |
||||
|
||||
return response.Build(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestClientServerWithJsonFormat() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
ISearchService client = new SearchService(new ExampleClient(wire, "text/json")); |
||||
//now the client has a real, typed, interface to work with: |
||||
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
//The test part of this, call the only other method |
||||
result = |
||||
client.RefineSearch( |
||||
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Refine", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestClientServerWithXmlFormat() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
ISearchService client = new SearchService(new ExampleClient(wire, "text/xml")); |
||||
//now the client has a real, typed, interface to work with: |
||||
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
//The test part of this, call the only other method |
||||
result = |
||||
client.RefineSearch( |
||||
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Refine", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestClientServerWithProtoFormat() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
ISearchService client = new SearchService(new ExampleClient(wire, "application/x-protobuf")); |
||||
//now the client has a real, typed, interface to work with: |
||||
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
//The test part of this, call the only other method |
||||
result = |
||||
client.RefineSearch( |
||||
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Refine", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestClientServerWithCustomFormat() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//Setup our custom mime-type format as the only format supported: |
||||
server.Options.MimeInputTypes.Clear(); |
||||
server.Options.MimeInputTypes.Add("foo/bar", CodedInputStream.CreateInstance); |
||||
server.Options.MimeOutputTypes.Clear(); |
||||
server.Options.MimeOutputTypes.Add("foo/bar", CodedOutputStream.CreateInstance); |
||||
|
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
ExampleClient exclient = new ExampleClient(wire, "foo/bar"); |
||||
//Add our custom mime-type format |
||||
exclient.Options.MimeInputTypes.Add("foo/bar", CodedInputStream.CreateInstance); |
||||
exclient.Options.MimeOutputTypes.Add("foo/bar", CodedOutputStream.CreateInstance); |
||||
ISearchService client = new SearchService(exclient); |
||||
|
||||
//now the client has a real, typed, interface to work with: |
||||
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
//The test part of this, call the only other method |
||||
result = |
||||
client.RefineSearch( |
||||
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Refine", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestServerWithUriFormat() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
MemoryStream input = new MemoryStream(Encoding.UTF8.GetBytes("?Criteria=Test&Criteria=Test+of%20URI")); |
||||
MemoryStream output = new MemoryStream(); |
||||
|
||||
//Call the server |
||||
wire.Execute("Search", |
||||
MessageFormatOptions.ContentFormUrlEncoded, input, |
||||
MessageFormatOptions.ContentTypeProtoBuffer, output |
||||
); |
||||
|
||||
SearchResponse result = SearchResponse.ParseFrom(output.ToArray()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Test of URI", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[1].Url); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test, ExpectedException(typeof(ArgumentOutOfRangeException))] |
||||
public void TestInvalidMimeType() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
MemoryStream input = new MemoryStream(); |
||||
MemoryStream output = new MemoryStream(); |
||||
|
||||
//Call the server |
||||
wire.Execute("Search", |
||||
"bad/mime", input, |
||||
MessageFormatOptions.ContentTypeProtoBuffer, output |
||||
); |
||||
Assert.Fail(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Test sending and recieving messages via text/json |
||||
/// </summary> |
||||
[Test] |
||||
public void TestDefaultMimeType() |
||||
{ |
||||
ExampleHttpServer server = new ExampleHttpServer(new ExampleSearchImpl()); |
||||
|
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IHttpTransfer wire = server; |
||||
|
||||
|
||||
MemoryStream input = new MemoryStream(new SearchRequest.Builder().AddCriteria("Test").Build().ToByteArray()); |
||||
MemoryStream output = new MemoryStream(); |
||||
|
||||
//With this default set, any invalid/unknown mime-type will be mapped to use that format |
||||
server.Options.DefaultContentType = MessageFormatOptions.ContentTypeProtoBuffer; |
||||
|
||||
wire.Execute("Search", |
||||
"foo", input, |
||||
"bar", output |
||||
); |
||||
|
||||
SearchResponse result = SearchResponse.ParseFrom(output.ToArray()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,171 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// http://github.com/jskeet/dotnet-protobufs/ |
||||
// Original C++/Java/Python code: |
||||
// http://code.google.com/p/protobuf/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using Google.ProtocolBuffers; |
||||
using Google.ProtocolBuffers.TestProtos; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// This class verifies the correct code is generated from unittest_rpc_interop.proto and provides a small demonstration |
||||
/// of using the new IRpcDispatch to write a client/server |
||||
/// </summary> |
||||
[TestFixture] |
||||
public class TestRpcGenerator |
||||
{ |
||||
/// <summary> |
||||
/// A sample implementation of the ISearchService for testing |
||||
/// </summary> |
||||
private class ExampleSearchImpl : ISearchService |
||||
{ |
||||
SearchResponse ISearchService.Search(SearchRequest searchRequest) |
||||
{ |
||||
if (searchRequest.CriteriaCount == 0) |
||||
{ |
||||
throw new ArgumentException("No criteria specified.", new InvalidOperationException()); |
||||
} |
||||
SearchResponse.Builder resp = SearchResponse.CreateBuilder(); |
||||
foreach (string criteria in searchRequest.CriteriaList) |
||||
{ |
||||
resp.AddResults( |
||||
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://search.com"). |
||||
Build()); |
||||
} |
||||
return resp.Build(); |
||||
} |
||||
|
||||
SearchResponse ISearchService.RefineSearch(RefineSearchRequest refineSearchRequest) |
||||
{ |
||||
SearchResponse.Builder resp = refineSearchRequest.PreviousResults.ToBuilder(); |
||||
foreach (string criteria in refineSearchRequest.CriteriaList) |
||||
{ |
||||
resp.AddResults( |
||||
SearchResponse.Types.ResultItem.CreateBuilder().SetName(criteria).SetUrl("http://refine.com"). |
||||
Build()); |
||||
} |
||||
return resp.Build(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example extraction of the wire protocol |
||||
/// </summary> |
||||
private interface IWireTransfer |
||||
{ |
||||
byte[] Execute(string method, byte[] message); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example of a server responding to a wire request |
||||
/// </summary> |
||||
private class ExampleServerHost : IWireTransfer |
||||
{ |
||||
private readonly IRpcServerStub _stub; |
||||
|
||||
public ExampleServerHost(ISearchService implementation) |
||||
{ |
||||
//on the server, we create a dispatch to call the appropriate method by name |
||||
IRpcDispatch dispatch = new SearchService.Dispatch(implementation); |
||||
//we then wrap that dispatch in a server stub which will deserialize the wire bytes to the message |
||||
//type appropriate for the method name being invoked. |
||||
_stub = new SearchService.ServerStub(dispatch); |
||||
} |
||||
|
||||
byte[] IWireTransfer.Execute(string method, byte[] message) |
||||
{ |
||||
//now when we recieve a wire transmission to invoke a method by name with a byte[] or stream payload |
||||
//we just simply call the sub: |
||||
IMessageLite response = _stub.CallMethod(method, CodedInputStream.CreateInstance(message), |
||||
ExtensionRegistry.Empty); |
||||
//now we return the expected response message: |
||||
return response.ToByteArray(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// An example of a client sending a wire request |
||||
/// </summary> |
||||
private class ExampleClient : IRpcDispatch |
||||
{ |
||||
private readonly IWireTransfer _wire; |
||||
|
||||
public ExampleClient(IWireTransfer wire) |
||||
{ |
||||
_wire = wire; |
||||
} |
||||
|
||||
TMessage IRpcDispatch.CallMethod<TMessage, TBuilder>(string method, IMessageLite request, |
||||
IBuilderLite<TMessage, TBuilder> response) |
||||
{ |
||||
byte[] rawResponse = _wire.Execute(method, request.ToByteArray()); |
||||
response.MergeFrom(rawResponse); |
||||
return response.Build(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Put it all together to create one seamless client/server experience full of rich-type goodness ;) |
||||
/// All you need to do is send/recieve the method name and message bytes across the wire. |
||||
/// </summary> |
||||
[Test] |
||||
public void TestClientServerDispatch() |
||||
{ |
||||
ExampleServerHost server = new ExampleServerHost(new ExampleSearchImpl()); |
||||
//obviously if this was a 'real' transport we would not use the server, rather the server would be listening, the client transmitting |
||||
IWireTransfer wire = server; |
||||
|
||||
ISearchService client = new SearchService(new ExampleClient(wire)); |
||||
//now the client has a real, typed, interface to work with: |
||||
SearchResponse result = client.Search(SearchRequest.CreateBuilder().AddCriteria("Test").Build()); |
||||
Assert.AreEqual(1, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
//The test part of this, call the only other method |
||||
result = |
||||
client.RefineSearch( |
||||
RefineSearchRequest.CreateBuilder().SetPreviousResults(result).AddCriteria("Refine").Build()); |
||||
Assert.AreEqual(2, result.ResultsCount); |
||||
Assert.AreEqual("Test", result.ResultsList[0].Name); |
||||
Assert.AreEqual("http://search.com", result.ResultsList[0].Url); |
||||
|
||||
Assert.AreEqual("Refine", result.ResultsList[1].Name); |
||||
Assert.AreEqual("http://refine.com", result.ResultsList[1].Url); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
@ECHO OFF |
||||
IF "%1" == "2008" GOTO COPY2008 |
||||
IF "%1" == "2010" GOTO COPY2010 |
||||
GOTO HELP |
||||
|
||||
:COPY2008 |
||||
type ProtocolBuffers.sln | FIND " Visual Studio " > Temp.sln |
||||
type ProtocolBuffers2008.sln | FIND /V " Visual Studio " >> Temp.sln |
||||
move /Y Temp.sln ProtocolBuffers.sln |
||||
GOTO EXIT |
||||
|
||||
:COPY2010 |
||||
type ProtocolBuffers2008.sln | FIND " Visual Studio " > Temp.sln |
||||
type ProtocolBuffers.sln | FIND /V " Visual Studio " >> Temp.sln |
||||
move /Y Temp.sln ProtocolBuffers2008.sln |
||||
GOTO EXIT |
||||
|
||||
:HELP |
||||
ECHO. |
||||
ECHO Specify the Visiual Studio edition (2008/2010) |
||||
ECHO Example: %~nx0 2008 |
||||
ECHO. |
||||
|
||||
:EXIT |
Loading…
Reference in new issue