Skip to content

Commit

Permalink
Merge pull request #148 from rwstauner/optional-fields-bitmask
Browse files Browse the repository at this point in the history
Remove artificial limit on optional field count
  • Loading branch information
rwstauner authored Jan 2, 2025
2 parents 393167a + cc0ca45 commit 2ae5913
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/protoboeuf/codegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,6 @@ def required_fields(msg)

def init_bitmask(msg)
optionals = optional_fields
raise NotImplementedError if optionals.length >= 63

if optionals.empty?
""
Expand Down
18 changes: 18 additions & 0 deletions test/codegen_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ def test_optional_fields
assert(Class.new { class_eval(gen.to_ruby) })
end

def test_many_optional_fields
unit = parse_string(<<~EOPROTO)
syntax = "proto3";
message TestManyOptionalFields {
#{(1..99).map { |i| "optional int32 a#{i} = #{i};" }.join("\n")}
}
EOPROTO
gen = CodeGen.new(unit)
klass = Class.new { class_eval(gen.to_ruby) }

msg = klass::TestManyOptionalFields.new(a59: 0, a60: 1, a99: 1)
msg = klass::TestManyOptionalFields.decode(klass::TestManyOptionalFields.encode(msg))
refute_predicate(msg, :has_a59?)
assert_predicate(msg, :has_a60?)
assert_predicate(msg, :has_a99?)
end

def test_enum_field
unit = parse_string(<<~EOPROTO)
syntax = "proto3";
Expand Down

0 comments on commit 2ae5913

Please sign in to comment.