Skip to content
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

Allow unpacked repeated primitives #224

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/codegen/encode_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ function field_encode_expr(@nospecialize(f::FieldType), ctx::Context)
!isempty(encoding_val_type) && (encoding_val_type = ", Val{$encoding_val_type}")
# TODO: do we want to allow unpacked representation? Docs say that parsers must always handle both cases
# and since packed is strictly more efficient, currently we don't allow that.
# is_packed = parse(Bool, get(f.options, "packed", "false"))
# if is_packed
is_packed = parse(Bool, get(f.options, "packed", "false"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want get(f.options, "packed", "true") So people really have to make an effort to get the unpacked representation, i.e. they have to write [packed=false] in their proto files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Sorry. In my case i needed it other way around and forgot about it.

if is_packed
return "PB.encode(e, $(string(f.number)), x.$(jl_fieldname(f))$(encoding_val_type))"
# else
# return """
# for el in x.$(jl_fieldname(f))
# PB.encode(e, $(string(f.number)), el$(encoding_val_type))
# end"""
# end
else
return """
for el in x.$(jl_fieldname(f))
PB.encode(e, $(string(f.number)), el$(encoding_val_type))
end
"""
end
else
return _field_encode_expr(f, ctx)
end
Expand Down