Code Monkey home page Code Monkey logo

Comments (5)

neild avatar neild commented on June 10, 2024 2

My first recommendation is that you replace , with something else in your generator parameters.

Failing that, yes, I recommend that you parse the CodeGeneratorRequest.Parameters yourself.

(As a distant third, I recommend that you find the protoc maintainers and get them to add a repeated field to CodeGeneratorRequest containing the individual parameters.) (I am not actually recommending this.) (It would be nice, though.)

from protobuf.

lfolger avatar lfolger commented on June 10, 2024

Thanks for filing this feature request.

To summarize the different alternatives from my point of view:

  1. We build a parser that supports escaping of the ',' so that values (or even keys) can contain ','.
  2. We add an overwrite option for users to provide a custom parser. This could be as simple as func (string) []KeyValuePairs where KeyValuePairs is just a pair of strings.
  3. Users could encode their parameters with something that doesn't contain ',' (e.g. base64) before passing it to protoc and decode it when their callback is invoked.

Solution 1. requires us to define the exact grammer for escaping and add the implementation (which is 175 lines in the prototype change).

Solution 3. doesn't require any changes but is suboptimal to use and certainly works around a limitation in the protogen package).

Solution 2. requires a very small change to the protogen but adds another public API.

I would like to get @neild feedback on this as well.

from protobuf.

neild avatar neild commented on June 10, 2024

I believe the behavior of separating options with a comma comes from protoc: If you pass --go_opt=a --go_opt=b, protoc passes a CodeGeneratorRequest.parameter of a,b. No quoting or escaping, it just joins all --*_opt params with a comma; see https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/command_line_interface.cc#L2393.

As such, I think the right thing to do is accept that commas are not valid in option values.

If you do need some different behavior, then you can always modify the CodeGeneratorRequest before passing it to protogen.Options.New. (This requires that you use New rather than Run, but Run isn't all that complicated.)

from protobuf.

Clement-Jean avatar Clement-Jean commented on June 10, 2024

@neild if I understand correctly, what you are recommending is parsing the CodeGeneratorRequest.Parameters and quoting/escaping it. Basically, duplicating the protogen.Options.run logic in our own plugin. Am I getting this right?

from protobuf.

lfolger avatar lfolger commented on June 10, 2024

Closing this issue for now. Feel free to reopen if you have further input or questions.

from protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.