Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PayloadEncoder -> PayloadCodec. #749

Merged
merged 2 commits into from
Mar 9, 2022
Merged

Rename PayloadEncoder -> PayloadCodec. #749

merged 2 commits into from
Mar 9, 2022

Conversation

robholland
Copy link
Contributor

What was changed

Renamed PayloadEncoder to PayloadCodec. Adjust the API to deal with slices of Payload rather than individual Payload or using a Payloads.

Why?

This is to be more consistent with the naming and interfaces used in other SDKs.

Adjust interface to take a Payload slice.
)
require.NoError(t, err)
compUnderMinPayload, err := zlibIgnoreMinConv.ToPayload(data)
require.NoError(t, err)
require.True(t, proto.Equal(uncompPayload, compUnderMinPayload))
}

func TestEncodingDataConverterClone(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed the cloning from ToPayload(s) because I believe the clone is only required for the FromPayload(s) cases where we must not mutate the Payload passed in. I believe it is safe to mutate Payload we receive from our parent DataConverter as those would not yet have been seen by any other code. Let me know if this is not correct.

// be nil. The byte slices of the payload's metadata or data should never be
// mutated directly, but they can be referenced or replaced.
Encode(*commonpb.Payload) error
Encode([]*commonpb.Payload) error
Copy link
Member

@cretz cretz Mar 9, 2022

Choose a reason for hiding this comment

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

I think we need to change our strategy a bit and have this return a collection instead of just mutating the parameter so you can encode multiple into one (and same for decode). We can then just change the docs to say "The parameters should never be mutated".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit nervous about changing the payload count, but I agree that returning a slice for these APIs would make them easier to use safely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated now.

Copy link
Member

Choose a reason for hiding this comment

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

We don't need to change the payload count for our use. We might even should document that we require "at least one" payload response everytime.

@robholland robholland requested a review from cretz March 9, 2022 16:04

func (z *zlibCodec) Encode(payloads []*commonpb.Payload) ([]*commonpb.Payload, error) {
result := make([]*commonpb.Payload, len(payloads))
for i, p := range payloads {
Copy link
Member

Choose a reason for hiding this comment

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

We can now leverage the fact that this operates on multiple payloads and compress them all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not something I'm comfortable doing in this PR.

Copy link
Member

@cretz cretz Mar 9, 2022

Choose a reason for hiding this comment

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

That is a bit scary, but it could be done, sure. But I'm ok with not doing it here. Really this is an example and I'd be fine removing this codec altogether, heh.

It's actually not the best algorithm, just the best in the stdlib. https://github.com/temporalio/samples-go/tree/main/snappycompress is better.

@robholland robholland merged commit 8608a59 into master Mar 9, 2022
@robholland robholland deleted the rh-codecs branch March 9, 2022 21:09
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