// Copyright (c) 2009 Shardul Deo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Authors: Shardul Deo, BJ Neilsen
//
// Protobufs needed for socket rpcs.

package protobuf.socketrpc;

message Request
{
  required string service_name = 1;             // Fully- qualified Service class name
  required string method_name = 2;              // Service method to invoke
  optional bytes request_proto = 3;             // Serialized request bytes
  optional string caller = 4;                   // Calling hostname or address
}

message Response
{
  optional bytes response_proto = 1;            // Serialized response
  optional string error = 2;                    // Error message, if any
  optional bool callback = 3 [default = false]; // Was callback invoked (not sure what this is for)
  optional ErrorReason error_reason = 4;        // Error Reason
  optional string server = 5;                   // Server hostname or address
}

// Possible error reasons
// The server-side errors are returned in the response from the server.
// The client-side errors are returned by the client-side code when it doesn't
// have a response from the server.
enum ErrorReason
{
  // Server-side errors
  BAD_REQUEST_DATA = 0;                         // Server received bad request data
  BAD_REQUEST_PROTO = 1;                        // Server received bad request proto
  SERVICE_NOT_FOUND = 2;                        // Service not found on server
  METHOD_NOT_FOUND = 3;                         // Method not found on server
  RPC_ERROR = 4;                                // Rpc threw exception on server
  RPC_FAILED = 5;                               // Rpc failed on server

  // Client-side errors (these are returned by the client-side code)
  INVALID_REQUEST_PROTO = 6;                    // Rpc was called with invalid request proto
  BAD_RESPONSE_PROTO = 7;                       // Server returned a bad response proto
  UNKNOWN_HOST = 8;                             // Could not find supplied host
  IO_ERROR = 9;                                 // I/O error while communicating with server
}