Skip to content

required fields not generated? #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kengruven opened this issue Feb 18, 2025 · 1 comment
Open

required fields not generated? #263

kengruven opened this issue Feb 18, 2025 · 1 comment

Comments

@kengruven
Copy link

(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
Copy link
Author

In the file ProtoBuf.jl/src/codegen/encode_methods.jl I tried changing line 8 from:

_encode_condition(@nospecialize(f::FieldType), ctx::Context) = "x.$(jl_fieldname(f)) != $(jl_init_value(f, ctx))"

to:

import ..Parsers: REQUIRED
_encode_condition(@nospecialize(f::FieldType), ctx::Context) = (f.label == REQUIRED ? "true" : "x.$(jl_fieldname(f)) != $(jl_init_value(f, ctx))")

and my program was able to send the number 0 to OLA without any problems! Of course, this is just a sloppy proof-of-concept that happens to work in one case. I'm certain this isn't the correct solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant