When compiling a .proto file with syntax = "proto3", the compiler should generate a method to query the presence of a message field regardless, see documentation
Message field always explicit presence
For a field e.g. "optional int32 test = 1", after compiling the .proto file to C# code, the class contains a query-method "bool HasTest()". but, when the field is of type Singular message no query-method is generated.
//----- Hazzer.proto Begin ----- syntax = "proto3";
message Payload
{
int32 pay = 1;
}
message Conveyor
{
Payload load = 1;
optional int32 sequence = 2;
}
//----- Hazzer.proto End-----
My understanding is that under the explicit presence discipline, there should be generated a query method. Hence, in Conveyor.cs I should find "bool HasSequence()" and "bool HasLoad()".
Only HasSequence() is generated. What am I missing?
The Has...
mechanism is only needed for primitives; in the case of messages, the fact that the message itself can be tested for null
is used as the "has" test; i.e.
if (obj.Load is not null)
{
// yay, it has a value; do something funky
}
(and yes, it could have used int?
for Sequence
, but: it doesn't)