mirror of https://github.com/grpc/grpc-go.git
client: deprecate CallCustomCodec and provide new version using encoding.Codec (#2556)
This commit is contained in:
parent
1925e2441e
commit
d14ffaeb5c
|
@ -164,7 +164,7 @@ func WithDefaultCallOptions(cos ...CallOption) DialOption {
|
|||
// WithCodec returns a DialOption which sets a codec for message marshaling and
|
||||
// unmarshaling.
|
||||
//
|
||||
// Deprecated: use WithDefaultCallOptions(CallCustomCodec(c)) instead.
|
||||
// Deprecated: use WithDefaultCallOptions(ForceCodec(_)) instead.
|
||||
func WithCodec(c Codec) DialOption {
|
||||
return WithDefaultCallOptions(CallCustomCodec(c))
|
||||
}
|
||||
|
|
37
rpc_util.go
37
rpc_util.go
|
@ -370,13 +370,13 @@ func (o CompressorCallOption) after(c *callInfo) {}
|
|||
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for
|
||||
// more details.
|
||||
//
|
||||
// If CallCustomCodec is not also used, the content-subtype will be used to
|
||||
// look up the Codec to use in the registry controlled by RegisterCodec. See
|
||||
// the documentation on RegisterCodec for details on registration. The lookup
|
||||
// of content-subtype is case-insensitive. If no such Codec is found, the call
|
||||
// If ForceCodec is not also used, the content-subtype will be used to look up
|
||||
// the Codec to use in the registry controlled by RegisterCodec. See the
|
||||
// documentation on RegisterCodec for details on registration. The lookup of
|
||||
// content-subtype is case-insensitive. If no such Codec is found, the call
|
||||
// will result in an error with code codes.Internal.
|
||||
//
|
||||
// If CallCustomCodec is also used, that Codec will be used for all request and
|
||||
// If ForceCodec is also used, that Codec will be used for all request and
|
||||
// response messages, with the content-subtype set to the given contentSubtype
|
||||
// here for requests.
|
||||
func CallContentSubtype(contentSubtype string) CallOption {
|
||||
|
@ -396,7 +396,7 @@ func (o ContentSubtypeCallOption) before(c *callInfo) error {
|
|||
}
|
||||
func (o ContentSubtypeCallOption) after(c *callInfo) {}
|
||||
|
||||
// CallCustomCodec returns a CallOption that will set the given Codec to be
|
||||
// ForceCodec returns a CallOption that will set the given Codec to be
|
||||
// used for all request and response messages for a call. The result of calling
|
||||
// String() will be used as the content-subtype in a case-insensitive manner.
|
||||
//
|
||||
|
@ -408,12 +408,37 @@ func (o ContentSubtypeCallOption) after(c *callInfo) {}
|
|||
//
|
||||
// This function is provided for advanced users; prefer to use only
|
||||
// CallContentSubtype to select a registered codec instead.
|
||||
//
|
||||
// This is an EXPERIMENTAL API.
|
||||
func ForceCodec(codec encoding.Codec) CallOption {
|
||||
return ForceCodecCallOption{Codec: codec}
|
||||
}
|
||||
|
||||
// ForceCodecCallOption is a CallOption that indicates the codec used for
|
||||
// marshaling messages.
|
||||
//
|
||||
// This is an EXPERIMENTAL API.
|
||||
type ForceCodecCallOption struct {
|
||||
Codec encoding.Codec
|
||||
}
|
||||
|
||||
func (o ForceCodecCallOption) before(c *callInfo) error {
|
||||
c.codec = o.Codec
|
||||
return nil
|
||||
}
|
||||
func (o ForceCodecCallOption) after(c *callInfo) {}
|
||||
|
||||
// CallCustomCodec behaves like ForceCodec, but accepts a grpc.Codec instead of
|
||||
// an encoding.Codec.
|
||||
//
|
||||
// Deprecated: use ForceCodec instead.
|
||||
func CallCustomCodec(codec Codec) CallOption {
|
||||
return CustomCodecCallOption{Codec: codec}
|
||||
}
|
||||
|
||||
// CustomCodecCallOption is a CallOption that indicates the codec used for
|
||||
// marshaling messages.
|
||||
//
|
||||
// This is an EXPERIMENTAL API.
|
||||
type CustomCodecCallOption struct {
|
||||
Codec Codec
|
||||
|
|
|
@ -51,6 +51,7 @@ import (
|
|||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/encoding"
|
||||
_ "google.golang.org/grpc/encoding/gzip"
|
||||
_ "google.golang.org/grpc/grpclog/glogger"
|
||||
"google.golang.org/grpc/health"
|
||||
|
@ -500,7 +501,7 @@ type test struct {
|
|||
streamServerInt grpc.StreamServerInterceptor
|
||||
unknownHandler grpc.StreamHandler
|
||||
sc <-chan grpc.ServiceConfig
|
||||
customCodec grpc.Codec
|
||||
customCodec encoding.Codec
|
||||
serverInitialWindowSize int32
|
||||
serverInitialConnWindowSize int32
|
||||
clientInitialWindowSize int32
|
||||
|
@ -632,9 +633,6 @@ func (te *test) listenAndServe(ts testpb.TestServiceServer, listen func(network,
|
|||
case "clientTimeoutCreds":
|
||||
sopts = append(sopts, grpc.Creds(&clientTimeoutCreds{}))
|
||||
}
|
||||
if te.customCodec != nil {
|
||||
sopts = append(sopts, grpc.CustomCodec(te.customCodec))
|
||||
}
|
||||
if te.svrKeepAlive != nil {
|
||||
sopts = append(sopts, grpc.KeepaliveParams(*te.svrKeepAlive))
|
||||
}
|
||||
|
@ -866,7 +864,7 @@ func (te *test) configDial(opts ...grpc.DialOption) ([]grpc.DialOption, string)
|
|||
opts = append(opts, grpc.WithPerRPCCredentials(te.perRPCCreds))
|
||||
}
|
||||
if te.customCodec != nil {
|
||||
opts = append(opts, grpc.WithDefaultCallOptions(grpc.CallCustomCodec(te.customCodec)))
|
||||
opts = append(opts, grpc.WithDefaultCallOptions(grpc.ForceCodec(te.customCodec)))
|
||||
}
|
||||
if !te.nonBlockingDial && te.srvAddr != "" {
|
||||
// Only do a blocking dial if server is up.
|
||||
|
@ -5736,7 +5734,7 @@ func (c *errCodec) Unmarshal(data []byte, v interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *errCodec) String() string {
|
||||
func (c *errCodec) Name() string {
|
||||
return "Fermat's near-miss."
|
||||
}
|
||||
|
||||
|
|
1
vet.sh
1
vet.sh
|
@ -112,6 +112,7 @@ google.golang.org/grpc/balancer_test.go:SA1019
|
|||
google.golang.org/grpc/clientconn_test.go:SA1019
|
||||
google.golang.org/grpc/balancer/roundrobin/roundrobin_test.go:SA1019
|
||||
google.golang.org/grpc/benchmark/benchmain/main.go:SA1019
|
||||
google.golang.org/grpc/benchmark/worker/benchmark_client.go:SA1019
|
||||
google.golang.org/grpc/internal/transport/handler_server.go:SA1019
|
||||
google.golang.org/grpc/internal/transport/handler_server_test.go:SA1019
|
||||
google.golang.org/grpc/stats/stats_test.go:SA1019
|
||||
|
|
Loading…
Reference in New Issue