MCPcopy
hub / github.com/connectrpc/connect-go / Write

Method Write

envelope.go:158–179  ·  view source on GitHub ↗

Write writes the enveloped message, compressing as necessary. It doesn't retain any references to the supplied envelope or its underlying data.

(env *envelope)

Source from the content-addressed store, hash-verified

156// Write writes the enveloped message, compressing as necessary. It doesn't
157// retain any references to the supplied envelope or its underlying data.
158func (w *envelopeWriter) Write(env *envelope) *Error {
159 if env.IsSet(flagEnvelopeCompressed) ||
160 w.compressionPool == nil ||
161 env.Data.Len() < w.compressMinBytes {
162 if w.sendMaxBytes > 0 && env.Data.Len() > w.sendMaxBytes {
163 return errorf(CodeResourceExhausted, "message size %d exceeds sendMaxBytes %d", env.Data.Len(), w.sendMaxBytes)
164 }
165 return w.write(env)
166 }
167 data := w.bufferPool.Get()
168 defer w.bufferPool.Put(data)
169 if err := w.compressionPool.Compress(data, env.Data); err != nil {
170 return err
171 }
172 if w.sendMaxBytes > 0 && data.Len() > w.sendMaxBytes {
173 return errorf(CodeResourceExhausted, "compressed message size %d exceeds sendMaxBytes %d", data.Len(), w.sendMaxBytes)
174 }
175 return w.write(&envelope{
176 Data: data,
177 Flags: env.Flags | flagEnvelopeCompressed,
178 })
179}
180
181func (w *envelopeWriter) marshalAppend(message any, codec marshalAppender) *Error {
182 // Codec supports MarshalAppend; try to re-use a []byte from the pool.

Callers 10

marshalAppendMethod · 0.95
marshalMethod · 0.95
TestEnvelopeFunction · 0.95
MarshalWebTrailersMethod · 0.45
TestHTTPCallGetBodyFunction · 0.45
WriteToMethod · 0.45
BenchmarkRESTFunction · 0.45
CloseMethod · 0.45
MarshalEndStreamMethod · 0.45

Calls 7

writeMethod · 0.95
errorfFunction · 0.85
IsSetMethod · 0.80
PutMethod · 0.80
CompressMethod · 0.80
LenMethod · 0.65
GetMethod · 0.65

Tested by 4

TestEnvelopeFunction · 0.76
TestHTTPCallGetBodyFunction · 0.36
BenchmarkRESTFunction · 0.36