ProtoBuf.jl icon indicating copy to clipboard operation
ProtoBuf.jl copied to clipboard

`required` fields not generated?

Open kengruven opened this issue 8 months ago • 2 comments

(I'm relatively inexperienced with protobufs, and also with Julia, so forgive me if my diagnosis here is wrong!)

I'm trying to use ProtoBuf.jl to send commands from Julia to OLA, which has a protobuf (2) RPC interface. I was able to successfully generate .jl files from their two .proto files, and encode messages with them, but my messages aren't being received correctly for some reason.

I tried running netcat (as a server) to capture the network traffic that the official OLA tools generate, and what my program generates, to compare them.

When sending a single command with a single DmxData message, eventually I narrowed it down to one difference. In the syntax of Protoscope, the official OLA client sends a DmxData which looks like:

{
  1: 0
  2: {`010203`}
  3: 100
}

while my program which uses ProtoBuf.jl-generated encode(io, DmxData) sends:

{
  2: {`010203`}
  3: 100
}

when the first field is 0. Field 1 is required int32 universe = 1, and by my reading of the protobuf reference, that means it should always be included on the wire.

The generated line of Julia which encodes this particular field looks like:

    x.universe != zero(Int32) && PB.encode(e, 1, x.universe)

which comes from print_field_encode_expr(io, f::FieldType, ctx::Context), which checks encode_condition -- but nothing there seems to check if the field is required.

Thanks!

kengruven avatar Feb 18 '25 00:02 kengruven