22
return data
23
}
25
>
decodePayloadsRecursive(parsed, encoder)
26
>
result, err := json.Marshal(parsed)
27
>
if err != nil {
28
return data
29
}
31
}
32
33
>
func decodePayloadsRecursive(v any, encoder codec.JSONPBEncoder) {
proto_decoder.go
34
>
switch val := v.(type) {
35
>
case map[string]any:
36
>
tryDecodePayloadJSON(val, encoder)
37
>
for _, child := range val {
38
>
decodePayloadsRecursive(child, encoder)
39
>
}
40
>
case []any:
41
>
for _, item := range val {
42
>
decodePayloadsRecursive(item, encoder)
43
>
}
44
>
default:
45
// Other types don't need decoding.
46
}
47
}
48
49
>
func tryDecodePayloadJSON(obj map[string]any, encoder codec.JSONPBEncoder) {
proto_decoder.go
50
>
metadata, ok := obj["metadata"].(map[string]any)
51
>
if !ok {
52
>
return
53
>
}
54
55
// Decode all metadata bytes values from base64 to strings.
57
>
b64, ok := val.(string)
58
>
if !ok {
59
continue
60
}
62
>
if err != nil {
63
continue
64
}
66
}
67
69
>
if !ok {
70
encoding = ""
71
}
73
>
if !ok {
74
>
messageType = ""
75
>
}
76
78
>
if !ok {
79
return
80
}
81
82
// For binary/protobuf with a known messageType, unmarshal and re-encode as JSON.
84
>
dataBytes, err := base64.StdEncoding.DecodeString(dataB64)
85
>
if err != nil {
86
return
87
}
88
>
msg, err := unmarshalProtoByTypeName(messageType, dataBytes)
proto_decoder.go
89
>
if err != nil {
90
>
return
91
>
}
92
>
jsonBytes, err := encoder.Encode(msg)
93
>
if err != nil {
94
return
95
}
97
>
if err := json.Unmarshal(jsonBytes, &decoded); err != nil {
98
return
99
}
101
>
return
102
}
103
104
// For JSON-based encodings, base64-decode and parse as JSON.
106
>
dataBytes, err := base64.StdEncoding.DecodeString(dataB64)
107
>
if err != nil {
108
return
109
}
111
>
if err := json.Unmarshal(dataBytes, &decoded); err != nil {
112
return
113
}
115
}
116
}