2019-06-08 19:40:44 +01: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 19:40:44 +01:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
type response struct {
|
2024-02-14 19:14:56 +03:00
|
|
|
conn *PoolConn
|
2019-06-08 19:40:44 +01:00
|
|
|
stream grpc.ClientStream
|
2020-11-26 01:18:35 +03:00
|
|
|
codec codec.Codec
|
2019-06-08 19:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read the response
|
2020-11-26 01:18:35 +03:00
|
|
|
func (r *response) Codec() codec.Codec {
|
|
|
|
return r.codec
|
2019-06-08 19:40:44 +01: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 19:40:44 +01:00
|
|
|
if err != nil {
|
2022-11-16 23:10:27 +03:00
|
|
|
return nil
|
2019-06-08 19:40:44 +01: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 19:40:44 +01:00
|
|
|
}
|
2020-11-18 12:24:58 +03:00
|
|
|
return md
|
2019-06-08 19:40:44 +01: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 18:51:52 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f.Data, nil
|
2019-06-08 19:40:44 +01:00
|
|
|
}
|