It is expected that third parties will generate service/RPC code themselves - see gRPC as an example.pull/317/head
parent
e8310aa259
commit
cc058e1118
11 changed files with 0 additions and 594 deletions
@ -1,30 +0,0 @@ |
||||
syntax = "proto2"; |
||||
|
||||
// Additional options required for C# generation. File from copyright |
||||
// line onwards is as per original distribution. |
||||
import "google/protobuf/unittest.proto"; |
||||
import "google/protobuf/unittest_custom_options.proto"; |
||||
|
||||
option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; |
||||
|
||||
// option (google.protobuf.csharp_file_options).service_generator_type = GENERIC; |
||||
|
||||
// We don't put this in a package within proto2 because we need to make sure |
||||
// that the generated code doesn't depend on being in the proto2 namespace. |
||||
package protobuf_unittest; |
||||
|
||||
option optimize_for = SPEED; |
||||
|
||||
service TestGenericService { |
||||
rpc Foo(FooRequest) returns (FooResponse); |
||||
rpc Bar(BarRequest) returns (BarResponse); |
||||
} |
||||
|
||||
service TestGenericServiceWithCustomOptions { |
||||
option (service_opt1) = -9876543210; |
||||
|
||||
rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) { |
||||
option (method_opt1) = METHODOPT1_VAL2; |
||||
} |
||||
} |
||||
|
@ -1,41 +0,0 @@ |
||||
// 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 = "UnitTestRpcInterop"; |
||||
|
||||
option (google.protobuf.csharp_file_options).service_generator_type = IRPCDISPATCH; |
||||
|
||||
option optimize_for = SPEED; |
||||
|
||||
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 { |
||||
/* |
||||
Add this option to specify the GuidAttribute on the service interface |
||||
option (google.protobuf.csharp_service_options).interface_id = "{A65F0925-FD11-4f94-B166-89AC4F027205}"; |
||||
*/ |
||||
rpc Search (SearchRequest) returns (SearchResponse) |
||||
/* |
||||
Add this option to specify the DispIdAttribute on the service interface |
||||
{ option (google.protobuf.csharp_method_options).dispatch_id = 5; } |
||||
*/ ; |
||||
|
||||
rpc RefineSearch (RefineSearchRequest) returns (SearchResponse); |
||||
} |
@ -1,42 +0,0 @@ |
||||
// 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 { |
||||
/* |
||||
Add this option to specify the GuidAttribute on the service interface |
||||
option (google.protobuf.csharp_service_options).interface_id = "{A65F0925-FD11-4f94-B166-89AC4F027205}"; |
||||
*/ |
||||
rpc Search (SearchRequest) returns (SearchResponse) |
||||
/* |
||||
Add this option to specify the DispIdAttribute on the service interface |
||||
{ option (google.protobuf.csharp_method_options).dispatch_id = 5; } |
||||
*/ ; |
||||
|
||||
rpc RefineSearch (RefineSearchRequest) returns (SearchResponse); |
||||
} |
@ -1,63 +0,0 @@ |
||||
#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.Descriptors; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// Interface for an RPC channel. A channel represents a communication line to |
||||
/// a service (IService implementation) which can be used to call that service's |
||||
/// methods. The service may be running on another machine. Normally, you should |
||||
/// not call an IRpcChannel directly, but instead construct a stub wrapping it. |
||||
/// Generated service classes contain a CreateStub method for precisely this purpose. |
||||
/// </summary> |
||||
public interface IRpcChannel |
||||
{ |
||||
/// <summary> |
||||
/// Calls the given method of the remote service. This method is similar |
||||
/// to <see cref="IService.CallMethod" /> with one important difference: the |
||||
/// caller decides the types of the IMessage objects, not the implementation. |
||||
/// The request may be of any type as long as <c>request.Descriptor == method.InputType</c>. |
||||
/// The response passed to the callback will be of the same type as |
||||
/// <paramref name="responsePrototype"/> (which must be such that |
||||
/// <c>responsePrototype.Descriptor == method.OutputType</c>). |
||||
/// </summary> |
||||
void CallMethod(MethodDescriptor method, IRpcController controller, |
||||
IMessage request, IMessage responsePrototype, Action<IMessage> done); |
||||
} |
||||
} |
@ -1,125 +0,0 @@ |
||||
#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; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// Mediates a single method call. The primary purpose of the controller |
||||
/// is to provide a way to manipulate settings specific to the |
||||
/// RPC implementation and to find out about RPC-level errors. |
||||
/// |
||||
/// The methods provided by this interface are intended to be a "least |
||||
/// common denominator" set of features which we expect all implementations to |
||||
/// support. Specific implementations may provide more advanced features, |
||||
/// (e.g. deadline propagation). |
||||
/// </summary> |
||||
public interface IRpcController |
||||
{ |
||||
#region Client side calls |
||||
|
||||
// These calls may be made from the client side only. Their results |
||||
// are undefined on the server side (may throw exceptions). |
||||
|
||||
/// <summary> |
||||
/// Resets the controller to its initial state so that it may be reused in |
||||
/// a new call. This can be called from the client side only. It must not |
||||
/// be called while an RPC is in progress. |
||||
/// </summary> |
||||
void Reset(); |
||||
|
||||
/// <summary> |
||||
/// After a call has finished, returns true if the call failed. The possible |
||||
/// reasons for failure depend on the RPC implementation. Failed must |
||||
/// only be called on the client side, and must not be called before a call has |
||||
/// finished. |
||||
/// </summary> |
||||
bool Failed { get; } |
||||
|
||||
/// <summary> |
||||
/// If Failed is true, ErrorText returns a human-readable description of the error. |
||||
/// </summary> |
||||
string ErrorText { get; } |
||||
|
||||
/// <summary> |
||||
/// Advises the RPC system that the caller desires that the RPC call be |
||||
/// canceled. The RPC system may cancel it immediately, may wait awhile and |
||||
/// then cancel it, or may not even cancel the call at all. If the call is |
||||
/// canceled, the "done" callback will still be called and the RpcController |
||||
/// will indicate that the call failed at that time. |
||||
/// </summary> |
||||
void StartCancel(); |
||||
|
||||
#endregion |
||||
|
||||
#region Server side calls |
||||
|
||||
// These calls may be made from the server side only. Their results |
||||
// are undefined on the client side (may throw exceptions). |
||||
|
||||
/// <summary> |
||||
/// Causes Failed to return true on the client side. <paramref name="reason"/> |
||||
/// will be incorporated into the message returned by ErrorText. |
||||
/// If you find you need to return machine-readable information about |
||||
/// failures, you should incorporate it into your response protocol buffer |
||||
/// and should *not* call SetFailed. |
||||
/// </summary> |
||||
void SetFailed(string reason); |
||||
|
||||
/// <summary> |
||||
/// If true, indicates that the client canceled the RPC, so the server may as |
||||
/// well give up on replying to it. This method must be called on the server |
||||
/// side only. The server should still call the final "done" callback. |
||||
/// </summary> |
||||
bool IsCanceled(); |
||||
|
||||
/// <summary> |
||||
/// Requests that the given callback be called when the RPC is canceled. |
||||
/// The parameter passed to the callback will always be null. The callback will |
||||
/// be called exactly once. If the RPC completes without being canceled, the |
||||
/// callback will be called after completion. If the RPC has already been canceled |
||||
/// when NotifyOnCancel is called, the callback will be called immediately. |
||||
/// |
||||
/// NotifyOnCancel must be called no more than once per request. It must be |
||||
/// called on the server side only. |
||||
/// </summary> |
||||
/// <param name="callback"></param> |
||||
void NotifyOnCancel(Action<object> callback); |
||||
|
||||
#endregion |
||||
} |
||||
} |
@ -1,102 +0,0 @@ |
||||
#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.Descriptors; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// Base interface for protocol-buffer-based RPC services. Services themselves |
||||
/// are abstract classes (implemented either by servers or as stubs) but they |
||||
/// implement this itnerface. The methods of this interface can be used to call |
||||
/// the methods of the service without knowing its exact type at compile time |
||||
/// (analagous to the IMessage interface). |
||||
/// </summary> |
||||
public interface IService |
||||
{ |
||||
/// <summary> |
||||
/// The ServiceDescriptor describing this service and its methods. |
||||
/// </summary> |
||||
ServiceDescriptor DescriptorForType { get; } |
||||
|
||||
/// <summary> |
||||
/// Call a method of the service specified by MethodDescriptor. This is |
||||
/// normally implemented as a simple switch that calls the standard |
||||
/// definitions of the service's methods. |
||||
/// <para> |
||||
/// Preconditions |
||||
/// <list> |
||||
/// <item><c>method.Service == DescriptorForType</c></item> |
||||
/// <item>request is of the exact same class as the object returned by GetRequestPrototype(method)</item> |
||||
/// <item>controller is of the correct type for the RPC implementation being used by this service. |
||||
/// For stubs, the "correct type" depends on the IRpcChannel which the stub is using. Server-side |
||||
/// implementations are expected to accept whatever type of IRpcController the server-side RPC implementation |
||||
/// uses.</item> |
||||
/// </list> |
||||
/// </para> |
||||
/// <para> |
||||
/// Postconditions |
||||
/// <list> |
||||
/// <item><paramref name="done" /> will be called when the method is complete. |
||||
/// This may before CallMethod returns or it may be at some point in the future.</item> |
||||
/// <item>The parameter to <paramref name="done"/> is the response. It will be of the |
||||
/// exact same type as would be returned by <see cref="GetResponsePrototype"/>.</item> |
||||
/// <item>If the RPC failed, the parameter to <paramref name="done"/> will be null. |
||||
/// Further details about the failure can be found by querying <paramref name="controller"/>.</item> |
||||
/// </list> |
||||
/// </para> |
||||
/// </summary> |
||||
void CallMethod(MethodDescriptor method, IRpcController controller, |
||||
IMessage request, Action<IMessage> done); |
||||
|
||||
/// <summary> |
||||
/// CallMethod requires that the request passed in is of a particular implementation |
||||
/// of IMessage. This method gets the default instance of this type of a given method. |
||||
/// You can then call WeakCreateBuilderForType to create a builder to build an object which |
||||
/// you can then pass to CallMethod. |
||||
/// </summary> |
||||
IMessage GetRequestPrototype(MethodDescriptor method); |
||||
|
||||
/// <summary> |
||||
/// Like GetRequestPrototype, but returns a prototype of the response message. |
||||
/// This is generally not needed because the IService implementation contructs |
||||
/// the response message itself, but it may be useful in some cases to know ahead |
||||
/// of time what type of object will be returned. |
||||
/// </summary> |
||||
IMessage GetResponsePrototype(MethodDescriptor method); |
||||
} |
||||
} |
@ -1,79 +0,0 @@ |
||||
#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; |
||||
|
||||
namespace Google.ProtocolBuffers |
||||
{ |
||||
/// <summary> |
||||
/// Grab-bag of utility functions useful when dealing with RPCs. |
||||
/// </summary> |
||||
public static class RpcUtil |
||||
{ |
||||
/// <summary> |
||||
/// Converts an Action[IMessage] to an Action[T]. |
||||
/// </summary> |
||||
public static Action<T> SpecializeCallback<T>(Action<IMessage> action) |
||||
where T : IMessage<T> |
||||
{ |
||||
return message => action(message); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts an Action[T] to an Action[IMessage]. |
||||
/// The generalized action will accept any message object which has |
||||
/// the same descriptor, and will convert it to the correct class |
||||
/// before calling the original action. However, if the generalized |
||||
/// callback is given a message with a different descriptor, an |
||||
/// exception will be thrown. |
||||
/// </summary> |
||||
public static Action<IMessage> GeneralizeCallback<TMessage, TBuilder>(Action<TMessage> action, |
||||
TMessage defaultInstance) |
||||
where TMessage : class, IMessage<TMessage, TBuilder> |
||||
where TBuilder : IBuilder<TMessage, TBuilder> |
||||
{ |
||||
return message => |
||||
{ |
||||
TMessage castMessage = message as TMessage; |
||||
if (castMessage == null) |
||||
{ |
||||
castMessage = defaultInstance.CreateBuilderForType().MergeFrom(message).Build(); |
||||
} |
||||
action(castMessage); |
||||
}; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue