Search code examples
c#protocol-buffersgrpcprotobuf-net

Check the presence of a message type in protoBuf


I am new to gRPC and wanted to check the presence of a message field in the C# language. I know that we can use the hasField() property in Java but there is no mention of any such property in C#.

message foo
{...}

message bar{
foo data=1;
}

How can I check whether the data field in message bar is set or not?


Solution

  • Unless marked as optional, the field will be present in every message.

    See optional

    The fields in data (type foo) may be unset, in which case defaults are used. See the language guide.

    NOTE Your question concerns protobufs (the messages that are sent) not gRPC (the RPC mechanism) specifically.