2017-04-17 18:08:24 -04:00
/ *
*
2018-06-08 05:26:10 -04:00
* Copyright 2014 gRPC authors .
2017-04-17 18:08:24 -04:00
*
2018-06-08 05:26:10 -04:00
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
2017-04-17 18:08:24 -04:00
*
2018-06-08 05:26:10 -04:00
* http : //www.apache.org/licenses/LICENSE-2.0
2017-04-17 18:08:24 -04:00
*
2018-06-08 05:26:10 -04:00
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
2017-04-17 18:08:24 -04:00
*
* /
package grpc
import (
"compress/gzip"
2019-04-12 14:36:17 -04:00
"context"
2017-04-17 18:08:24 -04:00
"encoding/binary"
2018-06-08 05:26:10 -04:00
"fmt"
2017-04-17 18:08:24 -04:00
"io"
"math"
2018-06-08 05:26:10 -04:00
"strings"
"sync"
2017-07-02 03:02:24 -04:00
"time"
2017-04-17 18:08:24 -04:00
"google.golang.org/grpc/codes"
2018-06-08 05:26:10 -04:00
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/encoding"
"google.golang.org/grpc/encoding/proto"
2019-04-12 14:36:17 -04:00
"google.golang.org/grpc/internal/transport"
2024-10-12 15:52:41 -04:00
"google.golang.org/grpc/mem"
2017-04-17 18:08:24 -04:00
"google.golang.org/grpc/metadata"
2017-07-02 03:02:24 -04:00
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
"google.golang.org/grpc/status"
2017-04-17 18:08:24 -04:00
)
// Compressor defines the interface gRPC uses to compress a message.
2018-06-08 05:26:10 -04:00
//
// Deprecated: use package encoding.
2017-04-17 18:08:24 -04:00
type Compressor interface {
// Do compresses p into w.
Do ( w io . Writer , p [ ] byte ) error
// Type returns the compression algorithm the Compressor uses.
Type ( ) string
}
2018-06-08 05:26:10 -04:00
type gzipCompressor struct {
pool sync . Pool
}
2017-04-17 18:08:24 -04:00
// NewGZIPCompressor creates a Compressor based on GZIP.
2018-06-08 05:26:10 -04:00
//
// Deprecated: use package encoding/gzip.
2017-04-17 18:08:24 -04:00
func NewGZIPCompressor ( ) Compressor {
2018-06-08 05:26:10 -04:00
c , _ := NewGZIPCompressorWithLevel ( gzip . DefaultCompression )
return c
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
// NewGZIPCompressorWithLevel is like NewGZIPCompressor but specifies the gzip compression level instead
// of assuming DefaultCompression.
//
// The error returned will be nil if the level is valid.
//
// Deprecated: use package encoding/gzip.
func NewGZIPCompressorWithLevel ( level int ) ( Compressor , error ) {
if level < gzip . DefaultCompression || level > gzip . BestCompression {
return nil , fmt . Errorf ( "grpc: invalid compression level: %d" , level )
}
return & gzipCompressor {
pool : sync . Pool {
2023-11-01 11:03:44 -04:00
New : func ( ) any {
2023-07-19 18:26:26 -04:00
w , err := gzip . NewWriterLevel ( io . Discard , level )
2018-06-08 05:26:10 -04:00
if err != nil {
panic ( err )
}
return w
} ,
} ,
} , nil
2017-04-17 18:08:24 -04:00
}
func ( c * gzipCompressor ) Do ( w io . Writer , p [ ] byte ) error {
2018-06-08 05:26:10 -04:00
z := c . pool . Get ( ) . ( * gzip . Writer )
defer c . pool . Put ( z )
z . Reset ( w )
2017-04-17 18:08:24 -04:00
if _ , err := z . Write ( p ) ; err != nil {
return err
}
return z . Close ( )
}
func ( c * gzipCompressor ) Type ( ) string {
return "gzip"
}
// Decompressor defines the interface gRPC uses to decompress a message.
2018-06-08 05:26:10 -04:00
//
// Deprecated: use package encoding.
2017-04-17 18:08:24 -04:00
type Decompressor interface {
// Do reads the data from r and uncompress them.
Do ( r io . Reader ) ( [ ] byte , error )
// Type returns the compression algorithm the Decompressor uses.
Type ( ) string
}
type gzipDecompressor struct {
2018-06-08 05:26:10 -04:00
pool sync . Pool
2017-04-17 18:08:24 -04:00
}
// NewGZIPDecompressor creates a Decompressor based on GZIP.
2018-06-08 05:26:10 -04:00
//
// Deprecated: use package encoding/gzip.
2017-04-17 18:08:24 -04:00
func NewGZIPDecompressor ( ) Decompressor {
return & gzipDecompressor { }
}
func ( d * gzipDecompressor ) Do ( r io . Reader ) ( [ ] byte , error ) {
2018-06-08 05:26:10 -04:00
var z * gzip . Reader
switch maybeZ := d . pool . Get ( ) . ( type ) {
case nil :
newZ , err := gzip . NewReader ( r )
if err != nil {
return nil , err
}
z = newZ
case * gzip . Reader :
z = maybeZ
if err := z . Reset ( r ) ; err != nil {
d . pool . Put ( z )
return nil , err
}
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
defer func ( ) {
z . Close ( )
d . pool . Put ( z )
} ( )
2023-07-19 18:26:26 -04:00
return io . ReadAll ( z )
2017-04-17 18:08:24 -04:00
}
func ( d * gzipDecompressor ) Type ( ) string {
return "gzip"
}
// callInfo contains all related configuration and information about an RPC.
type callInfo struct {
2018-06-08 05:26:10 -04:00
compressorType string
failFast bool
maxReceiveMessageSize * int
maxSendMessageSize * int
creds credentials . PerRPCCredentials
contentSubtype string
codec baseCodec
2019-04-12 14:36:17 -04:00
maxRetryRPCBufferSize int
2023-09-19 10:37:37 -04:00
onFinish [ ] func ( err error )
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
func defaultCallInfo ( ) * callInfo {
2019-04-12 14:36:17 -04:00
return & callInfo {
failFast : true ,
maxRetryRPCBufferSize : 256 * 1024 , // 256KB
}
2018-06-08 05:26:10 -04:00
}
2017-04-17 18:08:24 -04:00
// CallOption configures a Call before it starts or extracts information from
// a Call after it completes.
type CallOption interface {
// before is called before the call is sent to any server. If before
// returns a non-nil error, the RPC fails with that error.
before ( * callInfo ) error
// after is called after the call has completed. after cannot return an
// error, so any failures should be reported via output parameters.
2021-08-12 11:11:44 -04:00
after ( * callInfo , * csAttempt )
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
// EmptyCallOption does not alter the Call configuration.
// It can be embedded in another structure to carry satellite data for use
// by interceptors.
type EmptyCallOption struct { }
2017-04-17 18:08:24 -04:00
2021-08-12 11:11:44 -04:00
func ( EmptyCallOption ) before ( * callInfo ) error { return nil }
func ( EmptyCallOption ) after ( * callInfo , * csAttempt ) { }
2017-04-17 18:08:24 -04:00
2024-09-12 12:38:40 -04:00
// StaticMethod returns a CallOption which specifies that a call is being made
// to a method that is static, which means the method is known at compile time
// and doesn't change at runtime. This can be used as a signal to stats plugins
// that this method is safe to include as a key to a measurement.
func StaticMethod ( ) CallOption {
return StaticMethodCallOption { }
}
// StaticMethodCallOption is a CallOption that specifies that a call comes
// from a static method.
type StaticMethodCallOption struct {
EmptyCallOption
}
2017-04-17 18:08:24 -04:00
// Header returns a CallOptions that retrieves the header metadata
// for a unary RPC.
func Header ( md * metadata . MD ) CallOption {
2018-06-08 05:26:10 -04:00
return HeaderCallOption { HeaderAddr : md }
}
// HeaderCallOption is a CallOption for collecting response header metadata.
// The metadata field will be populated *after* the RPC completes.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type HeaderCallOption struct {
HeaderAddr * metadata . MD
}
2024-11-01 08:39:15 -04:00
func ( o HeaderCallOption ) before ( * callInfo ) error { return nil }
func ( o HeaderCallOption ) after ( _ * callInfo , attempt * csAttempt ) {
2021-08-12 11:11:44 -04:00
* o . HeaderAddr , _ = attempt . s . Header ( )
2017-04-17 18:08:24 -04:00
}
// Trailer returns a CallOptions that retrieves the trailer metadata
// for a unary RPC.
func Trailer ( md * metadata . MD ) CallOption {
2018-06-08 05:26:10 -04:00
return TrailerCallOption { TrailerAddr : md }
}
// TrailerCallOption is a CallOption for collecting response trailer metadata.
// The metadata field will be populated *after* the RPC completes.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type TrailerCallOption struct {
TrailerAddr * metadata . MD
}
2024-11-01 08:39:15 -04:00
func ( o TrailerCallOption ) before ( * callInfo ) error { return nil }
func ( o TrailerCallOption ) after ( _ * callInfo , attempt * csAttempt ) {
2021-08-12 11:11:44 -04:00
* o . TrailerAddr = attempt . s . Trailer ( )
2018-06-08 05:26:10 -04:00
}
// Peer returns a CallOption that retrieves peer information for a unary RPC.
// The peer field will be populated *after* the RPC completes.
func Peer ( p * peer . Peer ) CallOption {
return PeerCallOption { PeerAddr : p }
}
// PeerCallOption is a CallOption for collecting the identity of the remote
// peer. The peer field will be populated *after* the RPC completes.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type PeerCallOption struct {
PeerAddr * peer . Peer
2017-04-17 18:08:24 -04:00
}
2024-11-01 08:39:15 -04:00
func ( o PeerCallOption ) before ( * callInfo ) error { return nil }
func ( o PeerCallOption ) after ( _ * callInfo , attempt * csAttempt ) {
2021-08-12 11:11:44 -04:00
if x , ok := peer . FromContext ( attempt . s . Context ( ) ) ; ok {
* o . PeerAddr = * x
2018-06-08 05:26:10 -04:00
}
2017-07-02 03:02:24 -04:00
}
2024-10-12 15:52:41 -04:00
// WaitForReady configures the RPC's behavior when the client is in
// TRANSIENT_FAILURE, which occurs when all addresses fail to connect. If
// waitForReady is false, the RPC will fail immediately. Otherwise, the client
// will wait until a connection becomes available or the RPC's deadline is
// reached.
2018-06-08 05:26:10 -04:00
//
2024-10-12 15:52:41 -04:00
// By default, RPCs do not "wait for ready".
2019-04-12 14:36:17 -04:00
func WaitForReady ( waitForReady bool ) CallOption {
return FailFastCallOption { FailFast : ! waitForReady }
}
// FailFast is the opposite of WaitForReady.
//
// Deprecated: use WaitForReady.
2017-04-17 18:08:24 -04:00
func FailFast ( failFast bool ) CallOption {
2018-06-08 05:26:10 -04:00
return FailFastCallOption { FailFast : failFast }
}
// FailFastCallOption is a CallOption for indicating whether an RPC should fail
// fast or not.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type FailFastCallOption struct {
FailFast bool
}
func ( o FailFastCallOption ) before ( c * callInfo ) error {
c . failFast = o . FailFast
return nil
}
2024-11-01 08:39:15 -04:00
func ( o FailFastCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
2023-09-19 10:37:37 -04:00
// OnFinish returns a CallOption that configures a callback to be called when
// the call completes. The error passed to the callback is the status of the
// RPC, and may be nil. The onFinish callback provided will only be called once
// by gRPC. This is mainly used to be used by streaming interceptors, to be
// notified when the RPC completes along with information about the status of
// the RPC.
//
// # Experimental
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
func OnFinish ( onFinish func ( err error ) ) CallOption {
return OnFinishCallOption {
OnFinish : onFinish ,
}
}
// OnFinishCallOption is CallOption that indicates a callback to be called when
// the call completes.
//
// # Experimental
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
type OnFinishCallOption struct {
OnFinish func ( error )
}
func ( o OnFinishCallOption ) before ( c * callInfo ) error {
c . onFinish = append ( c . onFinish , o . OnFinish )
return nil
}
2024-11-01 08:39:15 -04:00
func ( o OnFinishCallOption ) after ( * callInfo , * csAttempt ) { }
2023-09-19 10:37:37 -04:00
2021-08-12 11:11:44 -04:00
// MaxCallRecvMsgSize returns a CallOption which sets the maximum message size
2023-07-19 18:26:26 -04:00
// in bytes the client can receive. If this is not set, gRPC uses the default
// 4MB.
2021-08-12 11:11:44 -04:00
func MaxCallRecvMsgSize ( bytes int ) CallOption {
return MaxRecvMsgSizeCallOption { MaxRecvMsgSize : bytes }
2018-06-08 05:26:10 -04:00
}
// MaxRecvMsgSizeCallOption is a CallOption that indicates the maximum message
2021-08-12 11:11:44 -04:00
// size in bytes the client can receive.
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type MaxRecvMsgSizeCallOption struct {
MaxRecvMsgSize int
}
func ( o MaxRecvMsgSizeCallOption ) before ( c * callInfo ) error {
c . maxReceiveMessageSize = & o . MaxRecvMsgSize
return nil
}
2024-11-01 08:39:15 -04:00
func ( o MaxRecvMsgSizeCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
2021-08-12 11:11:44 -04:00
// MaxCallSendMsgSize returns a CallOption which sets the maximum message size
2023-07-19 18:26:26 -04:00
// in bytes the client can send. If this is not set, gRPC uses the default
// `math.MaxInt32`.
2021-08-12 11:11:44 -04:00
func MaxCallSendMsgSize ( bytes int ) CallOption {
return MaxSendMsgSizeCallOption { MaxSendMsgSize : bytes }
2018-06-08 05:26:10 -04:00
}
// MaxSendMsgSizeCallOption is a CallOption that indicates the maximum message
2021-08-12 11:11:44 -04:00
// size in bytes the client can send.
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type MaxSendMsgSizeCallOption struct {
MaxSendMsgSize int
}
func ( o MaxSendMsgSizeCallOption ) before ( c * callInfo ) error {
c . maxSendMessageSize = & o . MaxSendMsgSize
return nil
}
2024-11-01 08:39:15 -04:00
func ( o MaxSendMsgSizeCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
// PerRPCCredentials returns a CallOption that sets credentials.PerRPCCredentials
// for a call.
func PerRPCCredentials ( creds credentials . PerRPCCredentials ) CallOption {
return PerRPCCredsCallOption { Creds : creds }
}
// PerRPCCredsCallOption is a CallOption that indicates the per-RPC
// credentials to use for the call.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type PerRPCCredsCallOption struct {
Creds credentials . PerRPCCredentials
}
func ( o PerRPCCredsCallOption ) before ( c * callInfo ) error {
c . creds = o . Creds
return nil
}
2024-11-01 08:39:15 -04:00
func ( o PerRPCCredsCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
// UseCompressor returns a CallOption which sets the compressor used when
// sending the request. If WithCompressor is also set, UseCompressor has
// higher priority.
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
func UseCompressor ( name string ) CallOption {
return CompressorCallOption { CompressorType : name }
}
// CompressorCallOption is a CallOption that indicates the compressor to use.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type CompressorCallOption struct {
CompressorType string
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
func ( o CompressorCallOption ) before ( c * callInfo ) error {
c . compressorType = o . CompressorType
return nil
}
2024-11-01 08:39:15 -04:00
func ( o CompressorCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
// CallContentSubtype returns a CallOption that will set the content-subtype
// for a call. For example, if content-subtype is "json", the Content-Type over
// the wire will be "application/grpc+json". The content-subtype is converted
// to lowercase before being included in Content-Type. See Content-Type on
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for
// more details.
//
2019-04-12 14:36:17 -04:00
// 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
2018-06-08 05:26:10 -04:00
// will result in an error with code codes.Internal.
//
2019-04-12 14:36:17 -04:00
// If ForceCodec is also used, that Codec will be used for all request and
2018-06-08 05:26:10 -04:00
// response messages, with the content-subtype set to the given contentSubtype
// here for requests.
func CallContentSubtype ( contentSubtype string ) CallOption {
return ContentSubtypeCallOption { ContentSubtype : strings . ToLower ( contentSubtype ) }
}
// ContentSubtypeCallOption is a CallOption that indicates the content-subtype
// used for marshaling messages.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type ContentSubtypeCallOption struct {
ContentSubtype string
}
func ( o ContentSubtypeCallOption ) before ( c * callInfo ) error {
c . contentSubtype = o . ContentSubtype
return nil
}
2024-11-01 08:39:15 -04:00
func ( o ContentSubtypeCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
2021-08-12 11:11:44 -04:00
// ForceCodec returns a CallOption that will set codec to be used for all
// request and response messages for a call. The result of calling Name() will
// be used as the content-subtype after converting to lowercase, unless
// CallContentSubtype is also used.
2018-06-08 05:26:10 -04:00
//
// See Content-Type on
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for
// more details. Also see the documentation on RegisterCodec and
// CallContentSubtype for more details on the interaction between Codec and
// content-subtype.
//
// This function is provided for advanced users; prefer to use only
// CallContentSubtype to select a registered codec instead.
2019-04-12 14:36:17 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
2019-04-12 14:36:17 -04:00
func ForceCodec ( codec encoding . Codec ) CallOption {
return ForceCodecCallOption { Codec : codec }
}
// ForceCodecCallOption is a CallOption that indicates the codec used for
// marshaling messages.
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2019-04-12 14:36:17 -04:00
type ForceCodecCallOption struct {
Codec encoding . Codec
}
func ( o ForceCodecCallOption ) before ( c * callInfo ) error {
2024-10-12 15:52:41 -04:00
c . codec = newCodecV1Bridge ( o . Codec )
2019-04-12 14:36:17 -04:00
return nil
}
2024-11-01 08:39:15 -04:00
func ( o ForceCodecCallOption ) after ( * callInfo , * csAttempt ) { }
2019-04-12 14:36:17 -04:00
2024-10-12 15:52:41 -04:00
// ForceCodecV2 returns a CallOption that will set codec to be used for all
// request and response messages for a call. The result of calling Name() will
// be used as the content-subtype after converting to lowercase, unless
// CallContentSubtype is also used.
//
// See Content-Type on
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for
// more details. Also see the documentation on RegisterCodec and
// CallContentSubtype for more details on the interaction between Codec and
// content-subtype.
//
// This function is provided for advanced users; prefer to use only
// CallContentSubtype to select a registered codec instead.
//
// # Experimental
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
func ForceCodecV2 ( codec encoding . CodecV2 ) CallOption {
return ForceCodecV2CallOption { CodecV2 : codec }
}
// ForceCodecV2CallOption is a CallOption that indicates the codec used for
// marshaling messages.
//
// # Experimental
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
type ForceCodecV2CallOption struct {
CodecV2 encoding . CodecV2
}
func ( o ForceCodecV2CallOption ) before ( c * callInfo ) error {
c . codec = o . CodecV2
return nil
}
2024-11-01 08:39:15 -04:00
func ( o ForceCodecV2CallOption ) after ( * callInfo , * csAttempt ) { }
2024-10-12 15:52:41 -04:00
2019-04-12 14:36:17 -04:00
// CallCustomCodec behaves like ForceCodec, but accepts a grpc.Codec instead of
// an encoding.Codec.
//
// Deprecated: use ForceCodec instead.
2018-06-08 05:26:10 -04:00
func CallCustomCodec ( codec Codec ) CallOption {
return CustomCodecCallOption { Codec : codec }
}
// CustomCodecCallOption is a CallOption that indicates the codec used for
// marshaling messages.
2019-04-12 14:36:17 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2018-06-08 05:26:10 -04:00
type CustomCodecCallOption struct {
Codec Codec
}
func ( o CustomCodecCallOption ) before ( c * callInfo ) error {
2024-10-12 15:52:41 -04:00
c . codec = newCodecV0Bridge ( o . Codec )
2018-06-08 05:26:10 -04:00
return nil
}
2024-11-01 08:39:15 -04:00
func ( o CustomCodecCallOption ) after ( * callInfo , * csAttempt ) { }
2018-06-08 05:26:10 -04:00
2019-04-12 14:36:17 -04:00
// MaxRetryRPCBufferSize returns a CallOption that limits the amount of memory
// used for buffering this RPC's requests for retry purposes.
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This API is EXPERIMENTAL and may be changed or removed in a
// later release.
2019-04-12 14:36:17 -04:00
func MaxRetryRPCBufferSize ( bytes int ) CallOption {
return MaxRetryRPCBufferSizeCallOption { bytes }
}
// MaxRetryRPCBufferSizeCallOption is a CallOption indicating the amount of
// memory to be used for caching this RPC for retry purposes.
2021-08-12 11:11:44 -04:00
//
2023-07-19 18:26:26 -04:00
// # Experimental
2021-08-12 11:11:44 -04:00
//
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
// later release.
2019-04-12 14:36:17 -04:00
type MaxRetryRPCBufferSizeCallOption struct {
MaxRetryRPCBufferSize int
}
func ( o MaxRetryRPCBufferSizeCallOption ) before ( c * callInfo ) error {
c . maxRetryRPCBufferSize = o . MaxRetryRPCBufferSize
return nil
}
2024-11-01 08:39:15 -04:00
func ( o MaxRetryRPCBufferSizeCallOption ) after ( * callInfo , * csAttempt ) { }
2019-04-12 14:36:17 -04:00
2017-04-17 18:08:24 -04:00
// The format of the payload: compressed or not?
type payloadFormat uint8
const (
2019-04-12 14:36:17 -04:00
compressionNone payloadFormat = 0 // no compression
compressionMade payloadFormat = 1 // compressed
2017-04-17 18:08:24 -04:00
)
2024-10-12 15:52:41 -04:00
func ( pf payloadFormat ) isCompressed ( ) bool {
return pf == compressionMade
}
type streamReader interface {
ReadHeader ( header [ ] byte ) error
Read ( n int ) ( mem . BufferSlice , error )
}
2017-04-17 18:08:24 -04:00
// parser reads complete gRPC messages from the underlying reader.
type parser struct {
// r is the underlying reader.
// See the comment on recvMsg for the permissible
// error types.
2024-10-12 15:52:41 -04:00
r streamReader
2017-04-17 18:08:24 -04:00
2018-06-08 05:26:10 -04:00
// The header of a gRPC message. Find more detail at
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md
2017-04-17 18:08:24 -04:00
header [ 5 ] byte
2023-11-01 11:03:44 -04:00
2024-10-12 15:52:41 -04:00
// bufferPool is the pool of shared receive buffers.
bufferPool mem . BufferPool
2017-04-17 18:08:24 -04:00
}
// recvMsg reads a complete gRPC message from the stream.
//
// It returns the message and its payload (compression/encoding)
// format. The caller owns the returned msg memory.
//
// If there is an error, possible values are:
2023-07-19 18:26:26 -04:00
// - io.EOF, when no messages remain
// - io.ErrUnexpectedEOF
// - of type transport.ConnectionError
// - an error from the status package
//
2017-04-17 18:08:24 -04:00
// No other error values or types must be returned, which also means
2024-10-12 15:52:41 -04:00
// that the underlying streamReader must not return an incompatible
2017-04-17 18:08:24 -04:00
// error.
2024-10-12 15:52:41 -04:00
func ( p * parser ) recvMsg ( maxReceiveMessageSize int ) ( payloadFormat , mem . BufferSlice , error ) {
err := p . r . ReadHeader ( p . header [ : ] )
if err != nil {
2017-04-17 18:08:24 -04:00
return 0 , nil , err
}
2024-10-12 15:52:41 -04:00
pf := payloadFormat ( p . header [ 0 ] )
2017-04-17 18:08:24 -04:00
length := binary . BigEndian . Uint32 ( p . header [ 1 : ] )
if length == 0 {
return pf , nil , nil
}
2018-06-08 05:26:10 -04:00
if int64 ( length ) > int64 ( maxInt ) {
return 0 , nil , status . Errorf ( codes . ResourceExhausted , "grpc: received message larger than max length allowed on current machine (%d vs. %d)" , length , maxInt )
}
if int ( length ) > maxReceiveMessageSize {
return 0 , nil , status . Errorf ( codes . ResourceExhausted , "grpc: received message larger than max (%d vs. %d)" , length , maxReceiveMessageSize )
2017-04-17 18:08:24 -04:00
}
2024-10-12 15:52:41 -04:00
data , err := p . r . Read ( int ( length ) )
if err != nil {
2017-04-17 18:08:24 -04:00
if err == io . EOF {
err = io . ErrUnexpectedEOF
}
return 0 , nil , err
}
2024-10-12 15:52:41 -04:00
return pf , data , nil
2017-04-17 18:08:24 -04:00
}
2019-04-12 14:36:17 -04:00
// encode serializes msg and returns a buffer containing the message, or an
// error if it is too large to be transmitted by grpc. If msg is nil, it
// generates an empty message.
2024-10-12 15:52:41 -04:00
func encode ( c baseCodec , msg any ) ( mem . BufferSlice , error ) {
2019-04-12 14:36:17 -04:00
if msg == nil { // NOTE: typed nils will not be caught by this check
return nil , nil
}
b , err := c . Marshal ( msg )
if err != nil {
return nil , status . Errorf ( codes . Internal , "grpc: error while marshaling: %v" , err . Error ( ) )
}
2024-10-12 15:52:41 -04:00
if uint ( b . Len ( ) ) > math . MaxUint32 {
b . Free ( )
2019-04-12 14:36:17 -04:00
return nil , status . Errorf ( codes . ResourceExhausted , "grpc: message too large (%d bytes)" , len ( b ) )
}
return b , nil
}
2024-09-12 12:38:40 -04:00
// compress returns the input bytes compressed by compressor or cp.
// If both compressors are nil, or if the message has zero length, returns nil,
// indicating no compression was done.
2019-04-12 14:36:17 -04:00
//
// TODO(dfawley): eliminate cp parameter by wrapping Compressor in an encoding.Compressor.
2024-10-12 15:52:41 -04:00
func compress ( in mem . BufferSlice , cp Compressor , compressor encoding . Compressor , pool mem . BufferPool ) ( mem . BufferSlice , payloadFormat , error ) {
if ( compressor == nil && cp == nil ) || in . Len ( ) == 0 {
return nil , compressionNone , nil
2024-09-12 12:38:40 -04:00
}
2024-10-12 15:52:41 -04:00
var out mem . BufferSlice
w := mem . NewWriter ( & out , pool )
2019-04-12 14:36:17 -04:00
wrapErr := func ( err error ) error {
2024-10-12 15:52:41 -04:00
out . Free ( )
2019-04-12 14:36:17 -04:00
return status . Errorf ( codes . Internal , "grpc: error while compressing: %v" , err . Error ( ) )
}
if compressor != nil {
2024-10-12 15:52:41 -04:00
z , err := compressor . Compress ( w )
2017-04-17 18:08:24 -04:00
if err != nil {
2024-10-12 15:52:41 -04:00
return nil , 0 , wrapErr ( err )
2017-04-17 18:08:24 -04:00
}
2024-10-12 15:52:41 -04:00
for _ , b := range in {
if _ , err := z . Write ( b . ReadOnlyData ( ) ) ; err != nil {
return nil , 0 , wrapErr ( err )
}
2017-07-02 03:02:24 -04:00
}
2019-04-12 14:36:17 -04:00
if err := z . Close ( ) ; err != nil {
2024-10-12 15:52:41 -04:00
return nil , 0 , wrapErr ( err )
2019-04-12 14:36:17 -04:00
}
} else {
2024-10-12 15:52:41 -04:00
// This is obviously really inefficient since it fully materializes the data, but
// there is no way around this with the old Compressor API. At least it attempts
// to return the buffer to the provider, in the hopes it can be reused (maybe
// even by a subsequent call to this very function).
buf := in . MaterializeToBuffer ( pool )
defer buf . Free ( )
if err := cp . Do ( w , buf . ReadOnlyData ( ) ) ; err != nil {
return nil , 0 , wrapErr ( err )
2017-04-17 18:08:24 -04:00
}
}
2024-10-12 15:52:41 -04:00
return out , compressionMade , nil
2019-04-12 14:36:17 -04:00
}
2017-04-17 18:08:24 -04:00
2019-04-12 14:36:17 -04:00
const (
payloadLen = 1
sizeLen = 4
headerLen = payloadLen + sizeLen
)
// msgHeader returns a 5-byte header for the message being transmitted and the
// payload, which is compData if non-nil or data otherwise.
2024-10-12 15:52:41 -04:00
func msgHeader ( data , compData mem . BufferSlice , pf payloadFormat ) ( hdr [ ] byte , payload mem . BufferSlice ) {
2019-04-12 14:36:17 -04:00
hdr = make ( [ ] byte , headerLen )
2024-10-12 15:52:41 -04:00
hdr [ 0 ] = byte ( pf )
var length uint32
if pf . isCompressed ( ) {
length = uint32 ( compData . Len ( ) )
payload = compData
2017-04-17 18:08:24 -04:00
} else {
2024-10-12 15:52:41 -04:00
length = uint32 ( data . Len ( ) )
payload = data
2017-04-17 18:08:24 -04:00
}
2019-04-12 14:36:17 -04:00
// Write length of payload into buf
2024-10-12 15:52:41 -04:00
binary . BigEndian . PutUint32 ( hdr [ payloadLen : ] , length )
return hdr , payload
2019-04-12 14:36:17 -04:00
}
2024-10-12 15:52:41 -04:00
func outPayload ( client bool , msg any , dataLength , payloadLength int , t time . Time ) * stats . OutPayload {
2019-04-12 14:36:17 -04:00
return & stats . OutPayload {
2023-09-19 10:37:37 -04:00
Client : client ,
Payload : msg ,
2024-10-12 15:52:41 -04:00
Length : dataLength ,
WireLength : payloadLength + headerLen ,
CompressedLength : payloadLength ,
2023-09-19 10:37:37 -04:00
SentTime : t ,
2017-07-02 03:02:24 -04:00
}
2017-04-17 18:08:24 -04:00
}
2024-10-12 15:52:41 -04:00
func checkRecvPayload ( pf payloadFormat , recvCompress string , haveCompressor bool , isServer bool ) * status . Status {
2017-04-17 18:08:24 -04:00
switch pf {
case compressionNone :
case compressionMade :
2018-06-08 05:26:10 -04:00
if recvCompress == "" || recvCompress == encoding . Identity {
return status . New ( codes . Internal , "grpc: compressed flag set with identity or empty encoding" )
}
if ! haveCompressor {
2024-10-12 15:52:41 -04:00
if isServer {
return status . Newf ( codes . Unimplemented , "grpc: Decompressor is not installed for grpc-encoding %q" , recvCompress )
} else {
return status . Newf ( codes . Internal , "grpc: Decompressor is not installed for grpc-encoding %q" , recvCompress )
}
2017-04-17 18:08:24 -04:00
}
default :
2018-06-08 05:26:10 -04:00
return status . Newf ( codes . Internal , "grpc: received unexpected payload format %d" , pf )
2017-04-17 18:08:24 -04:00
}
return nil
}
2019-04-12 14:36:17 -04:00
type payloadInfo struct {
2023-09-19 10:37:37 -04:00
compressedLength int // The compressed length got from wire.
2024-10-12 15:52:41 -04:00
uncompressedBytes mem . BufferSlice
}
func ( p * payloadInfo ) free ( ) {
if p != nil && p . uncompressedBytes != nil {
p . uncompressedBytes . Free ( )
}
2019-04-12 14:36:17 -04:00
}
2024-10-12 15:52:41 -04:00
// recvAndDecompress reads a message from the stream, decompressing it if necessary.
//
// Cancelling the returned cancel function releases the buffer back to the pool. So the caller should cancel as soon as
// the buffer is no longer needed.
// TODO: Refactor this function to reduce the number of arguments.
// See: https://google.github.io/styleguide/go/best-practices.html#function-argument-lists
func recvAndDecompress ( p * parser , s * transport . Stream , dc Decompressor , maxReceiveMessageSize int , payInfo * payloadInfo , compressor encoding . Compressor , isServer bool ,
) ( out mem . BufferSlice , err error ) {
pf , compressed , err := p . recvMsg ( maxReceiveMessageSize )
2017-04-17 18:08:24 -04:00
if err != nil {
2019-04-12 14:36:17 -04:00
return nil , err
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
2024-10-12 15:52:41 -04:00
compressedLength := compressed . Len ( )
if st := checkRecvPayload ( pf , s . RecvCompress ( ) , compressor != nil || dc != nil , isServer ) ; st != nil {
compressed . Free ( )
2019-04-12 14:36:17 -04:00
return nil , st . Err ( )
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
2020-04-16 10:34:35 -04:00
var size int
2024-10-12 15:52:41 -04:00
if pf . isCompressed ( ) {
defer compressed . Free ( )
2018-06-08 05:26:10 -04:00
// To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor,
// use this decompressor as the default.
if dc != nil {
2024-10-12 15:52:41 -04:00
var uncompressedBuf [ ] byte
uncompressedBuf , err = dc . Do ( compressed . Reader ( ) )
if err == nil {
out = mem . BufferSlice { mem . NewBuffer ( & uncompressedBuf , nil ) }
}
size = len ( uncompressedBuf )
2018-06-08 05:26:10 -04:00
} else {
2024-10-12 15:52:41 -04:00
out , size , err = decompress ( compressor , compressed , maxReceiveMessageSize , p . bufferPool )
2017-04-17 18:08:24 -04:00
}
2020-04-16 10:34:35 -04:00
if err != nil {
2023-07-19 18:26:26 -04:00
return nil , status . Errorf ( codes . Internal , "grpc: failed to decompress the received message: %v" , err )
2020-04-16 10:34:35 -04:00
}
2022-03-24 08:21:41 -04:00
if size > maxReceiveMessageSize {
2024-10-12 15:52:41 -04:00
out . Free ( )
2022-03-24 08:21:41 -04:00
// TODO: Revisit the error code. Currently keep it consistent with java
// implementation.
return nil , status . Errorf ( codes . ResourceExhausted , "grpc: received message after decompression larger than max (%d vs. %d)" , size , maxReceiveMessageSize )
}
2024-10-12 15:52:41 -04:00
} else {
out = compressed
2019-04-12 14:36:17 -04:00
}
2024-10-12 15:52:41 -04:00
if payInfo != nil {
payInfo . compressedLength = compressedLength
out . Ref ( )
payInfo . uncompressedBytes = out
}
return out , nil
2019-04-12 14:36:17 -04:00
}
2020-04-16 10:34:35 -04:00
// Using compressor, decompress d, returning data and size.
// Optionally, if data will be over maxReceiveMessageSize, just return the size.
2024-10-12 15:52:41 -04:00
func decompress ( compressor encoding . Compressor , d mem . BufferSlice , maxReceiveMessageSize int , pool mem . BufferPool ) ( mem . BufferSlice , int , error ) {
dcReader , err := compressor . Decompress ( d . Reader ( ) )
2020-04-16 10:34:35 -04:00
if err != nil {
return nil , 0 , err
}
2024-10-12 15:52:41 -04:00
// TODO: Can/should this still be preserved with the new BufferSlice API? Are
// there any actual benefits to allocating a single large buffer instead of
// multiple smaller ones?
//if sizer, ok := compressor.(interface {
// DecompressedSize(compressedBytes []byte) int
//}); ok {
// if size := sizer.DecompressedSize(d); size >= 0 {
// if size > maxReceiveMessageSize {
// return nil, size, nil
// }
// // size is used as an estimate to size the buffer, but we
// // will read more data if available.
// // +MinRead so ReadFrom will not reallocate if size is correct.
// //
// // TODO: If we ensure that the buffer size is the same as the DecompressedSize,
// // we can also utilize the recv buffer pool here.
// buf := bytes.NewBuffer(make([]byte, 0, size+bytes.MinRead))
// bytesRead, err := buf.ReadFrom(io.LimitReader(dcReader, int64(maxReceiveMessageSize)+1))
// return buf.Bytes(), int(bytesRead), err
// }
//}
var out mem . BufferSlice
_ , err = io . Copy ( mem . NewWriter ( & out , pool ) , io . LimitReader ( dcReader , int64 ( maxReceiveMessageSize ) + 1 ) )
if err != nil {
out . Free ( )
return nil , 0 , err
2020-04-16 10:34:35 -04:00
}
2024-10-12 15:52:41 -04:00
return out , out . Len ( ) , nil
2020-04-16 10:34:35 -04:00
}
2019-04-12 14:36:17 -04:00
// For the two compressor parameters, both should not be set, but if they are,
// dc takes precedence over compressor.
// TODO(dfawley): wrap the old compressor/decompressor using the new API?
2024-10-12 15:52:41 -04:00
func recv ( p * parser , c baseCodec , s * transport . Stream , dc Decompressor , m any , maxReceiveMessageSize int , payInfo * payloadInfo , compressor encoding . Compressor , isServer bool ) error {
data , err := recvAndDecompress ( p , s , dc , maxReceiveMessageSize , payInfo , compressor , isServer )
2019-04-12 14:36:17 -04:00
if err != nil {
return err
2017-04-17 18:08:24 -04:00
}
2024-10-12 15:52:41 -04:00
// If the codec wants its own reference to the data, it can get it. Otherwise, always
// free the buffers.
defer data . Free ( )
if err := c . Unmarshal ( data , m ) ; err != nil {
2023-07-19 18:26:26 -04:00
return status . Errorf ( codes . Internal , "grpc: failed to unmarshal the received message: %v" , err )
2017-04-17 18:08:24 -04:00
}
2024-10-12 15:52:41 -04:00
2017-04-17 18:08:24 -04:00
return nil
}
2019-10-02 13:42:55 -04:00
// Information about RPC
2017-07-02 03:02:24 -04:00
type rpcInfo struct {
2019-10-02 13:42:55 -04:00
failfast bool
preloaderInfo * compressorInfo
}
// Information about Preloader
// Responsible for storing codec, and compressors
// If stream (s) has context s.Context which stores rpcInfo that has non nil
// pointers to codec, and compressors, then we can use preparedMsg for Async message prep
// and reuse marshalled bytes
type compressorInfo struct {
codec baseCodec
cp Compressor
comp encoding . Compressor
2017-07-02 03:02:24 -04:00
}
type rpcInfoContextKey struct { }
2019-10-02 13:42:55 -04:00
func newContextWithRPCInfo ( ctx context . Context , failfast bool , codec baseCodec , cp Compressor , comp encoding . Compressor ) context . Context {
return context . WithValue ( ctx , rpcInfoContextKey { } , & rpcInfo {
failfast : failfast ,
preloaderInfo : & compressorInfo {
codec : codec ,
cp : cp ,
comp : comp ,
} ,
} )
2017-07-02 03:02:24 -04:00
}
func rpcInfoFromContext ( ctx context . Context ) ( s * rpcInfo , ok bool ) {
s , ok = ctx . Value ( rpcInfoContextKey { } ) . ( * rpcInfo )
return
2017-04-17 18:08:24 -04:00
}
// Code returns the error code for err if it was produced by the rpc system.
// Otherwise, it returns codes.Unknown.
2017-07-02 03:02:24 -04:00
//
2019-04-12 14:36:17 -04:00
// Deprecated: use status.Code instead.
2017-04-17 18:08:24 -04:00
func Code ( err error ) codes . Code {
2019-04-12 14:36:17 -04:00
return status . Code ( err )
2017-04-17 18:08:24 -04:00
}
// ErrorDesc returns the error description of err if it was produced by the rpc system.
// Otherwise, it returns err.Error() or empty string when err is nil.
2017-07-02 03:02:24 -04:00
//
2019-04-12 14:36:17 -04:00
// Deprecated: use status.Convert and Message method instead.
2017-04-17 18:08:24 -04:00
func ErrorDesc ( err error ) string {
2019-04-12 14:36:17 -04:00
return status . Convert ( err ) . Message ( )
2017-04-17 18:08:24 -04:00
}
// Errorf returns an error containing an error code and a description;
// Errorf returns nil if c is OK.
2017-07-02 03:02:24 -04:00
//
2018-06-08 05:26:10 -04:00
// Deprecated: use status.Errorf instead.
2023-11-01 11:03:44 -04:00
func Errorf ( c codes . Code , format string , a ... any ) error {
2017-07-02 03:02:24 -04:00
return status . Errorf ( c , format , a ... )
2017-04-17 18:08:24 -04:00
}
2023-11-01 11:03:44 -04:00
var errContextCanceled = status . Error ( codes . Canceled , context . Canceled . Error ( ) )
var errContextDeadline = status . Error ( codes . DeadlineExceeded , context . DeadlineExceeded . Error ( ) )
2019-04-12 14:36:17 -04:00
// toRPCErr converts an error into an error from the status package.
func toRPCErr ( err error ) error {
2022-03-24 08:21:41 -04:00
switch err {
case nil , io . EOF :
2019-04-12 14:36:17 -04:00
return err
2022-03-24 08:21:41 -04:00
case context . DeadlineExceeded :
2023-11-01 11:03:44 -04:00
return errContextDeadline
2022-03-24 08:21:41 -04:00
case context . Canceled :
2023-11-01 11:03:44 -04:00
return errContextCanceled
2022-03-24 08:21:41 -04:00
case io . ErrUnexpectedEOF :
2019-04-12 14:36:17 -04:00
return status . Error ( codes . Internal , err . Error ( ) )
}
2022-03-24 08:21:41 -04:00
2019-04-12 14:36:17 -04:00
switch e := err . ( type ) {
case transport . ConnectionError :
return status . Error ( codes . Unavailable , e . Desc )
2022-03-24 08:21:41 -04:00
case * transport . NewStreamError :
return toRPCErr ( e . Err )
2019-04-12 14:36:17 -04:00
}
2022-03-24 08:21:41 -04:00
if _ , ok := status . FromError ( err ) ; ok {
return err
}
2019-04-12 14:36:17 -04:00
return status . Error ( codes . Unknown , err . Error ( ) )
}
2018-06-08 05:26:10 -04:00
// setCallInfoCodec should only be called after CallOptions have been applied.
func setCallInfoCodec ( c * callInfo ) error {
if c . codec != nil {
2021-08-12 11:11:44 -04:00
// codec was already set by a CallOption; use it, but set the content
// subtype if it is not set.
if c . contentSubtype == "" {
// c.codec is a baseCodec to hide the difference between grpc.Codec and
// encoding.Codec (Name vs. String method name). We only support
// setting content subtype from encoding.Codec to avoid a behavior
// change with the deprecated version.
2024-10-12 15:52:41 -04:00
if ec , ok := c . codec . ( encoding . CodecV2 ) ; ok {
2021-08-12 11:11:44 -04:00
c . contentSubtype = strings . ToLower ( ec . Name ( ) )
}
}
2018-06-08 05:26:10 -04:00
return nil
2017-07-02 03:02:24 -04:00
}
2018-06-08 05:26:10 -04:00
if c . contentSubtype == "" {
// No codec specified in CallOptions; use proto by default.
2024-10-12 15:52:41 -04:00
c . codec = getCodec ( proto . Name )
2018-06-08 05:26:10 -04:00
return nil
}
// c.contentSubtype is already lowercased in CallContentSubtype
2024-10-12 15:52:41 -04:00
c . codec = getCodec ( c . contentSubtype )
2018-06-08 05:26:10 -04:00
if c . codec == nil {
return status . Errorf ( codes . Internal , "no codec registered for content-subtype %s" , c . contentSubtype )
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
return nil
2017-04-17 18:08:24 -04:00
}
2018-06-08 05:26:10 -04:00
// The SupportPackageIsVersion variables are referenced from generated protocol
// buffer files to ensure compatibility with the gRPC version used. The latest
2024-10-12 15:52:41 -04:00
// support package version is 9.
2018-06-08 05:26:10 -04:00
//
2021-08-12 11:11:44 -04:00
// Older versions are kept for compatibility.
2017-04-17 18:08:24 -04:00
//
2018-06-08 05:26:10 -04:00
// These constants should not be referenced from any other code.
const (
SupportPackageIsVersion3 = true
SupportPackageIsVersion4 = true
SupportPackageIsVersion5 = true
2020-04-16 10:34:35 -04:00
SupportPackageIsVersion6 = true
2021-08-12 11:11:44 -04:00
SupportPackageIsVersion7 = true
2024-09-12 12:38:40 -04:00
SupportPackageIsVersion8 = true
2024-10-12 15:52:41 -04:00
SupportPackageIsVersion9 = true
2018-06-08 05:26:10 -04:00
)
2017-07-02 03:02:24 -04:00
const grpcUA = "grpc-go/" + Version