refactor common proto resource (un)marshallers into generic functions #41562
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have many implementations of resource marshallers and unmarshallers that are basically identical aside from the types. Most developers just find an existing resource and copy whatever it does.
This PR adds new generic marshal and unmarshal functions that should work for all new RFD153-style resources based on protobuf types generated with
buf
. The recommendation for new types going forward is to useservices.MarshalProtoResource
andservices.UnmarshalProtoResource
for your type.services.FastMarshalProtoResourceDeprecated
andservices.FastUnmarshalProtoResourceDeprecated
were also added since 7 of the new types already wrote their (un)marshal functions based onutils.FastMarshal
, which does not support some protobuf features likeoneof
. If someone takes the time to check if it would be safe to convert these types to the new protojson-based marshaler, they could potentially be converted.For now in this PR, I am keeping all functionality identical and just refactoring common code into shared functions. The one exception to this is MarshalAccessMonitoringRule which previously just called
utils.FastMarshal
without considering theMarshalOption
s, it now usesFastMarshalProtoResourceDeprecated
which does respect the marshal options.