[wip] add support for foreign types #94
Closed
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.
As discussed in #93 (comment), this is the third approach to supporting fast serialization of well-known types:
The idea is adding a flag,
foreign
to the compiler, which forces code generation to write free-standing functions (i.e. functions where the ProtoBuf message being (de)serialized is an argument, and not a method receiver). This allows the functions to operate on ProtoBuf objects from foreign packages.As @biosvs points out on the other issue, generating free-standing functions is going to be very hard without adding a lot of
if
indirections. I had some time today so I sketched out a possible solution that abstracts method definitions and function calls behind a generic API. I managed to get foreign functions generation working formarshal+size
-- all the other generation kinds are not implemented.@biosvs: I would very much like to hear your thoughts on this approach. I think it's reasonably clean given the complexity that foreign types add. I'm out of time for this week, so I'll pick this up again next week -- if you have any suggestions or ways to improve on this design please feel free to push them to your own branch and I'll merge them here. Thanks again for your help with this feature!