awakesecurity / gRPC-haskell

Haskell gRPC support
https://hackage.haskell.org/package/grpc-haskell
Apache License 2.0
240 stars 76 forks source link

Generic runtime representation #106

Open tim2CF opened 4 years ago

tim2CF commented 4 years ago

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 commented 4 years ago

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

tim2CF commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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