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

Function translateMetadata

gcp/observability/logging.go:51–70  ·  view source on GitHub ↗

translateMetadata translates the metadata from Binary Logging format to its GrpcLogEntry equivalent.

(m *binlogpb.Metadata)

Source from the content-addressed store, hash-verified

49// translateMetadata translates the metadata from Binary Logging format to
50// its GrpcLogEntry equivalent.
51func translateMetadata(m *binlogpb.Metadata) map[string]string {
52 metadata := make(map[string]string)
53 for _, entry := range m.GetEntry() {
54 entryKey := entry.GetKey()
55 var newVal string
56 if strings.HasSuffix(entryKey, "-bin") { // bin header
57 newVal = base64.StdEncoding.EncodeToString(entry.GetValue())
58 } else { // normal header
59 newVal = string(entry.GetValue())
60 }
61 var oldVal string
62 var ok bool
63 if oldVal, ok = metadata[entryKey]; !ok {
64 metadata[entryKey] = newVal
65 continue
66 }
67 metadata[entryKey] = oldVal + "," + newVal
68 }
69 return metadata
70}
71
72func setPeerIfPresent(binlogEntry *binlogpb.GrpcLogEntry, grpcLogEntry *grpcLogEntry) {
73 if binlogEntry.GetPeer() != nil {

Callers 2

buildGCPLoggingEntryMethod · 0.85
TestTranslateMetadataMethod · 0.85

Calls 3

GetEntryMethod · 0.80
GetKeyMethod · 0.45
GetValueMethod · 0.45

Tested by 1

TestTranslateMetadataMethod · 0.68