feat: add LoadReader method to generated funcs #72
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.
Issue #, if available:
#52 #53
Description of changes:
I ended up writing this for my own use before I noticed that there was an existing PR/Issue for this already. Since the other one still hasn't been merged, I figured I may as well throw my hat in the ring as well. By sheer coincidence it's almost identical to the other PR, except for the following:
LoadReader
instead ofLoadFromBinary
os.ReadFile
inLoad
withos.Open
and pass the*os.File
toLoadReader
, can defer the*os.File.Close()
mise use protoc
as of submitting this PRWhen generating the plugin loading functions from protobufs, previously there was only an option to load plugins directly from disk via file names. This prevents use cases such as loading plugins embedded using
embed
or via anfs.FS
virtual filesystem.To address this, there is now a
LoadReader
method generated that accepts anio.Reader
and uses that viaio.ReadAll
, rather than having to load a file viaos.ReadFile
first. The existingLoad
method has been rewritten to simply callLoadReader
with the result of calling theos.Open
with the file name.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.