Skip to content

Instantly share code, notes, and snippets.

@taylortrimble
Created February 21, 2017 00:32
Show Gist options
  • Save taylortrimble/058504e94507804e88fdcd7b00ad13f6 to your computer and use it in GitHub Desktop.
Save taylortrimble/058504e94507804e88fdcd7b00ad13f6 to your computer and use it in GitHub Desktop.
An idea for framing gRPC requests from JavaScript WebSockets to a generic proxy.
syntax = "proto3";
option go_package = "proxy";
// Frames an API request message.
//
// Each request to the API has a unique stream id per-connection, starting at one.
// This stream id associates all request and response messages for a single request
// together.
//
// The stream id must be included for each frame, and there is a 1:1 relationship
// between frames and request messages. Each frame encapsulates a single, full and
// unsegmented request message.
//
// GRPC calls consist of unary or streaming requests and unary or streaming responses.
// For unary request messages and the first message of a streaming request, the
// service and method names must be set, and the client streams and server streams
// values must be valid. Subsequent request messages for streaming requests should
// not set service or method names, and should not set client streams or server
// streams. The server will ignore those values for subsequent request messages.
// The last request message for a streaming request must set close stream to true.
// Close stream is ignored for unary requests.
message RequestFrame {
int64 stream_id = 1;
bytes message = 2;
string service = 3;
string method = 4;
bool client_streams = 5;
bool server_streams = 6;
bool close_stream = 7;
}
// Frames API response messages.
//
// The stream id associates each response message with its originating request.
// The stream id must be included for each frame, and there is a 1:1 relationship
// between frames and response messages. Each frame encapsulates a single, full and
// unsegmented response message.
//
// GRPC responses can be unary or streaming. Unary response messages, or the last
// response message for a streaming response, must set status, and can optionally
// set status message. Setting status closes a response stream.
//
// Status is defined as a gRPC status code PLUS ONE. This helps distinguish
// between no status set and GRPC_STATUS_OK.
message ResponseFrame {
int64 stream_id = 1;
bytes message = 2;
int64 status = 3;
string status_message = 4;
}
// Future support:
// grpc-timeout (no timeout for now)
// compression (use WebSocket compression for now)
// override authority (defaults to WebSocket host)
// content-type (protobuf only for now)
// user-agent (defaults to WebSocket header)
// custom headers (no custom headers for now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment