Skip to content

feat: add LoadReader method to generated funcs #72

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

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

Conversation

darkliquid
Copy link

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:

  • I call the function LoadReader instead of LoadFromBinary
  • I replace os.ReadFile in Load with os.Open and pass the *os.File to LoadReader, can defer the *os.File.Close()
  • I added a simple test
  • I used the latest protoc available via mise use protoc as of submitting this PR

When 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 an fs.FS virtual filesystem.

To address this, there is now a LoadReader method generated that accepts an io.Reader and uses that via io.ReadAll, rather than having to load a file via os.ReadFile first. The existing Load method has been rewritten to simply call LoadReader with the result of calling the os.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.

When 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 an `fs.FS` virtual filesystem.

To address this, there is now a `LoadReader` method generated that
accepts an `io.Reader` and uses that via `io.ReadAll`, rather than
having to load a file via `os.ReadFile` first. The existing `Load`
method has been rewritten to simply call `LoadReader` with the result
of calling the `os.Open` with the file name.
@knqyf263 knqyf263 requested a review from Copilot April 7, 2025 06:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 72 out of 72 changed files in this pull request and generated no comments.

@LukaGiorgadze
Copy link

LukaGiorgadze commented Jul 20, 2025

@knqyf263 thoughts on this PR?

@knqyf263
Copy link
Owner

I haven't tested it myself, but if someone else has tested it and confirmed that it works, the change seems fine.

@LukaGiorgadze
Copy link

LukaGiorgadze commented Jul 21, 2025

I haven't tested it myself, but if someone else has tested it and confirmed that it works, the change seems fine.

Ok, let's keep it in PR, I'll do testing today.

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.

3 participants