go.uber.org/yarpc@v1.72.1/encoding/protobuf/internal/testpb/test.pb.yarpc.go (about)

     1  // Code generated by protoc-gen-yarpc-go. DO NOT EDIT.
     2  // source: encoding/protobuf/internal/testpb/test.proto
     3  
     4  // Copyright (c) 2022 Uber Technologies, Inc.
     5  //
     6  // Permission is hereby granted, free of charge, to any person obtaining a copy
     7  // of this software and associated documentation files (the "Software"), to deal
     8  // in the Software without restriction, including without limitation the rights
     9  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10  // copies of the Software, and to permit persons to whom the Software is
    11  // furnished to do so, subject to the following conditions:
    12  //
    13  // The above copyright notice and this permission notice shall be included in
    14  // all copies or substantial portions of the Software.
    15  //
    16  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    21  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    22  // THE SOFTWARE.
    23  
    24  package testpb
    25  
    26  import (
    27  	"context"
    28  	"io/ioutil"
    29  	"reflect"
    30  
    31  	"github.com/gogo/protobuf/jsonpb"
    32  	"github.com/gogo/protobuf/proto"
    33  	"go.uber.org/fx"
    34  	"go.uber.org/yarpc"
    35  	"go.uber.org/yarpc/api/transport"
    36  	"go.uber.org/yarpc/api/x/restriction"
    37  	"go.uber.org/yarpc/encoding/protobuf"
    38  	"go.uber.org/yarpc/encoding/protobuf/reflection"
    39  )
    40  
    41  var _ = ioutil.NopCloser
    42  
    43  // TestYARPCClient is the YARPC client-side interface for the Test service.
    44  type TestYARPCClient interface {
    45  	Unary(context.Context, *TestMessage, ...yarpc.CallOption) (*TestMessage, error)
    46  	Duplex(context.Context, ...yarpc.CallOption) (TestServiceDuplexYARPCClient, error)
    47  }
    48  
    49  // TestServiceDuplexYARPCClient sends TestMessages and receives TestMessages, returning io.EOF when the stream is complete.
    50  type TestServiceDuplexYARPCClient interface {
    51  	Context() context.Context
    52  	Send(*TestMessage, ...yarpc.StreamOption) error
    53  	Recv(...yarpc.StreamOption) (*TestMessage, error)
    54  	CloseSend(...yarpc.StreamOption) error
    55  }
    56  
    57  func newTestYARPCClient(clientConfig transport.ClientConfig, anyResolver jsonpb.AnyResolver, options ...protobuf.ClientOption) TestYARPCClient {
    58  	return &_TestYARPCCaller{protobuf.NewStreamClient(
    59  		protobuf.ClientParams{
    60  			ServiceName:  "uber.yarpc.encoding.protobuf.Test",
    61  			ClientConfig: clientConfig,
    62  			AnyResolver:  anyResolver,
    63  			Options:      options,
    64  		},
    65  	)}
    66  }
    67  
    68  // NewTestYARPCClient builds a new YARPC client for the Test service.
    69  func NewTestYARPCClient(clientConfig transport.ClientConfig, options ...protobuf.ClientOption) TestYARPCClient {
    70  	return newTestYARPCClient(clientConfig, nil, options...)
    71  }
    72  
    73  // TestYARPCServer is the YARPC server-side interface for the Test service.
    74  type TestYARPCServer interface {
    75  	Unary(context.Context, *TestMessage) (*TestMessage, error)
    76  	Duplex(TestServiceDuplexYARPCServer) error
    77  }
    78  
    79  // TestServiceDuplexYARPCServer receives TestMessages and sends TestMessage.
    80  type TestServiceDuplexYARPCServer interface {
    81  	Context() context.Context
    82  	Recv(...yarpc.StreamOption) (*TestMessage, error)
    83  	Send(*TestMessage, ...yarpc.StreamOption) error
    84  }
    85  
    86  type buildTestYARPCProceduresParams struct {
    87  	Server      TestYARPCServer
    88  	AnyResolver jsonpb.AnyResolver
    89  }
    90  
    91  func buildTestYARPCProcedures(params buildTestYARPCProceduresParams) []transport.Procedure {
    92  	handler := &_TestYARPCHandler{params.Server}
    93  	return protobuf.BuildProcedures(
    94  		protobuf.BuildProceduresParams{
    95  			ServiceName: "uber.yarpc.encoding.protobuf.Test",
    96  			UnaryHandlerParams: []protobuf.BuildProceduresUnaryHandlerParams{
    97  				{
    98  					MethodName: "Unary",
    99  					Handler: protobuf.NewUnaryHandler(
   100  						protobuf.UnaryHandlerParams{
   101  							Handle:      handler.Unary,
   102  							NewRequest:  newTestServiceUnaryYARPCRequest,
   103  							AnyResolver: params.AnyResolver,
   104  						},
   105  					),
   106  				},
   107  			},
   108  			OnewayHandlerParams: []protobuf.BuildProceduresOnewayHandlerParams{},
   109  			StreamHandlerParams: []protobuf.BuildProceduresStreamHandlerParams{
   110  				{
   111  					MethodName: "Duplex",
   112  					Handler: protobuf.NewStreamHandler(
   113  						protobuf.StreamHandlerParams{
   114  							Handle: handler.Duplex,
   115  						},
   116  					),
   117  				},
   118  			},
   119  		},
   120  	)
   121  }
   122  
   123  // BuildTestYARPCProcedures prepares an implementation of the Test service for YARPC registration.
   124  func BuildTestYARPCProcedures(server TestYARPCServer) []transport.Procedure {
   125  	return buildTestYARPCProcedures(buildTestYARPCProceduresParams{Server: server})
   126  }
   127  
   128  // FxTestYARPCClientParams defines the input
   129  // for NewFxTestYARPCClient. It provides the
   130  // paramaters to get a TestYARPCClient in an
   131  // Fx application.
   132  type FxTestYARPCClientParams struct {
   133  	fx.In
   134  
   135  	Provider    yarpc.ClientConfig
   136  	AnyResolver jsonpb.AnyResolver  `name:"yarpcfx" optional:"true"`
   137  	Restriction restriction.Checker `optional:"true"`
   138  }
   139  
   140  // FxTestYARPCClientResult defines the output
   141  // of NewFxTestYARPCClient. It provides a
   142  // TestYARPCClient to an Fx application.
   143  type FxTestYARPCClientResult struct {
   144  	fx.Out
   145  
   146  	Client TestYARPCClient
   147  
   148  	// We are using an fx.Out struct here instead of just returning a client
   149  	// so that we can add more values or add named versions of the client in
   150  	// the future without breaking any existing code.
   151  }
   152  
   153  // NewFxTestYARPCClient provides a TestYARPCClient
   154  // to an Fx application using the given name for routing.
   155  //
   156  //  fx.Provide(
   157  //    testpb.NewFxTestYARPCClient("service-name"),
   158  //    ...
   159  //  )
   160  func NewFxTestYARPCClient(name string, options ...protobuf.ClientOption) interface{} {
   161  	return func(params FxTestYARPCClientParams) FxTestYARPCClientResult {
   162  		cc := params.Provider.ClientConfig(name)
   163  
   164  		if params.Restriction != nil {
   165  			if namer, ok := cc.GetUnaryOutbound().(transport.Namer); ok {
   166  				if err := params.Restriction.Check(protobuf.Encoding, namer.TransportName()); err != nil {
   167  					panic(err.Error())
   168  				}
   169  			}
   170  		}
   171  
   172  		return FxTestYARPCClientResult{
   173  			Client: newTestYARPCClient(cc, params.AnyResolver, options...),
   174  		}
   175  	}
   176  }
   177  
   178  // FxTestYARPCProceduresParams defines the input
   179  // for NewFxTestYARPCProcedures. It provides the
   180  // paramaters to get TestYARPCServer procedures in an
   181  // Fx application.
   182  type FxTestYARPCProceduresParams struct {
   183  	fx.In
   184  
   185  	Server      TestYARPCServer
   186  	AnyResolver jsonpb.AnyResolver `name:"yarpcfx" optional:"true"`
   187  }
   188  
   189  // FxTestYARPCProceduresResult defines the output
   190  // of NewFxTestYARPCProcedures. It provides
   191  // TestYARPCServer procedures to an Fx application.
   192  //
   193  // The procedures are provided to the "yarpcfx" value group.
   194  // Dig 1.2 or newer must be used for this feature to work.
   195  type FxTestYARPCProceduresResult struct {
   196  	fx.Out
   197  
   198  	Procedures     []transport.Procedure `group:"yarpcfx"`
   199  	ReflectionMeta reflection.ServerMeta `group:"yarpcfx"`
   200  }
   201  
   202  // NewFxTestYARPCProcedures provides TestYARPCServer procedures to an Fx application.
   203  // It expects a TestYARPCServer to be present in the container.
   204  //
   205  //  fx.Provide(
   206  //    testpb.NewFxTestYARPCProcedures(),
   207  //    ...
   208  //  )
   209  func NewFxTestYARPCProcedures() interface{} {
   210  	return func(params FxTestYARPCProceduresParams) FxTestYARPCProceduresResult {
   211  		return FxTestYARPCProceduresResult{
   212  			Procedures: buildTestYARPCProcedures(buildTestYARPCProceduresParams{
   213  				Server:      params.Server,
   214  				AnyResolver: params.AnyResolver,
   215  			}),
   216  			ReflectionMeta: TestReflectionMeta,
   217  		}
   218  	}
   219  }
   220  
   221  // TestReflectionMeta is the reflection server metadata
   222  // required for using the gRPC reflection protocol with YARPC.
   223  //
   224  // See https://github.com/grpc/grpc/blob/master/doc/server-reflection.md.
   225  var TestReflectionMeta = reflection.ServerMeta{
   226  	ServiceName:     "uber.yarpc.encoding.protobuf.Test",
   227  	FileDescriptors: yarpcFileDescriptorClosurefc320162ebaf2b25,
   228  }
   229  
   230  type _TestYARPCCaller struct {
   231  	streamClient protobuf.StreamClient
   232  }
   233  
   234  func (c *_TestYARPCCaller) Unary(ctx context.Context, request *TestMessage, options ...yarpc.CallOption) (*TestMessage, error) {
   235  	responseMessage, err := c.streamClient.Call(ctx, "Unary", request, newTestServiceUnaryYARPCResponse, options...)
   236  	if responseMessage == nil {
   237  		return nil, err
   238  	}
   239  	response, ok := responseMessage.(*TestMessage)
   240  	if !ok {
   241  		return nil, protobuf.CastError(emptyTestServiceUnaryYARPCResponse, responseMessage)
   242  	}
   243  	return response, err
   244  }
   245  
   246  func (c *_TestYARPCCaller) Duplex(ctx context.Context, options ...yarpc.CallOption) (TestServiceDuplexYARPCClient, error) {
   247  	stream, err := c.streamClient.CallStream(ctx, "Duplex", options...)
   248  	if err != nil {
   249  		return nil, err
   250  	}
   251  	return &_TestServiceDuplexYARPCClient{stream: stream}, nil
   252  }
   253  
   254  type _TestYARPCHandler struct {
   255  	server TestYARPCServer
   256  }
   257  
   258  func (h *_TestYARPCHandler) Unary(ctx context.Context, requestMessage proto.Message) (proto.Message, error) {
   259  	var request *TestMessage
   260  	var ok bool
   261  	if requestMessage != nil {
   262  		request, ok = requestMessage.(*TestMessage)
   263  		if !ok {
   264  			return nil, protobuf.CastError(emptyTestServiceUnaryYARPCRequest, requestMessage)
   265  		}
   266  	}
   267  	response, err := h.server.Unary(ctx, request)
   268  	if response == nil {
   269  		return nil, err
   270  	}
   271  	return response, err
   272  }
   273  
   274  func (h *_TestYARPCHandler) Duplex(serverStream *protobuf.ServerStream) error {
   275  	return h.server.Duplex(&_TestServiceDuplexYARPCServer{serverStream: serverStream})
   276  }
   277  
   278  type _TestServiceDuplexYARPCClient struct {
   279  	stream *protobuf.ClientStream
   280  }
   281  
   282  func (c *_TestServiceDuplexYARPCClient) Context() context.Context {
   283  	return c.stream.Context()
   284  }
   285  
   286  func (c *_TestServiceDuplexYARPCClient) Send(request *TestMessage, options ...yarpc.StreamOption) error {
   287  	return c.stream.Send(request, options...)
   288  }
   289  
   290  func (c *_TestServiceDuplexYARPCClient) Recv(options ...yarpc.StreamOption) (*TestMessage, error) {
   291  	responseMessage, err := c.stream.Receive(newTestServiceDuplexYARPCResponse, options...)
   292  	if responseMessage == nil {
   293  		return nil, err
   294  	}
   295  	response, ok := responseMessage.(*TestMessage)
   296  	if !ok {
   297  		return nil, protobuf.CastError(emptyTestServiceDuplexYARPCResponse, responseMessage)
   298  	}
   299  	return response, err
   300  }
   301  
   302  func (c *_TestServiceDuplexYARPCClient) CloseSend(options ...yarpc.StreamOption) error {
   303  	return c.stream.Close(options...)
   304  }
   305  
   306  type _TestServiceDuplexYARPCServer struct {
   307  	serverStream *protobuf.ServerStream
   308  }
   309  
   310  func (s *_TestServiceDuplexYARPCServer) Context() context.Context {
   311  	return s.serverStream.Context()
   312  }
   313  
   314  func (s *_TestServiceDuplexYARPCServer) Recv(options ...yarpc.StreamOption) (*TestMessage, error) {
   315  	requestMessage, err := s.serverStream.Receive(newTestServiceDuplexYARPCRequest, options...)
   316  	if requestMessage == nil {
   317  		return nil, err
   318  	}
   319  	request, ok := requestMessage.(*TestMessage)
   320  	if !ok {
   321  		return nil, protobuf.CastError(emptyTestServiceDuplexYARPCRequest, requestMessage)
   322  	}
   323  	return request, err
   324  }
   325  
   326  func (s *_TestServiceDuplexYARPCServer) Send(response *TestMessage, options ...yarpc.StreamOption) error {
   327  	return s.serverStream.Send(response, options...)
   328  }
   329  
   330  func newTestServiceUnaryYARPCRequest() proto.Message {
   331  	return &TestMessage{}
   332  }
   333  
   334  func newTestServiceUnaryYARPCResponse() proto.Message {
   335  	return &TestMessage{}
   336  }
   337  
   338  func newTestServiceDuplexYARPCRequest() proto.Message {
   339  	return &TestMessage{}
   340  }
   341  
   342  func newTestServiceDuplexYARPCResponse() proto.Message {
   343  	return &TestMessage{}
   344  }
   345  
   346  var (
   347  	emptyTestServiceUnaryYARPCRequest   = &TestMessage{}
   348  	emptyTestServiceUnaryYARPCResponse  = &TestMessage{}
   349  	emptyTestServiceDuplexYARPCRequest  = &TestMessage{}
   350  	emptyTestServiceDuplexYARPCResponse = &TestMessage{}
   351  )
   352  
   353  var yarpcFileDescriptorClosurefc320162ebaf2b25 = [][]byte{
   354  	// encoding/protobuf/internal/testpb/test.proto
   355  	[]byte{
   356  		0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x49, 0xcd, 0x4b, 0xce,
   357  		0x4f, 0xc9, 0xcc, 0x4b, 0xd7, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0xcf, 0xcc,
   358  		0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0x2f, 0x49, 0x2d, 0x2e, 0x29, 0x48, 0x02, 0x53, 0x7a,
   359  		0x60, 0x59, 0x21, 0x99, 0xd2, 0xa4, 0xd4, 0x22, 0xbd, 0xca, 0xc4, 0xa2, 0x82, 0x64, 0x3d, 0x98,
   360  		0x46, 0x3d, 0x98, 0x46, 0x25, 0x65, 0x2e, 0xee, 0x90, 0xd4, 0xe2, 0x12, 0xdf, 0xd4, 0xe2, 0xe2,
   361  		0xc4, 0xf4, 0x54, 0x21, 0x11, 0x2e, 0xd6, 0xb2, 0xc4, 0x9c, 0xd2, 0x54, 0x09, 0x46, 0x05, 0x46,
   362  		0x0d, 0xce, 0x20, 0x08, 0xc7, 0xe8, 0x24, 0x23, 0x17, 0x0b, 0x48, 0x95, 0x50, 0x2c, 0x17, 0x6b,
   363  		0x68, 0x5e, 0x62, 0x51, 0xa5, 0x90, 0xa6, 0x1e, 0x3e, 0x53, 0xf5, 0x90, 0x8c, 0x94, 0x22, 0x5e,
   364  		0xa9, 0x50, 0x12, 0x17, 0x9b, 0x4b, 0x69, 0x41, 0x4e, 0x6a, 0x05, 0x6d, 0xcc, 0xd7, 0x60, 0x34,
   365  		0x60, 0x74, 0xe2, 0x88, 0x62, 0x83, 0x84, 0x51, 0x12, 0x1b, 0x58, 0x8d, 0x31, 0x20, 0x00, 0x00,
   366  		0xff, 0xff, 0x2c, 0x33, 0x41, 0xcb, 0x4f, 0x01, 0x00, 0x00,
   367  	},
   368  }
   369  
   370  func init() {
   371  	yarpc.RegisterClientBuilder(
   372  		func(clientConfig transport.ClientConfig, structField reflect.StructField) TestYARPCClient {
   373  			return NewTestYARPCClient(clientConfig, protobuf.ClientBuilderOptions(clientConfig, structField)...)
   374  		},
   375  	)
   376  }