MCPcopy Create free account
hub / github.com/temporalio/temporal / Encode

Method Encode

chasm/path_encoder.go:47–90  ·  view source on GitHub ↗

The Encode method encodes node path in a way that the following uses cases can be achieved by doing a simple a range query in DB based on prefixes of the encoded path: 1. Getting all nodes for a chasm tree. 2. Getting all nodes for a sub-tree. 3. Getting all immediate children of a Collection node.

(
	node *Node,
	path []string,
)

Source from the content-addressed store, hash-verified

45//
46// path >= "foo" AND path < "foo%"
47func (e *defaultPathEncoder) Encode(
48 node *Node,
49 path []string,
50) (string, error) {
51 if path == nil {
52 path = node.path()
53 }
54
55 if len(path) == 0 {
56 return "", nil
57 }
58
59 var b strings.Builder
60 lastIdx := len(path) - 1
61 for i, nodeName := range path {
62 if i > 0 {
63 if i == lastIdx &&
64 node.parent != nil &&
65 node.parent.serializedNode.GetMetadata().GetCollectionAttributes() != nil {
66 _, _ = b.WriteRune(collectionSeparator)
67 } else {
68 _, _ = b.WriteRune(nameSeparator)
69 }
70 }
71
72 if nodeName == "" {
73 return "", serviceerror.NewInternalf("path contains empty node name: %v", path)
74 }
75
76 for _, r := range nodeName {
77 if r == utf8.RuneError {
78 return "", serviceerror.NewInvalidArgumentf("node name contains invalid UTF-8 code point: %v", nodeName)
79 }
80
81 if r == escapeChar ||
82 r == nameSeparator ||
83 r <= collectionSeparator {
84 _, _ = b.WriteRune(escapeChar)
85 }
86 _, _ = b.WriteRune(r)
87 }
88 }
89 return b.String(), nil
90}
91
92func (e *defaultPathEncoder) Decode(
93 encodedPath string,

Callers 1

Calls 4

pathMethod · 0.80
GetMetadataMethod · 0.65
StringMethod · 0.65

Tested by 1