Skip to content

[api-go] Support direct Payload's and Payload`s at top-level of Any in payload visitor #1862

@yuandrew

Description

@yuandrew

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
When creating a common.Payload and marshaling it into an Any type, the visitor is not able to visit this scenario, due to a missing case *common.Payload in visitPayloads().

This scenario is not used in our API today, but something we may want to support in the future.

Describe the solution you'd like
Implement this base case so we can visit this scenario.

Additional context
Here is a basic test I wrote to validate this new feature

func TestVisitPayloads_AnyPayload(t *testing.T) {
	msg, err := anypb.New(inputPayload())
	require.NoError(t, err)
	root := &protocol.Message{Body: msg}
	var anyCount int
	err = VisitPayloads(context.Background(), root, VisitPayloadsOptions{
		Visitor: func(ctx *VisitPayloadsContext, p []*common.Payload) ([]*common.Payload, error) {
			anyCount++
			// Only mutate if the payloads has "test"
			if len(p) == 1 && string(p[0].Data) == "test" {
				return []*common.Payload{{Data: []byte("new-val")}}, nil
			}
			return p, nil
		},
	})
	require.NoError(t, err)
	require.Equal(t, 1, anyCount)
	update1, err := root.Body.UnmarshalNew()
	require.NoError(t, err)
	require.Equal(t, "new-val", string(update1.(*common.Payload).Data))
}

also see temporalio/api-go#202 (comment) for more context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions