Skip to content
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

Feature Request: add options to limit generating encode and decode methods to only specific message types #1084

Open
akrennmair opened this issue Aug 9, 2024 · 2 comments

Comments

@akrennmair
Copy link

I'm facing the specific problem that a significant amount of the generated script size of a project mine consists of scripts generated by ts-proto. I was looking into limiting what is being generated, and found the outputEncodeMethods option to be too limited: generally speaking, I have two top-level types, and for one (the request type) I only want to generate an encode method, while for the other (the response type), I only want to generate a decode method.

I would therefore like to have options to limit the generation of encode resp. decode methods to only specific types. A similar suggestion has also been made as a comment to #773: #773 (comment)

I also have a branch in which I implemented a possible solution that simply regular expressions. I'm not sure though whether this is sufficient as a general solution. I will submit a PR for it.

@stephenh
Copy link
Owner

Hi @akrennmair ; thanks for the PR! I guess that makes sense...

Out of curiosity, for your use case, is each type only primitives? Or does it have other messages?

I.e. I could see something like:

  • message Person -> you want to encode Person, but
  • message Person has a address = Address field and a pets = repeated Pet field

Such that to "encode Person", you actually end up ending encode methods for ~4-5 different messages, which seems like it would make keeping the regex updated kind of tedious? Or do you think that wouldn't be a problem?

@akrennmair
Copy link
Author

@stephenh the way we structure our messages is through nested message types, so we do have more complex structures in there, but they're all underneath our request message type, so they'd be automatically covered by a regex just matching for a prefix. I updated one of the integration tests to specifically demonstrate that: https://github.com/stephenh/ts-proto/pull/1085/files#diff-1039be2c30dc2bd6576bdf8e7acd59bee9e3bf408cf023373f9bf2241d675a69

I have been thinking as well whether it could become too tedious to manually manage the regular expression, so I wonder whether it would also makes sense to add inverted options, i.e. output{Encode,Decode}ExcludeTypes where any types matching that regex would not have their encode resp. decode methods generated.

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

No branches or pull requests

2 participants