go.temporal.io/server/common/payload/payload.go
127 LOC · 55 covered · 72 uncovered · 24 ranges · 22250 concepts · 20 introducers · 11071 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.
package payload
import (
"bytes"
"maps"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/sdk/converter"
"go.temporal.io/server/common/util"
)
var (
defaultDataConverter = converter.GetDefaultDataConverter()
nilPayload, _ = Encode(nil) // Data: nil
nilSlicePayload, _ = Encode([]string(nil)) // Data: "null" (nil value is json encoded as null)
emptySlicePayload, _ = Encode([]string{}) // Data: "[]"
)
// Error can be safely ignored here because string always can be converted to JSON
p, _ := defaultDataConverter.ToPayload(str)
return p
}
// Error can be safely ignored here because []byte always can be raw encoded
p, _ := defaultDataConverter.ToPayload(bytes)
return p
}
return defaultDataConverter.ToPayload(value)
}
return defaultDataConverter.FromPayload(p, valuePtr)
}
return defaultDataConverter.ToString(p)
}
// MergeMapOfPayload returns a new map resulting from merging map `src` into `dst`.
// If a key in `src` already exists in `dst`, then the value in `src` replaces
// the value in `dst`.
// If a key in `src` has nil or empty slice payload value, then it deletes
// the key from `dst` if it exists.
// For example:
//
// dst := map[string]*commonpb.Payload{
// "key1": EncodeString("value1"),
// "key2": EncodeString("value2"),
// }
// src := map[string]*commonpb.Payload{
// "key1": EncodeString("newValue1"),
// "key2": nilPayload,
// }
// res := MergeMapOfPayload(dst, src)
//
// The resulting map `res` is:
//
// map[string]*commonpb.Payload{
// "key1": EncodeString("newValue1"),
// }
func MergeMapOfPayload(
dst map[string]*commonpb.Payload,
src map[string]*commonpb.Payload,
if src == nil {
}
for k, v := range src {
}
}
}
// isNilPayload checks if the payload is equivalent to nil.
// There are four cases:
// - payload object is nil
// - payload's data is nil
// - payload's data is "null" (json encoded value for nil objects)
// - payload's data is "[]" (empty slice for backwards compatibility)
return p == nil ||
bytes.Equal(p.Data, nilPayload.Data) ||
bytes.Equal(p.Data, nilSlicePayload.Data) ||
bytes.Equal(p.Data, emptySlicePayload.Data)
}
// FilterNilSearchAttributes returns a new SearchAttributes with nil/empty payload values filtered out.
// If the input is nil or all values are nil/empty, returns nil.
// This is used to filter out nil search attributes from workflow start and continue-as-new events.
// Reuses MergeMapOfPayload which already handles nil payload filtering.
func FilterNilSearchAttributes(sa *commonpb.SearchAttributes) *commonpb.SearchAttributes {
payload.go ×1
if sa == nil || len(sa.GetIndexedFields()) == 0 {
}
if len(filtered) == 0 {
}
}
// FilterNilMemo returns a new Memo with nil/empty payload values filtered out.
// If the input is nil or all values are nil/empty, returns nil.
// This is used to filter out nil memo fields from workflow start, continue-as-new, and modify-properties events.
// Reuses MergeMapOfPayload which already handles nil payload filtering.
if memo == nil || len(memo.GetFields()) == 0 {
}
if len(filtered) == 0 {
}
}