MCPcopy Index your code
hub / github.com/cortexproject/cortex / ParseProtoReader

Function ParseProtoReader

pkg/util/http.go:153–180  ·  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

151
152// ParseProtoReader parses a compressed proto from an io.Reader.
153func ParseProtoReader(ctx context.Context, reader io.Reader, expectedSize, maxSize int, req proto.Message, compression CompressionType) error {
154 sp := opentracing.SpanFromContext(ctx)
155 if sp != nil {
156 sp.LogFields(otlog.String("event", "util.ParseProtoRequest[start reading]"))
157 }
158 body, err := decompressRequest(reader, expectedSize, maxSize, compression, sp)
159 if err != nil {
160 return err
161 }
162
163 if sp != nil {
164 sp.LogFields(otlog.String("event", "util.ParseProtoRequest[unmarshal]"), otlog.Int("size", len(body)))
165 }
166
167 // We re-implement proto.Unmarshal here as it calls XXX_Unmarshal first,
168 // which we can't override without upsetting golint.
169 req.Reset()
170 if u, ok := req.(proto.Unmarshaler); ok {
171 err = u.Unmarshal(body)
172 } else {
173 err = proto.NewBuffer(body).Unmarshal(req)
174 }
175 if err != nil {
176 return err
177 }
178
179 return nil
180}
181
182func decompressRequest(reader io.Reader, expectedSize, maxSize int, compression CompressionType, sp opentracing.Span) (body []byte, err error) {
183 defer func() {

Callers 8

RemoteReadHandlerFunction · 0.92
TestMarshallFunction · 0.92
TestParseProtoReaderFunction · 0.92
HandlerFunction · 0.92
runPRW2HandleFromPoolFunction · 0.92
runPRW2HandleFromScratchFunction · 0.92
decodeOTLPWriteRequestFunction · 0.92

Calls 5

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

Tested by 5

TestMarshallFunction · 0.74
TestParseProtoReaderFunction · 0.74
runPRW2HandleFromPoolFunction · 0.74
runPRW2HandleFromScratchFunction · 0.74