2019-06-03 20:44:43 +03:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/codec"
|
|
|
|
"github.com/unistack-org/micro/v3/codec/bytes"
|
2019-06-03 20:44:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type rpcRequest struct {
|
|
|
|
service string
|
|
|
|
method string
|
|
|
|
contentType string
|
|
|
|
codec codec.Codec
|
|
|
|
header map[string]string
|
|
|
|
body []byte
|
|
|
|
stream bool
|
|
|
|
payload interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type rpcMessage struct {
|
|
|
|
topic string
|
|
|
|
contentType string
|
|
|
|
payload interface{}
|
2019-11-25 19:31:43 +03:00
|
|
|
header map[string]string
|
|
|
|
body []byte
|
|
|
|
codec codec.Codec
|
2019-06-03 20:44:43 +03: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 {
|
|
|
|
return r.method
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Codec() codec.Reader {
|
|
|
|
return r.codec
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Header() map[string]string {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Read() ([]byte, error) {
|
2019-06-18 20:51:52 +03:00
|
|
|
f := &bytes.Frame{}
|
|
|
|
if err := r.codec.ReadBody(f); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f.Data, nil
|
2019-06-03 20:44:43 +03: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 19:31:43 +03:00
|
|
|
|
|
|
|
func (r *rpcMessage) Header() map[string]string {
|
|
|
|
return r.header
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Body() []byte {
|
|
|
|
return r.body
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcMessage) Codec() codec.Reader {
|
|
|
|
return r.codec
|
|
|
|
}
|