proto_decoder.go ×19

Frontier kind: Joint frontier

unlabeled · c_eec8778932f6

1 test · 2723 LOC · 132 files · introduces 1 test · 67 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
20 ranges67 lines · 2 files
Tests
1 test

Contains — complete concept membership

All code (extent)
386 ranges2723 lines · 132 files · Browse complete extent
All tests (intent)
1 testBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 67 introduced LOC across 20 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/tools/tdbg/proto_decoder.go 63 introduced LOC · 19 ranges

Open complete file

22 return data
23 }
24 > encoder := codec.NewJSONPBEncoder() proto_decoder.go
25 > decodePayloadsRecursive(parsed, encoder)
26 > result, err := json.Marshal(parsed)
27 > if err != nil {
28 return data
29 }
30 > return result proto_decoder.go
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.
56 > for key, val := range metadata { proto_decoder.go
57 > b64, ok := val.(string)
58 > if !ok {
59 continue
60 }
61 > decoded, err := base64.StdEncoding.DecodeString(b64) proto_decoder.go
62 > if err != nil {
63 continue
64 }
65 > metadata[key] = string(decoded) proto_decoder.go
66 }
67
68 > encoding, ok := metadata["encoding"].(string) proto_decoder.go
69 > if !ok {
70 encoding = ""
71 }
72 > messageType, ok := metadata["messageType"].(string) proto_decoder.go
73 > if !ok {
74 > messageType = ""
75 > }
76
77 > dataB64, ok := obj["data"].(string) proto_decoder.go
78 > if !ok {
79 return
80 }
81
82 // For binary/protobuf with a known messageType, unmarshal and re-encode as JSON.
83 > if messageType != "" && encoding == "binary/protobuf" { proto_decoder.go
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 }
96 > var decoded any proto_decoder.go
97 > if err := json.Unmarshal(jsonBytes, &decoded); err != nil {
98 return
99 }
100 > obj["data"] = decoded proto_decoder.go
101 > return
102 }
103
104 // For JSON-based encodings, base64-decode and parse as JSON.
105 > if strings.HasPrefix(encoding, "json/") { proto_decoder.go
106 > dataBytes, err := base64.StdEncoding.DecodeString(dataB64)
107 > if err != nil {
108 return
109 }
110 > var decoded any proto_decoder.go
111 > if err := json.Unmarshal(dataBytes, &decoded); err != nil {
112 return
113 }
114 > obj["data"] = decoded proto_decoder.go
115 }
116 }
118 // unmarshalProtoByTypeName resolves a proto type by its full name from the
119 // global registry and unmarshals the given bytes into it.
120 > func unmarshalProtoByTypeName(typeName string, data []byte) (proto.Message, error) { proto_decoder.go
121 > mt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(typeName))
122 > if err != nil {
123 > return nil, fmt.Errorf("unable to find %s type: %w", typeName, err)
124 > }
125 > msg := mt.New().Interface()
126 > if err := proto.Unmarshal(data, msg); err != nil {
127 return nil, fmt.Errorf("unable to unmarshal to %s: %w", typeName, err)
128 }
129 > return msg, nil proto_decoder.go
130 }
go.temporal.io/server/common/codec/jsonpb.go 4 introduced LOC · 1 range

Open complete file

47
48 // Encode HistoryEvent slice to bytes.
49 > func (e *JSONPBEncoder) EncodeHistoryEvents(historyEvents []*historypb.HistoryEvent) ([]byte, error) { jsonpb.go
50 > return e.encodeSlice(
51 > len(historyEvents),
52 > func(i int) proto.Message { return historyEvents[i] })
53 }
54