github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/rpc/common/call.go (about)

     1  package common
     2  
     3  type callType uint8
     4  
     5  const (
     6  	_ callType = iota
     7  	callUnary
     8  	callClientStream
     9  	callServerStream
    10  	callBidirStream
    11  )
    12  
    13  // CallMethodInfo is an information about the RPC.
    14  type CallMethodInfo struct {
    15  	// Name of the service.
    16  	Service string
    17  
    18  	// Name of the RPC.
    19  	Name string
    20  
    21  	t callType
    22  }
    23  
    24  // ServerStream checks if CallMethodInfo contains
    25  // information about the server-side streaming RPC.
    26  func (c CallMethodInfo) ServerStream() bool {
    27  	return c.t == callServerStream || c.t == callBidirStream
    28  }
    29  
    30  // ClientStream checks if CallMethodInfo contains
    31  // information about the client-side streaming RPC.
    32  func (c CallMethodInfo) ClientStream() bool {
    33  	return c.t == callClientStream || c.t == callBidirStream
    34  }
    35  
    36  func (c *CallMethodInfo) setCommon(service, name string) {
    37  	c.Service = service
    38  	c.Name = name
    39  }
    40  
    41  // CallMethodInfoUnary returns CallMethodInfo structure
    42  // initialized for the unary RPC.
    43  func CallMethodInfoUnary(service, name string) (info CallMethodInfo) {
    44  	info.setCommon(service, name)
    45  	info.t = callUnary
    46  
    47  	return
    48  }
    49  
    50  // CallMethodInfoClientStream returns CallMethodInfo structure
    51  // initialized for the client-side streaming RPC.
    52  func CallMethodInfoClientStream(service, name string) (info CallMethodInfo) {
    53  	info.setCommon(service, name)
    54  	info.t = callClientStream
    55  
    56  	return
    57  }
    58  
    59  // CallMethodInfoServerStream returns CallMethodInfo structure
    60  // initialized for the server-side streaming RPC.
    61  func CallMethodInfoServerStream(service, name string) (info CallMethodInfo) {
    62  	info.setCommon(service, name)
    63  	info.t = callServerStream
    64  
    65  	return
    66  }
    67  
    68  // CallMethodInfoBidirectionalStream returns CallMethodInfo structure
    69  // initialized for the bidirectional streaming RPC.
    70  func CallMethodInfoBidirectionalStream(service, name string) (info CallMethodInfo) {
    71  	info.setCommon(service, name)
    72  	info.t = callBidirStream
    73  
    74  	return
    75  }