ttrpc: remove use of typeurl

Rather than employ the typeurl package, we now generate code to
correctly allocate the incoming types from the caller. As a side-effect
of this activity, the services definitions have been split out into a
separate type that handles the full resolution and dispatch of the
method, incuding correctly mapping the RPC status.

This work is a pre-cursor to larger protocol change that will allow us
to handle multiple, concurrent requests.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-11-21 18:03:52 -08:00
parent 2d76dba1df
commit 2a81659f49
8 changed files with 225 additions and 136 deletions

View File

@@ -31,12 +31,8 @@ func newTestingClient(client *Client) *testingClient {
}
func (tc *testingClient) Test(ctx context.Context, req *testPayload) (*testPayload, error) {
resp, err := tc.client.Call(ctx, serviceName, "Test", req)
if err != nil {
return nil, err
}
return resp.(*testPayload), nil
var tp testPayload
return &tp, tc.client.Call(ctx, serviceName, "Test", req, &tp)
}
type testPayload struct {
@@ -72,17 +68,19 @@ func TestServer(t *testing.T) {
// more mocking of what is generated code. Unlike grpc, we register with a
// closure so that the descriptor is allocated only on registration.
registerTestingService := func(srv *Server, svc testingService) error {
return srv.Register(serviceName, map[string]Handler{
"Test": HandlerFunc(func(ctx context.Context, req interface{}) (interface{}, error) {
return svc.Test(ctx, req.(*testPayload))
}),
registerTestingService := func(srv *Server, svc testingService) {
srv.Register(serviceName, map[string]Method{
"Test": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) {
var req testPayload
if err := unmarshal(&req); err != nil {
return nil, err
}
return svc.Test(ctx, &req)
},
})
}
if err := registerTestingService(server, testImpl); err != nil {
t.Fatal(err)
}
registerTestingService(server, testImpl)
listener, err := net.Listen("tcp", ":0")
if err != nil {