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

Function ParseProtoReader

pkg/util/http.go:138–165  ·  view source on GitHub ↗

ParseProtoReader parses a compressed proto from an io.Reader.

(ctx context.Context, reader io.Reader, expectedSize, maxSize int, req proto.Message, compression CompressionType)

Source from the content-addressed store, hash-verified

136
137// ParseProtoReader parses a compressed proto from an io.Reader.
138func ParseProtoReader(ctx context.Context, reader io.Reader, expectedSize, maxSize int, req proto.Message, compression CompressionType) error {
139 sp := trace.SpanFromContext(ctx)
140 if sp != nil {
141 sp.SetAttributes(attribute.String("event", "util.ParseProtoRequest[start reading]"))
142 }
143 body, err := decompressRequest(reader, expectedSize, maxSize, compression, sp)
144 if err != nil {
145 return err
146 }
147
148 if sp != nil {
149 sp.SetAttributes(attribute.String("event", "util.ParseProtoRequest[unmarshal]"), attribute.Int("size", len(body)))
150 }
151
152 // We re-implement proto.Unmarshal here as it calls XXX_Unmarshal first,
153 // which we can't override without upsetting golint.
154 req.Reset()
155 if u, ok := req.(proto.Unmarshaler); ok {
156 err = u.Unmarshal(body)
157 } else {
158 err = proto.NewBuffer(body).Unmarshal(req)
159 }
160 if err != nil {
161 return err
162 }
163
164 return nil
165}
166
167func decompressRequest(reader io.Reader, expectedSize, maxSize int, compression CompressionType, sp trace.Span) (body []byte, err error) {
168 defer func() {

Callers

nothing calls this directly

Calls 5

decompressRequestFunction · 0.85
IntMethod · 0.80
ResetMethod · 0.65
UnmarshalMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected