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

Function SerializeProtoResponse

pkg/util/http.go:273–291  ·  view source on GitHub ↗

SerializeProtoResponse serializes a protobuf response into an HTTP response.

(w http.ResponseWriter, resp proto.Message, compression CompressionType)

Source from the content-addressed store, hash-verified

271
272// SerializeProtoResponse serializes a protobuf response into an HTTP response.
273func SerializeProtoResponse(w http.ResponseWriter, resp proto.Message, compression CompressionType) error {
274 data, err := proto.Marshal(resp)
275 if err != nil {
276 http.Error(w, err.Error(), http.StatusInternalServerError)
277 return fmt.Errorf("error marshaling proto response: %v", err)
278 }
279
280 switch compression {
281 case NoCompression:
282 case RawSnappy:
283 data = snappy.Encode(nil, data)
284 }
285
286 if _, err := w.Write(data); err != nil {
287 http.Error(w, err.Error(), http.StatusInternalServerError)
288 return fmt.Errorf("error sending proto response: %v", err)
289 }
290 return nil
291}

Callers 3

RemoteReadHandlerFunction · 0.92
TestMarshallFunction · 0.92
TestParseProtoReaderFunction · 0.92

Calls 4

EncodeMethod · 0.65
MarshalMethod · 0.45
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by 2

TestMarshallFunction · 0.74
TestParseProtoReaderFunction · 0.74