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

Function encode

rpc_util.go:814–827  ·  view source on GitHub ↗

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.

(c baseCodec, msg any)

Source from the content-addressed store, hash-verified

812// error if it is too large to be transmitted by grpc. If msg is nil, it
813// generates an empty message.
814func encode(c baseCodec, msg any) (mem.BufferSlice, error) {
815 if msg == nil { // NOTE: typed nils will not be caught by this check
816 return nil, nil
817 }
818 b, err := c.Marshal(msg)
819 if err != nil {
820 return nil, status.Errorf(codes.Internal, "grpc: error while marshaling: %v", err.Error())
821 }
822 if bufSize := uint(b.Len()); bufSize > math.MaxUint32 {
823 b.Free()
824 return nil, status.Errorf(codes.ResourceExhausted, "grpc: message too large (%d bytes)", bufSize)
825 }
826 return b, nil
827}
828
829// compress returns the input bytes compressed by compressor or cp.
830// If both compressors are nil, or if the message has zero length, returns nil,

Callers 5

sendResponseMethod · 0.85
EncodeMethod · 0.85
prepareMsgFunction · 0.85
TestEncodeMethod · 0.85
bmEncodeFunction · 0.85

Calls 5

ErrorfFunction · 0.92
MarshalMethod · 0.65
ErrorMethod · 0.65
LenMethod · 0.65
FreeMethod · 0.65

Tested by 2

TestEncodeMethod · 0.68
bmEncodeFunction · 0.68