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

Fix the handling of packed repeated fields (#38). #64

Merged
merged 6 commits into from
Feb 15, 2017

Conversation

judah
Copy link
Collaborator

@judah judah commented Dec 28, 2016

  • Don't emit empty packed fields during encoding.
  • Allow parsing packed fields as unpacked and vice versa.
  • Proto3 repeated fields are packed by default.

- Don't emit empty packed fields during encoding.
- Allow parsing packed fields as unpacked and vice versa.
- Proto3 repeated fields are packed by default.
getSimpleVal = do
Equal <- equalWireTypes name fieldWt wt
get val
-- Get a block of packed values, reversed.
getPackedVals :: w ~ B.ByteString => Either String [a]
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be simpler as "getPackedVals :: B.ByteString -> Either String [a]" and then the type equality can be implicit at the call site (in the RepeatedField case below)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turned out GHC can infer these types (maybe due to the refactor you suggested below), so I just removed the type signature.

-- depending on how it was encoded.
-- Note that if fieldWt is Lengthy (e.g., "string" or
-- message) we should always parse it as unpacked.
| Right Equal <- equalWireTypes name wt fieldWt -> do
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively (ha), "RepeatedField _ f -> getPackedVals <|> getUnpackedVals <|> fail ..." and keep the "equalWireTypes" calls in the helper functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@judah judah merged commit 888d627 into google:master Feb 15, 2017
avdv pushed a commit to avdv/proto-lens that referenced this pull request Aug 9, 2023
- Don't emit empty packed fields during encoding.
- Allow parsing packed fields as unpacked and vice versa.
- Proto3 repeated fields are packed by default.
ylecornec pushed a commit to ylecornec/proto-lens that referenced this pull request Feb 19, 2024
- Don't emit empty packed fields during encoding.
- Allow parsing packed fields as unpacked and vice versa.
- Proto3 repeated fields are packed by default.
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.

None yet

2 participants