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

Function recvAndDecompress

rpc_util.go:944–976  ·  view source on GitHub ↗

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:

(p *parser, s recvCompressor, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor, isServer bool)

Source from the content-addressed store, hash-verified

942// TODO: Refactor this function to reduce the number of arguments.
943// See: https://google.github.io/styleguide/go/best-practices.html#function-argument-lists
944func recvAndDecompress(p *parser, s recvCompressor, dc Decompressor, maxReceiveMessageSize int, payInfo *payloadInfo, compressor encoding.Compressor, isServer bool) (out mem.BufferSlice, err error) {
945 pf, compressed, err := p.recvMsg(maxReceiveMessageSize)
946 if err != nil {
947 return nil, err
948 }
949
950 compressedLength := compressed.Len()
951
952 if st := checkRecvPayload(pf, s.RecvCompress(), compressor != nil || dc != nil, isServer); st != nil {
953 compressed.Free()
954 return nil, st.Err()
955 }
956
957 if pf.isCompressed() {
958 defer compressed.Free()
959 // To match legacy behavior, if the decompressor is set by WithDecompressor or RPCDecompressor,
960 // use this decompressor as the default.
961 out, err = decompress(compressor, compressed, dc, maxReceiveMessageSize, p.bufferPool)
962 if err != nil {
963 return nil, err
964 }
965 } else {
966 out = compressed
967 }
968
969 if payInfo != nil {
970 payInfo.compressedLength = compressedLength
971 out.Ref()
972 payInfo.uncompressedBytes = out
973 }
974
975 return out, nil
976}
977
978// decompress processes the given data by decompressing it using either
979// a custom decompressor or a standard compressor. If a custom decompressor

Callers 2

processUnaryRPCMethod · 0.85
recvFunction · 0.85

Calls 9

checkRecvPayloadFunction · 0.85
decompressFunction · 0.85
ErrMethod · 0.80
isCompressedMethod · 0.80
LenMethod · 0.65
RecvCompressMethod · 0.65
FreeMethod · 0.65
RefMethod · 0.65
recvMsgMethod · 0.45

Tested by

no test coverage detected