2019-06-08 21:40:44 +03:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2021-10-27 00:57:12 +03:00
|
|
|
"go.unistack.org/micro/v3/codec"
|
|
|
|
"go.unistack.org/micro/v3/metadata"
|
2019-06-08 21:40:44 +03:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type response struct {
|
2020-09-17 16:08:21 +03:00
|
|
|
conn *poolConn
|
2019-06-08 21:40:44 +03:00
|
|
|
stream grpc.ClientStream
|
2020-11-26 01:18:35 +03:00
|
|
|
codec codec.Codec
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read the response
|
2020-11-26 01:18:35 +03:00
|
|
|
func (r *response) Codec() codec.Codec {
|
|
|
|
return r.codec
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// read the header
|
2020-11-18 12:24:58 +03:00
|
|
|
func (r *response) Header() metadata.Metadata {
|
|
|
|
meta, err := r.stream.Header()
|
2019-06-08 21:40:44 +03:00
|
|
|
if err != nil {
|
2020-11-18 12:24:58 +03:00
|
|
|
return metadata.New(0)
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|
2020-11-18 12:24:58 +03:00
|
|
|
md := metadata.New(len(meta))
|
|
|
|
for k, v := range meta {
|
|
|
|
md.Set(k, strings.Join(v, ","))
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|
2020-11-18 12:24:58 +03:00
|
|
|
return md
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read the undecoded response
|
|
|
|
func (r *response) Read() ([]byte, error) {
|
2020-11-26 01:18:35 +03:00
|
|
|
f := &codec.Frame{}
|
|
|
|
if err := r.codec.ReadBody(&wrapStream{r.stream}, f); err != nil {
|
2019-06-18 20:51:52 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f.Data, nil
|
2019-06-08 21:40:44 +03:00
|
|
|
}
|