MCPcopy
hub / github.com/grpc/grpc-go / SetSendCompressor

Function SetSendCompressor

server.go:2155–2166  ·  view source on GitHub ↗

SetSendCompressor sets a compressor for outbound messages from the server. It must not be called after any event that causes headers to be sent (see ServerStream.SetHeader for the complete list). Provided compressor is used when below conditions are met: - compressor is registered via encoding.Regi

(ctx context.Context, name string)

Source from the content-addressed store, hash-verified

2153// Notice: This function is EXPERIMENTAL and may be changed or removed in a
2154// later release.
2155func SetSendCompressor(ctx context.Context, name string) error {
2156 stream, ok := ServerTransportStreamFromContext(ctx).(*transport.ServerStream)
2157 if !ok || stream == nil {
2158 return fmt.Errorf("failed to fetch the stream from the given context")
2159 }
2160
2161 if err := validateSendCompressor(name, stream.ClientAdvertisedCompressors()); err != nil {
2162 return fmt.Errorf("unable to set send compressor: %w", err)
2163 }
2164
2165 return stream.SetSendCompress(name)
2166}
2167
2168// ClientSupportedCompressors returns compressor names advertised by the client
2169// via grpc-accept-encoding header.

Calls 5

validateSendCompressorFunction · 0.85
SetSendCompressMethod · 0.80
ErrorfMethod · 0.65