0

I'm new to gRPC, and I've tried to search this, but can't seem to find any reference to method calls that send and receive primitive types. I created a method where I send a string, and return a bool (in C#, bool IsPhoneNumberValid ( string PhoneNumber)

In their simple sample posted on their web site - HelloRequest, and HelloReply are listed as a message with a single field. Is this the standard practise in gRPC? I would like to see a reference to this is as the best practise, or what am I missing in the documentation?

codeputer
  • 1,987
  • 3
  • 19
  • 45

1 Answers1

1

It is my understanding that the parameter and return type for all gRPC method calls are to be protobuf messages. Since the primitive types are not protobuf messages on their own, then they are not accepted as valid parameters. Google provides some wrapper types that are, in my understanding, to support nullable types and are in fact protobuf messages (google.protobuf.StringValue). You can pass these as parameters to methods.

Rob Goodwin
  • 2,676
  • 2
  • 27
  • 47
  • 2
    That is the correct understanding. We typically would encourage making a message specifically for that one method instead of using the wrapper messages. The reasoning is similar to https://stackoverflow.com/a/50996412/4690866 , as it allows you to add new fields later. – Eric Anderson Aug 06 '19 at 21:01