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

Function prepareMsg

stream.go:1887–1904  ·  view source on GitHub ↗

prepareMsg returns the hdr, payload and data using the compressors passed or using the passed preparedmsg. The returned boolean indicates whether compression was made and therefore whether the payload needs to be freed in addition to the returned data. Freeing the payload if the returned boolean is

(m any, codec baseCodec, cp Compressor, comp encoding.Compressor, pool mem.BufferPool)

Source from the content-addressed store, hash-verified

1885// addition to the returned data. Freeing the payload if the returned boolean is
1886// false can lead to undefined behavior.
1887func prepareMsg(m any, codec baseCodec, cp Compressor, comp encoding.Compressor, pool mem.BufferPool) (hdr []byte, data, payload mem.BufferSlice, pf payloadFormat, err error) {
1888 if preparedMsg, ok := m.(*PreparedMsg); ok {
1889 return preparedMsg.hdr, preparedMsg.encodedData, preparedMsg.payload, preparedMsg.pf, nil
1890 }
1891 // The input interface is not a prepared msg.
1892 // Marshal and Compress the data at this point
1893 data, err = encode(codec, m)
1894 if err != nil {
1895 return nil, nil, nil, 0, err
1896 }
1897 compData, pf, err := compress(data, cp, comp, pool)
1898 if err != nil {
1899 data.Free()
1900 return nil, nil, nil, 0, err
1901 }
1902 hdr, payload = msgHeader(data, compData, pf)
1903 return hdr, data, payload, pf, nil
1904}

Callers 3

SendMsgMethod · 0.85
SendMsgMethod · 0.85
SendMsgMethod · 0.85

Calls 4

encodeFunction · 0.85
compressFunction · 0.85
msgHeaderFunction · 0.85
FreeMethod · 0.65

Tested by

no test coverage detected