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

Use encoding.TextMarshaler/encoding.TextUnmarshaler if present #413

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

drshriveer
Copy link

Background:

In order to parse custom flag types it is currently necessary to implement the flags.Unmarshaler and optionally the flags.Marshaler interface. That interface is specific to this library, but many types already make use of encoding.TextMarshaler and encoding.TextUnmarshaler which is a bit more standardized. It is cumbersome, and sometimes impossible when you don't own the code, to implement both interfaces. Thus this PR allows adds the ability to marshal flags by those interfaces.

Changes:

  • add interface check for encoding.TextMarshaler to convertMarshal only AFTER checking for the flags.Marshaler interface.
  • add interface check for encoding.TextUnmarshaler to convertUnmarshal only AFTER checking for the flags.Unmarshaler interface.
  • add round-trip test for a type that implements text unmarshallers.

@drshriveer drshriveer changed the title Use encoding.TextMarshaler OR encoding.TextUnmarshaler if present Use encoding.TextMarshaler/encoding.TextUnmarshaler if present Sep 5, 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.

1 participant