go.temporal.io/server/common/searchattribute/encode.go
101 LOC · 53 covered · 48 uncovered · 18 ranges · 91 concepts · 12 introducers · 41 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 searchattribute
import (
"errors"
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/server/common/payload"
"go.temporal.io/server/common/searchattribute/sadefs"
)
// Encode encodes map of search attribute values to search attributes.
// typeMap can be nil (then MetadataType field won't be set).
// In case of error, it will continue to next search attribute and return last error.
func Encode(searchAttributes map[string]any, typeMap *NameTypeMap) (*commonpb.SearchAttributes, error) {
encode.go ×1
if len(searchAttributes) == 0 {
}
var lastErr error
for saName, saValue := range searchAttributes {
valPayload, err := payload.Encode(saValue)
if err != nil {
lastErr = err
indexedFields[saName] = nil
continue
}
saType := enumspb.INDEXED_VALUE_TYPE_UNSPECIFIED
if typeMap != nil {
if err != nil {
// Silently skip unknown search attributes. This can happen due to
// version mismatches where a newer server wrote a predefined SA
// that this server doesn't recognize.
delete(indexedFields, saName)
continue
}
lastErr = err
continue
}
}
}
}
// Decode decodes search attributes to the map of search attribute values using (in order):
// 1. type from typeMap,
// 2. if typeMap is nil, type from MetadataType field is used.
// In case of error, it will continue to next search attribute and return last error.
func Decode(
searchAttributes *commonpb.SearchAttributes,
typeMap *NameTypeMap,
allowList bool,
if len(searchAttributes.GetIndexedFields()) == 0 {
}
var lastErr error
for saName, saPayload := range searchAttributes.GetIndexedFields() {
saType := enumspb.INDEXED_VALUE_TYPE_UNSPECIFIED
if typeMap != nil {
saType, err = typeMap.getType(saName, customCategory|predefinedCategory)
if err != nil {
// Chasm search attributes are not in the standard type map;
// allow them through with UNSPECIFIED type.
// SA not found in the type map. Fall through to DecodeValue with
// UNSPECIFIED type, which uses the payload's MetadataType as a
// fallback. This handles two cases:
// 1. Version mismatch: a newer server wrote a predefined SA that
// this server's constants don't recognize.
// 2. Cache lag: a recently registered custom SA that hasn't yet
// propagated to this server's SA manager cache.
// If MetadataType is also UNSPECIFIED (truly unknown payload),
// DecodeValue returns an error and the SA is excluded from the result.
} else {
lastErr = err
}
}
}
if err != nil {
result[saName] = nil
continue
}
}
}