2019-06-03 18:44:43 +01:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2020-11-26 01:17:21 +03:00
|
|
|
"io"
|
|
|
|
|
2020-09-20 16:08:45 +03:00
|
|
|
"github.com/unistack-org/micro/v3/codec"
|
2020-11-18 12:27:44 +03:00
|
|
|
"github.com/unistack-org/micro/v3/metadata"
|
2021-04-26 19:04:27 +03:00
|
|
|
"github.com/unistack-org/micro/v3/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ server.Request = &rpcRequest{}
|
|
|
|
_ server.Message = &rpcMessage{}
|
2019-06-03 18:44:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type rpcRequest struct {
|
2020-11-26 01:17:21 +03:00
|
|
|
rw io.ReadWriter
|
2021-04-26 19:04:27 +03:00
|
|
|
payload interface{}
|
|
|
|
codec codec.Codec
|
|
|
|
header metadata.Metadata
|
2019-06-03 18:44:43 +01:00
|
|
|
method string
|
2020-11-26 01:17:21 +03:00
|
|
|
endpoint string
|
2019-06-03 18:44:43 +01:00
|
|
|
contentType string
|
2021-04-26 19:04:27 +03:00
|
|
|
service string
|
2019-06-03 18:44:43 +01:00
|
|
|
body []byte
|
|
|
|
stream bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type rpcMessage struct {
|
|
|
|
payload interface{}
|
2021-04-26 19:04:27 +03:00
|
|
|
codec codec.Codec
|
2020-11-18 12:27:44 +03:00
|
|
|
header metadata.Metadata
|
2021-04-26 19:04:27 +03:00
|
|
|
topic string
|
|
|
|
contentType string
|
2019-11-25 16:31:43 +00:00
|
|
|
body []byte
|
2019-06-03 18:44:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) ContentType() string {
|
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Service() string {
|
|
|
|
return r.service
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Method() string {
|
|
|
|
return r.method
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Endpoint() string {
|
2021-04-26 19:04:27 +03:00
|
|
|
return r.endpoint
|
2019-06-03 18:44:43 +01:00
|
|
|
}
|
|
|
|
|
2020-11-26 01:17:21 +03:00
|
|
|
func (r *rpcRequest) Codec() codec.Codec {
|
2019-06-03 18:44:43 +01:00
|
|
|
return r.codec
|
|
|
|
}
|
|
|
|
|
2020-11-18 12:27:44 +03:00
|
|
|
func (r *rpcRequest) Header() metadata.Metadata {
|
2019-06-03 18:44:43 +01:00
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Read() ([]byte, error) {
|
2020-11-26 01:17:21 +03:00
|
|
|
f := &codec.Frame{}
|
|
|
|
if err := r.codec.ReadBody(r.rw, f); err != nil {
|
2019-06-18 18:51:52 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f.Data, nil
|
2019-06-03 18:44:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Stream() bool {
|
|
|
|
return r.stream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Body() interface{} {
|
|
|
|
return r.payload
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) ContentType() string {
|
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Topic() string {
|
|
|
|
return r.topic
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Payload() interface{} {
|
|
|
|
return r.payload
|
|
|
|
}
|
2019-11-25 16:31:43 +00:00
|
|
|
|
2020-11-18 12:27:44 +03:00
|
|
|
func (r *rpcMessage) Header() metadata.Metadata {
|
2019-11-25 16:31:43 +00:00
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Body() []byte {
|
|
|
|
return r.body
|
|
|
|
}
|
|
|
|
|
2020-11-26 01:17:21 +03:00
|
|
|
func (r *rpcMessage) Codec() codec.Codec {
|
2019-11-25 16:31:43 +00:00
|
|
|
return r.codec
|
|
|
|
}
|