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

Add CQG CMS API protobuf Haskell package #1

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

cdepillabout
Copy link
Contributor

@cdepillabout cdepillabout commented Jun 1, 2024

This PR adds an initial cqg-cms-api-proto Haskell package. This package contains Haskell modules generated from the CQG CMS API protobuf files.

This is currently using the proto-lens functionality for manually generating Haskell modules from the protobuf files: https://github.com/google/proto-lens/tree/master?tab=readme-ov-file#manually-running-the-protocol-compiler

Most of the commits in this PR won't be too interesting to review, but the downloading and generation script may be slightly interesting to review (cqg-cms-api-proto/generate.sh).

Comment on lines +34 to +43
library
exposed-modules:
Proto.CMS.ApiLimit1
Proto.CMS.ApiLimit1_Fields
Proto.CMS.Cmsapi1
Proto.CMS.Cmsapi1_Fields
Proto.CMS.Common1
Proto.CMS.Common1_Fields
Proto.CMS.Location1
Proto.CMS.Location1_Fields
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having these Haskell modules all be named Proto.* feels somewhat unfortunate. It feels like it would be better if we could name them something like CQG.Proto.CMS.ApiLimit1, but it doesn't appear that the proto-lens library has any way of generating modules with a different naming scheme.

Copy link
Member

Choose a reason for hiding this comment

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

This sounds like it would pretty straightforward to rename the modules as part of running generate.sh. I agree that we should put them into the namespace that we want.

Copy link
Member

Choose a reason for hiding this comment

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

Also, how do you feel about formatting the code as part of generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sounds like it would pretty straightforward to rename the modules as part of running generate.sh

I imagine we could do this with some mvs and seds, but it would be something we might have to fiddle with again in the future when upgrading the proto-lens version. I'm also not sure how big of an advantage it would be.

I'm imagining we have this cqg-cms-api-proto library, which just contains the generated Haskell modules, like in this PR.

And then we have a separate library like cqg-cms-api-client, which contains the higher-level functions, intended for use by end-users (which in this case, would be our FCM libraries in the bitnomial repo).

Right now, my plan is to set up the cqg-cms-api-client package so it is fully-usable as-is, and re-exports everything necessary from the cqg-cms-api-proto library. So end-users wouldn't have to touch the cqg-cms-api-proto library at all, it would just be an internal implementation detail.

As long as end-users don't have to directly use cqg-cms-api-proto, I imagine it would be fine to leave the module names as Proto.CMS.* and Proto.Common.*.

how do you feel about formatting the code as part of generation?

I think this would be relatively straightforward to add, but:

  1. The generated code is so verbose that it is pretty hard to read. I don't think that a different formatting style would make it much easier.
  2. In my experience, proto-lens follows a pretty good pattern, so the generated protobuf Haskell modules are pretty easy to use once you get the hang of proto-lens. In practice it feels easier to look at the haddocks or the underlying .proto files (as opposed to the source of the generated Haskell files).
  3. It appears that the generated code at least has a consistent formatting (even if it is not the formatting style we normally use).

@GambolingPangolin GambolingPangolin merged commit 76735aa into master Jun 4, 2024
1 check passed
@cdepillabout cdepillabout deleted the cqg-cms-api-proto branch June 5, 2024 05:31
Copy link

Add Protobuf Generator

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.

2 participants