MCPcopy
hub / github.com/grafana/tempo / decompressFromBuffer

Function decompressFromBuffer

pkg/util/http.go:211–237  ·  pkg/util/http.go::decompressFromBuffer
(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp trace.Span)

Source from the content-addressed store, hash-verified

209}
210
211func decompressFromBuffer(buffer *bytes.Buffer, maxSize int, compression CompressionType, sp trace.Span) ([]byte, error) {
212 if len(buffer.Bytes()) > maxSize {
213 return nil, fmt.Errorf(messageSizeLargerErrFmt, len(buffer.Bytes()), maxSize)
214 }
215 switch compression {
216 case NoCompression:
217 return buffer.Bytes(), nil
218 case RawSnappy:
219 if sp != nil {
220 sp.SetAttributes(attribute.String("event", "util.ParseProtoRequest[decompress]"),
221 attribute.Int("size", len(buffer.Bytes())))
222 }
223 size, err := snappy.DecodedLen(buffer.Bytes())
224 if err != nil {
225 return nil, err
226 }
227 if size > maxSize {
228 return nil, fmt.Errorf(messageSizeLargerErrFmt, size, maxSize)
229 }
230 body, err := snappy.Decode(nil, buffer.Bytes())
231 if err != nil {
232 return nil, err
233 }
234 return body, nil
235 }
236 return nil, nil
237}
238
239// tryBufferFromReader attempts to cast the reader to a `*bytes.Buffer` this is possible when using httpgrpc.
240// If it fails it will return nil and false.

Callers 2

decompressRequestFunction · 0.85
decompressFromReaderFunction · 0.85

Calls 4

BytesMethod · 0.80
IntMethod · 0.80
DecodeMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected