Skip to content

Commit

Permalink
Fix GeneratedService and RpcClient to be independent of wire protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Slesinsky committed Jun 24, 2015
1 parent 02c90ed commit 3abd95c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
15 changes: 9 additions & 6 deletions lib/src/protobuf/generated_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class ServerContext {
// TODO: Place server specific information in this class.
}

/// Abstract class used to implement a Service API.
/// The implementation of a Service API.
///
/// The protoc compiler generates subclasses of this class containing abstract
/// methods for each defined service method and a handleCall method that
/// dispatches to the corresponding abstract method.
/// The protoc plugin generates subclasses (with names ending with ServiceBase)
/// that extend GeneratedService and dispatch requests by method.
abstract class GeneratedService {
Future<List<int>> handleCall(
ServerContext ctx, String methodName, List<int> request);
/// Creates a message object that can deserialize a request.
GeneratedMessage createRequest(String methodName);

/// Dispatches the call. The request object should come from [createRequest].
Future<GeneratedMessage> handleCall(
ServerContext ctx, String methodName, GeneratedMessage request);
}
22 changes: 17 additions & 5 deletions lib/src/protobuf/rpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ class ClientContext {
// TODO: Place client side specific information here.
}

/// Client interface.
/// Client-side transport for making calls to a service.
///
/// This must be implemented by protobuf clients which are passed to the
/// generated client stub class at construction.
/// Subclasses implement whatever serialization and networking is needed
/// to make a call. They should serialize the request to binary or JSON as
/// appropriate and merge the response into the supplied emptyResponse
/// before returning it.
///
/// The protoc plugin generates a client-side stub for each service that
/// takes an RpcClient as a constructor parameter.
abstract class RpcClient {
Future<List<int>> Invoke(
ClientContext ctx, String methodName, List<int> request);

/// Sends a request to a server and returns the reply.
///
/// The implementation should serialize the request as binary or JSON, as
/// appropriate. It should merge the reply into [emptyResponse] and
/// return it.
Future<GeneratedMessage> invoke(
ClientContext ctx, String serviceName, String methodName,
GeneratedMessage request, GeneratedMessage emptyResponse);
}

0 comments on commit 3abd95c

Please sign in to comment.