MCPcopy
hub / github.com/grpc/grpc-go / ToLoadReport

Function ToLoadReport

orca/internal/internal.go:58–71  ·  view source on GitHub ↗

ToLoadReport unmarshals a binary encoded [ORCA LoadReport] protobuf message from md and returns the corresponding struct. The load report is expected to be stored as the value for key "endpoint-load-metrics-bin". If no load report was found in the provided metadata, if multiple load reports are fou

(md metadata.MD)

Source from the content-addressed store, hash-verified

56//
57// [ORCA LoadReport]: (https://github.com/cncf/xds/blob/main/xds/data/orca/v3/orca_load_report.proto#L15)
58func ToLoadReport(md metadata.MD) (*v3orcapb.OrcaLoadReport, error) {
59 vs := md.Get(TrailerMetadataKey)
60 if len(vs) == 0 {
61 return nil, nil
62 }
63 if len(vs) != 1 {
64 return nil, errors.New("multiple orca load reports found in provided metadata")
65 }
66 ret := new(v3orcapb.OrcaLoadReport)
67 if err := proto.Unmarshal([]byte(vs[0]), ret); err != nil {
68 return nil, fmt.Errorf("failed to unmarshal load report found in metadata: %v", err)
69 }
70 return ret, nil
71}

Callers 4

TestToLoadReportMethod · 0.92
ParseMethod · 0.92

Calls 3

GetMethod · 0.65
UnmarshalMethod · 0.65
ErrorfMethod · 0.65

Tested by 3

TestToLoadReportMethod · 0.74