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.
- I downloaded protoc from here
- A proto file called Hazzer.proto contains:
//----- Hazzer.proto Begin ----- syntax = "proto3";
message Payload
{
int32 pay = 1;
}
message Conveyor
{
Payload load = 1;
optional int32 sequence = 2;
}
//----- Hazzer.proto End-----
- I compile Hazzer.proto (which resides in a folder called Proto): protoc.exe --csharp_out=./ProtocOutput ./Protos/Hazzer.proto
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 fornullis used as the "has" test; i.e.(and yes, it could have used
int?forSequence, but: it doesn't)