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

Method recvMsg

rpc_util.go:785–809  ·  view source on GitHub ↗

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: - io.EOF, when no messages remain - io.ErrUnexpectedEOF - of type transport.ConnectionErr

(maxReceiveMessageSize int)

Source from the content-addressed store, hash-verified

783// that the underlying streamReader must not return an incompatible
784// error.
785func (p *parser) recvMsg(maxReceiveMessageSize int) (payloadFormat, mem.BufferSlice, error) {
786 err := p.r.ReadMessageHeader(p.header[:])
787 if err != nil {
788 return 0, nil, err
789 }
790
791 pf := payloadFormat(p.header[0])
792 length := binary.BigEndian.Uint32(p.header[1:])
793
794 if int64(length) > int64(maxInt) {
795 return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max length allowed on current machine (%d vs. %d)", length, maxInt)
796 }
797 if int(length) > maxReceiveMessageSize {
798 return 0, nil, status.Errorf(codes.ResourceExhausted, "grpc: received message larger than max (%d vs. %d)", length, maxReceiveMessageSize)
799 }
800
801 data, err := p.r.Read(int(length))
802 if err != nil {
803 if err == io.EOF {
804 err = io.ErrUnexpectedEOF
805 }
806 return 0, nil, err
807 }
808 return pf, data, nil
809}
810
811// encode serializes msg and returns a buffer containing the message, or an
812// error if it is too large to be transmitted by grpc. If msg is nil, it

Callers 3

TestSimpleParsingMethod · 0.95
TestMultipleParsingMethod · 0.95
recvAndDecompressFunction · 0.45

Calls 4

ErrorfFunction · 0.92
payloadFormatTypeAlias · 0.85
ReadMessageHeaderMethod · 0.65
ReadMethod · 0.65

Tested by 2

TestSimpleParsingMethod · 0.76
TestMultipleParsingMethod · 0.76