Search code examples
flutterdartprotocol-buffersgrpc

Autogenerate .proto files in dart


I have a flutter app with a client which sends data to a server. For this I convert my data to json. At a certain point this data will need to be saved to disk as well. Someone pointed out that it would be good to use grpc for this. After reading about it I found out that there are some good benifits, thus I want to start using it.

Now I have the following problems:

1: I need to convert all my model classes to .proto files manually.

2: My model classes contain some properties. I dont see that I can place properties in the .proto files.

Question 1: Is there a way of automatically converting classes to .proto files which I am missing?

Question 2: Is there a way to place properties in my .proto files or am I thinking wrong?

I was only able to find two packages for helping with converting to proto files 'proto_generator' and 'proto_annotations', but these are not from google and thus I prefer not to use them.


Solution

  • I'm less familiar with Dart and its tooling but Google|gRPC|Protobufs don't have extensive tooling to go from language-specific implementations to the language-independent protocol buffers.

    I think there are 2 reasons for this:

    First, language-specific implementations may encourage a language-specific schema when it may be preferable to start with the generic "What methods and messages should my app's components exchange?";

    Second, you should generally not bind your application data model to the on-the-wire model. There should not be a 1:1 correspondence between the two.