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

Generic runtime representation #106

Open
tim2CF opened this issue Sep 4, 2020 · 7 comments
Open

Generic runtime representation #106

tim2CF opened this issue Sep 4, 2020 · 7 comments

Comments

@tim2CF
Copy link

tim2CF commented Sep 4, 2020

Hello! Is there some sort of generic runtime representation of protobuf types generated from protobuf files? Something similar to this (but for protobuf) https://hackage.haskell.org/package/aeson-1.5.3.0/docs/Data-Aeson.html#t:Value

@Gabriella439
Copy link
Contributor

@tim2CF: There is not a generic representation, as far as I know.

@tim2CF
Copy link
Author

tim2CF commented Sep 4, 2020

I meant not exactly GHC.Generics, but some sort of protobuf AST which can be used to fold protobuf messages in generic way. Or at least some sort of protobuf reflection API which can give information about message field types and indexes in terms of Haskell.

@Gabriella439
Copy link
Contributor

@tim2CF: Yeah, I understand what you mean, but I don't think there is such a representation. Protobuf is not like CBOR or JSON so there is no standard generic AST for the data.

@tim2CF
Copy link
Author

tim2CF commented Sep 4, 2020

Well, maybe not data itself, but schema of data. Information about, types, names and indexes of messages in form of Haskell terms. Protobuf reflection API exists in some implementations. I'm not sure is it part of standard itself or not, but you can take a look for example to other Haskell implementation here

https://hackage.haskell.org/package/proto-lens-0.7.0.0/docs/Data-ProtoLens-Message.html#g:1

It's quite useful in some cases, for example for generalized Arbitrary instance for any protobuf message

http://hackage.haskell.org/package/proto-lens-arbitrary-0.1.2.9/docs/src/Data.ProtoLens.Arbitrary.html#arbitraryMessage

@Gabriella439
Copy link
Contributor

@tim2CF: Oh, so if all you need is the AST of the .proto file then our proto3-suite package supports that. This module is the entry point to parsing the AST from a .proto file: https://hackage.haskell.org/package/proto3-suite-0.4.0.0/docs/Proto3-Suite-DotProto-Generate.html

@tim2CF
Copy link
Author

tim2CF commented Sep 4, 2020

@Gabriel439 cool, thanks for the link! I'm building library for signing/verifying protobuf messages in deterministic way, and wanna to support both Haskell implementations, because I'm using both of them. We just started this library, but eventually it will be there

https://github.com/coingaming/signable

In general for me more preferable way is to get proto information through type class instance, like in proto-lens (I basically can give Proxy MyMessage and get all meta info about MyMessage). I think in your library I can get all meta information exactly the same way through dotProto method, because every generated protobuf message implements it, right?

https://hackage.haskell.org/package/proto3-suite-0.4.0.0/docs/Proto3-Suite-Class.html#v:dotProto

@Gabriella439
Copy link
Contributor

@tim2CF: Yeah, I believe the dotProto method will allow you to retrieve metadata about fields

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