Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bergundy
Copy link
Member

Closes #833

@bergundy bergundy requested review from a team as code owners July 25, 2025 16:20
@bergundy bergundy force-pushed the multi-signal-input branch 2 times, most recently from 3ddd256 to d3151e3 Compare July 25, 2025 17:00
)

func CreatePayloads(data [][]byte, metadata map[string][]byte, isBase64 bool) (*common.Payloads, error) {
func CreatePayloads(data [][]byte, metadata map[string][][]byte, isBase64 bool) (*common.Payloads, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little confusing following this code. May need some godoc on this method explaining this map[string][][]byte data structure. As it looks today, I'd call this expecting 1:1 with data, but that's not the case. Rather it seems that the first array value is applied unless there is one for the data index. So if I have 3 pieces of data and my metadata has 2 values for "encoding", say "foo" and "bar", the first data item and the third data item get "foo" and only the middle one gets "bar".

Not saying this is wrong necessarily, just confusing and worth documenting somewhere clearly so it is clear that the logic below is by intention and what callers should expect. Maybe just toss a "If metadata has an entry at a data index, it is used, otherwise it uses the metadata entry at index 0" above the function would be enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a comment was made as a result of this comment (it's a bit hard to know without an update to this thread).

// If it's JSON, validate it
if strings.HasPrefix(string(metadata["encoding"]), "json/") && !json.Valid(in) {
return nil, fmt.Errorf("input #%v is not valid JSON", i+1)
var metadataForIndex = map[string][]byte{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var metadataForIndex = map[string][]byte{}
metadataForIndex := make(map[string][]byte, len(metadata))

Pedantic, can ignore, but a nice thing to do

Comment on lines +632 to +639
if vals, ok := metadata[metaPieces[0]]; ok {
if len(vals) == len(inData) {
return nil, fmt.Errorf("received more --input-meta flags for key %q than number of inputs", metaPieces[0])
}
metadata[metaPieces[0]] = append(vals, []byte(metaPieces[1]))
} else {
metadata[metaPieces[0]] = [][]byte{[]byte(metaPieces[1])}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if vals, ok := metadata[metaPieces[0]]; ok {
if len(vals) == len(inData) {
return nil, fmt.Errorf("received more --input-meta flags for key %q than number of inputs", metaPieces[0])
}
metadata[metaPieces[0]] = append(vals, []byte(metaPieces[1]))
} else {
metadata[metaPieces[0]] = [][]byte{[]byte(metaPieces[1])}
}
metadata[metaPieces[0]] = append(metadata[metaPieces[0]], []byte(metaPieces[1]))
if len(metadata[metaPieces[0]]) > len(inData) {
return nil, fmt.Errorf("received more --input-meta flags for key %q than number of inputs", metaPieces[0])
}

Pedantic, but for a map of slices, it's a bit more idiomatic Go to append to the nil result of the absent key rather than have conditionals (can use intermediate vars if you are concerned with the accesses)

@bergundy bergundy force-pushed the multi-signal-input branch from 8bd599e to a5ec0c1 Compare July 30, 2025 13:06
@bergundy bergundy requested review from Sushisource and cretz July 31, 2025 14:23
)

func CreatePayloads(data [][]byte, metadata map[string][]byte, isBase64 bool) (*common.Payloads, error) {
func CreatePayloads(data [][]byte, metadata map[string][][]byte, isBase64 bool) (*common.Payloads, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a comment was made as a result of this comment (it's a bit hard to know without an update to this thread).

@bergundy bergundy merged commit 733c68a into temporalio:next-server Aug 4, 2025
7 checks passed
@bergundy bergundy deleted the multi-signal-input branch August 4, 2025 21:40
bergundy added a commit that referenced this pull request Oct 3, 2025
bergundy added a commit that referenced this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants