-
Notifications
You must be signed in to change notification settings - Fork 192
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
Support custom struct tags #347
Conversation
For better compatibility and consistency could we make it only operate on explicit types? Syntax could be Please add tests. |
Type-scope `//msgp:tag {tagname} Type1 Type2` directives take *exclusive* precedence over file-scope directives for the types they apply to. If a type has a custom tag set via a type-scope directive: 1. The tag set via the type-scope directive will be checked first, then `msg` and `msgpack` are checked as fallbacks 2. Any tag set in a file-scope directive will *not* be checked for that type (enabling the use of type-scope tag directives for compatibility purposes).
I've implemented an explicit type-scope directive form (using the suggested syntax) in addition to the file-scope form. When a type-scope directive is used to set a custom tag for a type, any tag set via a file-scope directive be ignored for all of that type's fields. This behavior allows type-scope directives to be used for compatibility while still being able to support the simpler file-scope directives. Tests have been added for both file-scope and type-scope tag directives. |
@klauspost Could I please get a review of these changes at your convenience? |
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 am not a fan of the global directive, but I guess now we give people the option to avoid a potential foot-gun.
Unless there are any objections I will merge shortly.
I hate to bike-shed but IMO the change was less invasive as purely a "global" setting. With this change at the type level we've got the implementation details bleeding through down to the AST parsing code. (Keep in mind nothing is truly "global" here -- this is a file-based codegen tool. I can't really envision a circumstance where splitting types between files when the tagging requirements are different would be problematic.) |
@philhofer Are you thinking from an implementation perspective or from a user perspective? |
From an implementation perspective, it's easier to keep directives at the file level rather than the type level, just because of how the code is currently written. You can just stick the desired tag name(s) in From a user perspective, I can sort of see why per-type tagging might be useful, but generally you're going to want to use one tag everywhere. In the rare cases where you wouldn't want to do that, you'd probably already have the types in separate files already, where it's a moot point. The tool is already file-based. (And it sounds like @very-amused 's use-case would want this to be applied globally anyway.) |
If it would be preferred to merge with file-scope syntax only, I could use |
@very-amused Feel free to revert, but keep the test for the global type. |
@klauspost The revert is done, file-scope syntax and associated tests were kept. |
Thanks for the contribution! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/tinylib/msgp](https://togithub.com/tinylib/msgp) | `v1.1.9` -> `v1.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>tinylib/msgp (github.com/tinylib/msgp)</summary> ### [`v1.2.0`](https://togithub.com/tinylib/msgp/releases/tag/v1.2.0) [Compare Source](https://togithub.com/tinylib/msgp/compare/v1.1.9...v1.2.0) ##### What's Changed - omitzero implementation by [@​bradleypeabody](https://togithub.com/bradleypeabody) in [https://github.com/tinylib/msgp/pull/334](https://togithub.com/tinylib/msgp/pull/334) - `replace` directive by [@​infastin](https://togithub.com/infastin) in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) - Support custom struct tags by [@​very-amused](https://togithub.com/very-amused) in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - Add map\[string]struct{} support by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/339](https://togithub.com/tinylib/msgp/pull/339) - Add `any` support by [@​VirrageS](https://togithub.com/VirrageS) in [https://github.com/tinylib/msgp/pull/350](https://togithub.com/tinylib/msgp/pull/350) - support for `any` maps in msgp.AppendIntf like in (\*Writer).WriteIntf by [@​eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - allownil: Allocate 0 length slices by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/336](https://togithub.com/tinylib/msgp/pull/336) - Fix ignored tag directives on unnamed fields by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/352](https://togithub.com/tinylib/msgp/pull/352) - Added `time.Duration` case to AppendIntf by [@​RiaanLaubscher](https://togithub.com/RiaanLaubscher) in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - Bounds checks elimination by [@​mhr3](https://togithub.com/mhr3) in [https://github.com/tinylib/msgp/pull/348](https://togithub.com/tinylib/msgp/pull/348) - test AppendIntf against ReadIntfBytes by [@​eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/341](https://togithub.com/tinylib/msgp/pull/341) - Support illumos. by [@​jperkin](https://togithub.com/jperkin) in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) ##### New Contributors - [@​eliottness](https://togithub.com/eliottness) made their first contribution in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - [@​jperkin](https://togithub.com/jperkin) made their first contribution in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) - [@​very-amused](https://togithub.com/very-amused) made their first contribution in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - [@​RiaanLaubscher](https://togithub.com/RiaanLaubscher) made their first contribution in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - [@​infastin](https://togithub.com/infastin) made their first contribution in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) **Full Changelog**: tinylib/msgp@v1.1.9...v1.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZWJvdCJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/tinylib/msgp](https://togithub.com/tinylib/msgp) | `v1.1.9` -> `v1.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>tinylib/msgp (github.com/tinylib/msgp)</summary> ### [`v1.2.0`](https://togithub.com/tinylib/msgp/releases/tag/v1.2.0) [Compare Source](https://togithub.com/tinylib/msgp/compare/v1.1.9...v1.2.0) #### What's Changed - omitzero implementation by [@​bradleypeabody](https://togithub.com/bradleypeabody) in [https://github.com/tinylib/msgp/pull/334](https://togithub.com/tinylib/msgp/pull/334) - `replace` directive by [@​infastin](https://togithub.com/infastin) in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) - Support custom struct tags by [@​very-amused](https://togithub.com/very-amused) in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - Add map\[string]struct{} support by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/339](https://togithub.com/tinylib/msgp/pull/339) - Add `any` support by [@​VirrageS](https://togithub.com/VirrageS) in [https://github.com/tinylib/msgp/pull/350](https://togithub.com/tinylib/msgp/pull/350) - support for `any` maps in msgp.AppendIntf like in (\*Writer).WriteIntf by [@​eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - allownil: Allocate 0 length slices by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/336](https://togithub.com/tinylib/msgp/pull/336) - Fix ignored tag directives on unnamed fields by [@​klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/352](https://togithub.com/tinylib/msgp/pull/352) - Added `time.Duration` case to AppendIntf by [@​RiaanLaubscher](https://togithub.com/RiaanLaubscher) in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - Bounds checks elimination by [@​mhr3](https://togithub.com/mhr3) in [https://github.com/tinylib/msgp/pull/348](https://togithub.com/tinylib/msgp/pull/348) - test AppendIntf against ReadIntfBytes by [@​eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/341](https://togithub.com/tinylib/msgp/pull/341) - Support illumos. by [@​jperkin](https://togithub.com/jperkin) in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) #### New Contributors - [@​eliottness](https://togithub.com/eliottness) made their first contribution in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - [@​jperkin](https://togithub.com/jperkin) made their first contribution in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) - [@​very-amused](https://togithub.com/very-amused) made their first contribution in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - [@​RiaanLaubscher](https://togithub.com/RiaanLaubscher) made their first contribution in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - [@​infastin](https://togithub.com/infastin) made their first contribution in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) **Full Changelog**: tinylib/msgp@v1.1.9...v1.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGVib3QiXX0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/tinylib/msgp](https://togithub.com/tinylib/msgp) | `v1.1.9` -> `v1.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2ftinylib%2fmsgp/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2ftinylib%2fmsgp/v1.1.9/v1.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>tinylib/msgp (github.com/tinylib/msgp)</summary> ### [`v1.2.0`](https://togithub.com/tinylib/msgp/releases/tag/v1.2.0) [Compare Source](https://togithub.com/tinylib/msgp/compare/v1.1.9...v1.2.0) #### What's Changed - omitzero implementation by [@&open-telemetry#8203;bradleypeabody](https://togithub.com/bradleypeabody) in [https://github.com/tinylib/msgp/pull/334](https://togithub.com/tinylib/msgp/pull/334) - `replace` directive by [@&open-telemetry#8203;infastin](https://togithub.com/infastin) in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) - Support custom struct tags by [@&open-telemetry#8203;very-amused](https://togithub.com/very-amused) in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - Add map\[string]struct{} support by [@&open-telemetry#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/339](https://togithub.com/tinylib/msgp/pull/339) - Add `any` support by [@&open-telemetry#8203;VirrageS](https://togithub.com/VirrageS) in [https://github.com/tinylib/msgp/pull/350](https://togithub.com/tinylib/msgp/pull/350) - support for `any` maps in msgp.AppendIntf like in (\*Writer).WriteIntf by [@&open-telemetry#8203;eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - allownil: Allocate 0 length slices by [@&open-telemetry#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/336](https://togithub.com/tinylib/msgp/pull/336) - Fix ignored tag directives on unnamed fields by [@&open-telemetry#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/tinylib/msgp/pull/352](https://togithub.com/tinylib/msgp/pull/352) - Added `time.Duration` case to AppendIntf by [@&open-telemetry#8203;RiaanLaubscher](https://togithub.com/RiaanLaubscher) in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - Bounds checks elimination by [@&open-telemetry#8203;mhr3](https://togithub.com/mhr3) in [https://github.com/tinylib/msgp/pull/348](https://togithub.com/tinylib/msgp/pull/348) - test AppendIntf against ReadIntfBytes by [@&open-telemetry#8203;eliottness](https://togithub.com/eliottness) in [https://github.com/tinylib/msgp/pull/341](https://togithub.com/tinylib/msgp/pull/341) - Support illumos. by [@&open-telemetry#8203;jperkin](https://togithub.com/jperkin) in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) #### New Contributors - [@&open-telemetry#8203;eliottness](https://togithub.com/eliottness) made their first contribution in [https://github.com/tinylib/msgp/pull/340](https://togithub.com/tinylib/msgp/pull/340) - [@&open-telemetry#8203;jperkin](https://togithub.com/jperkin) made their first contribution in [https://github.com/tinylib/msgp/pull/343](https://togithub.com/tinylib/msgp/pull/343) - [@&open-telemetry#8203;very-amused](https://togithub.com/very-amused) made their first contribution in [https://github.com/tinylib/msgp/pull/347](https://togithub.com/tinylib/msgp/pull/347) - [@&open-telemetry#8203;RiaanLaubscher](https://togithub.com/RiaanLaubscher) made their first contribution in [https://github.com/tinylib/msgp/pull/353](https://togithub.com/tinylib/msgp/pull/353) - [@&open-telemetry#8203;infastin](https://togithub.com/infastin) made their first contribution in [https://github.com/tinylib/msgp/pull/346](https://togithub.com/tinylib/msgp/pull/346) **Full Changelog**: tinylib/msgp@v1.1.9...v1.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View the [repository job log](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGVib3QiXX0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Closes #313
This PR adds support for reading MessagePack field names from a custom struct tag via the
//msgp:tag {tagname}
directive. If the custom tag isn't present for a field,msg
andmsgpack
are checked next.Example: