go.temporal.io/server/common/payloads/payloads.go

70 LOC · 19 covered · 51 uncovered · 5 ranges · 628 concepts · 5 introducers · 385 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package payloads
2
3 import (
4 "fmt"
5 "strings"
6
7 commonpb "go.temporal.io/api/common/v1"
8 "go.temporal.io/sdk/converter"
9 )
10
11 var (
12 defaultDataConverter = converter.GetDefaultDataConverter()
13 )
14
15 > func EncodeString(str string) *commonpb.Payloads { payloads.go ×1
16 > // Error can be safely ignored here becase string always can be converted.
17 > ps, _ := defaultDataConverter.ToPayloads(str)
18 > return ps
19 > }
20
21 func EncodeInt(i int) *commonpb.Payloads {
22 // Error can be safely ignored here becase int always can be converted.
23 ps, _ := defaultDataConverter.ToPayloads(i)
24 return ps
25 }
26
27 > func EncodeBytes(bytes []byte) *commonpb.Payloads { payloads.go ×1
28 > // Error can be safely ignored here becase []byte always can be raw encoded.
29 > ps, _ := defaultDataConverter.ToPayloads(bytes)
30 > return ps
31 > }
32
33 > func Encode(value ...any) (*commonpb.Payloads, error) { payloads.go ×1
34 > return defaultDataConverter.ToPayloads(value...)
35 > }
36
37 func EncodeSingle(value any) (*commonpb.Payload, error) {
38 ps, err := defaultDataConverter.ToPayloads(value)
39 if err != nil {
40 return nil, err
41 }
42 if len(ps.GetPayloads()) < 1 {
43 return nil, nil
44 }
45 return ps.GetPayloads()[0], nil
46 }
47
48 func MustEncodeSingle(value any) *commonpb.Payload {
49 p, err := EncodeSingle(value)
50 if err != nil {
51 panic(fmt.Sprintf("unable to encode single payload: %v", err)) //nolint:forbidigo // Must-helper: callers opt into panic on encode failure
52 }
53 return p
54 }
55
56 func MustEncode(value ...any) *commonpb.Payloads {
57 p, err := defaultDataConverter.ToPayloads(value...)
58 if err != nil {
59 panic(fmt.Sprintf("unable to encode payloads: %v", err)) //nolint:forbidigo // Must-helper: callers opt into panic on encode failure
60 }
61 return p
62 }
63
64 > func Decode(ps *commonpb.Payloads, valuePtr ...any) error { payloads.go ×1
65 > return defaultDataConverter.FromPayloads(ps, valuePtr...)
66 > }
67
68 > func ToString(ps *commonpb.Payloads) string { payloads.go ×1
69 > return fmt.Sprintf("[%s]", strings.Join(defaultDataConverter.ToStrings(ps), ", "))
70 > }