Skip to content

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 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.

@SUNsung
Copy link

SUNsung commented Sep 6, 2025

@knqyf263 Will this be added to the master?

@inliquid
Copy link
Contributor

inliquid commented Sep 6, 2025

@darkliquid maybe keep LoadBinary as a third option? And probably rename Load, so that all three would be in one place:

  • LoadPath
  • LoadBinary
  • LoadReader

First two will call LoadReader under the hood.

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.

5 participants