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

Make array on decode if it's not supposed to be nil #304

Closed
wants to merge 1 commit into from

Conversation

makarchuk
Copy link

Addresses #278. #302 fixed issue only partially. It serialized non-nil empty slice as it should, but on decode it deserialized as nil anyway.

This PR addresses this "issue".

I'm open to any suggestions on code improvement for this one

Copy link
Collaborator

@klauspost klauspost left a comment

Choose a reason for hiding this comment

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

LGTM

@makarchuk
Copy link
Author

Can I help out somehow to speed up merge of this one?
It's quite important for me

@klauspost
Copy link
Collaborator

I suppose a few tests would help.

klauspost added a commit to klauspost/msgp that referenced this pull request Oct 27, 2023
When `allownil` is enabled, always allocate zero length slices.

This ensures roundtrips with 0-length slices are not returned as nil.

Replaces tinylib#304

Adds tests. Bonus: Don't shell out to test issue 94.
@klauspost
Copy link
Collaborator

@makarchuk I have added #336

When looking at this, I would expect the additional allocations to be a significant downside for current users. Instead I've added it to allownil. Since these members can explicitly state if they want to be empty slice or nil, it makes sense there.

That would make allownil members fully roundtrip safe in Go.

klauspost added a commit that referenced this pull request Feb 10, 2024
* allownil: Allocate 0 length slices

When `allownil` is enabled, always allocate zero length slices.

This ensures roundtrips with 0-length slices are not returned as nil.

Replaces #304

Adds tests. Bonus: Don't shell out to test issue 94.
@klauspost klauspost closed this Feb 10, 2024
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.

2 participants