-
Notifications
You must be signed in to change notification settings - Fork 26
Fix broken decode_binary!
#81
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
base: main
Are you sure you want to change the base?
Conversation
|
I'm seeing that running Is that going to be a blocker for getting PRs merged? I don't mind circling back and seeing what I can do about those 3 missed lines, but it might be a few days before I get to it… |
|
It looks like the CI is failing here because of a test case rather than coverage. I can reproduce the failure locally: |
Oh, you're totally right! Guess I didn't notice that test failure when I ran It's not obvious to me what the correct answer is here. I think my change makes sense, but I'm not super familiar with Phoenix Channels implementation (or SlipStream, for that matter). Would you prefer I close this PR until I've got something more concrete to offer? Or leave it open for a bit in the hopes I find time to wrap my head around it shortly? |
Encoding was correct, but the pattern match for decoding wasn't properly accounting for a couple of values that Phoenix uses. Added a round trip test for binary encoding to verify that encode/decode returns the original value. Also added a round trip test for non-binary json encoding for good measure (even though it wasn't broken).
be6f551 to
f5fd66f
Compare
the-mikedavis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind leaving the PR open. Do you have steps to reproduce the problem you're seeing? The code on main looks correct to me so I'm not sure where the garbled values are coming from
| end | ||
|
|
||
| defp decode_binary!(<< | ||
| @push::size(8), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current implementation for decode_binary!/1 is correct: this clause is decoding binary pushes and the clause below is for replies. I would need to check the Phoenix code again but I think only the reply binary has the ref_size and ref parts.
Decoding binary-encoded payloads using
Slipstream.Serializer.PhoenixSocketV2Serializerresults in garbled values. Encoding seems correct, but the pattern match for decoding isn't properly accounting for a couple of ref-related values that Phoenix uses…I've added a round trip test that ensures decoding a binary-encoded value returns the original value. I also added a round trip test for non-binary json encoding just for good measure (it wasn't broken).
These changes bring SlipStream's implementation in line with what I'm seeing In Phoenix itself:
https://github.com/phoenixframework/phoenix/blob/v1.8.1/lib/phoenix/socket/serializers/v2_json_serializer.ex#L124C8-L124C21