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

Override features defined in enclosed scopes. #479

Merged
merged 7 commits into from
Oct 3, 2024
Merged

Override features defined in enclosed scopes. #479

merged 7 commits into from
Oct 3, 2024

Conversation

chungyc
Copy link
Member

@chungyc chungyc commented Oct 2, 2024

This completes support of Protobuf Editions to the same level that proto-lens supports proto2 and proto3 except for the following, which I do not think are critical bugs:

  • features.utf8_validation = NONE does not disable UTF-8 validation.

  • If more than one field sharing the same message type are in a single message type, and if one of the fields has features.message_encoding = DELIMITED, then all of these fields will use DELIMITED encoding.

Unevaluated tests are intentionally included despite warnings by HLint so that they are still built and can be easily enabled later if the above are fixed.

Resolves #468.

Comment on lines +145 to +156
[ const (testCase "NONE (skipped)" (pure ())) $
-- We actually cannot disable validation of UTF-8 in strings.
-- This could be done by passing down the verification mode
-- to the code generator and using decodeUtf8Lenient instead
-- when verification is disabled. This may not be worth it;
-- the content with a string containing invalid UTF-8 is undefined,
-- and changing it to a bytes field would be a straightforward fix.
--
-- If this was done, we would stop ignoring this test case.
deserializeFrom "NONE"
(Just $ defFeatures & utf8ValidationNone .~ "depends on decoding")
(tagged 8 $ Lengthy invalidUtf8)

Check warning

Code scanning / HLint

Evaluate Warning test

proto-lens-tests/tests/edition2023_test.hs:(145,9)-(156,42): Warning: Evaluate
  
Found:
  const (testCase "NONE (skipped)" (pure ()))
    $ deserializeFrom
        "NONE"
        (Just $ defFeatures & utf8ValidationNone .~ "depends on decoding")
        (tagged 8 $ Lengthy invalidUtf8)
  
Perhaps:
  (testCase "NONE (skipped)" (pure ()))
Comment on lines +169 to +180
, const (testCase "LENGTH_PREFIXED (skipped)" (pure ())) $
-- proto-lens sets DELIMITED encoding by message type, not field.
-- Full compatability with Protobuf Editions would require it to be
-- by field. However, given the usual use case for DELIMITED encoding,
-- where it is to support legacy proto2 groups in which message types
-- and fields are tied toggether, this may not be worth fixing.
--
-- If this was done, we would stop ignoring this test case.
serializeTo "LENGTH_PREFIXED"
(defFeatures & messageEncodingLengthPrefixed . foo .~ 21)
(braced "message_encoding_length_prefixed" $ keyedInt "foo" 21)
(tagged 11 $ Lengthy $ tagged 1 $ VarInt 21)

Check warning

Code scanning / HLint

Evaluate Warning test

proto-lens-tests/tests/edition2023_test.hs:(169,9)-(180,54): Warning: Evaluate
  
Found:
  const (testCase "LENGTH_PREFIXED (skipped)" (pure ()))
    $ serializeTo
        "LENGTH_PREFIXED"
        (defFeatures & messageEncodingLengthPrefixed . foo .~ 21)
        (braced "message_encoding_length_prefixed" $ keyedInt "foo" 21)
        (tagged 11 $ Lengthy $ tagged 1 $ VarInt 21)
  
Perhaps:
  (testCase "LENGTH_PREFIXED (skipped)" (pure ()))
@chungyc
Copy link
Member Author

chungyc commented Oct 2, 2024

@agrue, this last change completes support for Protobuf Editions.

Copy link
Contributor

@agrue agrue left a comment

Choose a reason for hiding this comment

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

Thanks for all the tests!

@agrue agrue merged commit 24276fe into google:master Oct 3, 2024
11 checks passed
@chungyc chungyc deleted the edition-overrides-incremental branch October 3, 2024 04:03
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.

Support "Protobuf Editions"
2 participants