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

Thoughts about writing a .proto generator from haskell code? #368

Open
martyall opened this issue Nov 20, 2019 · 1 comment
Open

Thoughts about writing a .proto generator from haskell code? #368

martyall opened this issue Nov 20, 2019 · 1 comment

Comments

@martyall
Copy link

Are there any thoughts about being able to generate .proto files from haskell types, ideally using generics? This is currently something we're interested in order to reduce some serious boilerplate, especially during prototyping phases.

This is currently something that proto3-suite is capable of doing. The problem with this library (at least at the moment) is that they do not use protoc but instead have their own custom parser, which does not support all of the specs of the language. So for example in our case, we use proto-lens for the protobuf files that we don't control, and proto3-suite for everything else, which is kind of annoying.

I wouldn't expect this generator to be able to handle all features of the protobuf3 spec, but basically there would be an implementation for types deriving Generic

@judah
Copy link
Collaborator

judah commented Nov 20, 2019

Thanks for bringing this up; I wasn't aware that proto3-suite supported that mode.
API-wise, this doesn't seem very objectionable because it only affects manually-written Message instances. I imagine it could also make writing some unit tests simpler.

Unfortunately, my guess is it would be quite involved to implement and maintain this feature, so I'm not convinced it's feasible in practice without significantly refactoring proto-lens. The Message class has several methods (used for reflection as well as encoding/decoding):
http://hackage.haskell.org/package/proto-lens-0.6.0.0/docs/Data-ProtoLens-Message.html#t:Message

Much of our logic around encoding/decoding is currently implemented in the codegen as part of proto-lens-protoc. The proto-lens library itself only contains low-level knowledge like how to encode/decode integers and strings. I'm not sure how we would avoid duplicating the higher-level logic, which is pretty undesirable. And currently we rely on the deep codegen to get good performance out of GHC.

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