From cf35b3fdeaef531c7724ec727aa759317d904a8d Mon Sep 17 00:00:00 2001 From: Dave Benvenuti Date: Mon, 6 Jan 2025 13:45:46 -0800 Subject: [PATCH] Use setters instead of setting ivars explicitly so we get integer range checks. TODO don't know if this is right or not --- lib/protoboeuf/codegen.rb | 7 +- lib/protoboeuf/protobuf/any.rb | 23 +- lib/protoboeuf/protobuf/boolvalue.rb | 19 +- lib/protoboeuf/protobuf/bytesvalue.rb | 21 +- lib/protoboeuf/protobuf/descriptor.rb | 833 +++++++++++-------------- lib/protoboeuf/protobuf/doublevalue.rb | 19 +- lib/protoboeuf/protobuf/duration.rb | 23 +- lib/protoboeuf/protobuf/field_mask.rb | 19 +- lib/protoboeuf/protobuf/floatvalue.rb | 19 +- lib/protoboeuf/protobuf/int32value.rb | 21 +- lib/protoboeuf/protobuf/int64value.rb | 21 +- lib/protoboeuf/protobuf/stringvalue.rb | 21 +- lib/protoboeuf/protobuf/struct.rb | 69 +- lib/protoboeuf/protobuf/timestamp.rb | 23 +- lib/protoboeuf/protobuf/uint32value.rb | 21 +- lib/protoboeuf/protobuf/uint64value.rb | 21 +- 16 files changed, 524 insertions(+), 656 deletions(-) diff --git a/lib/protoboeuf/codegen.rb b/lib/protoboeuf/codegen.rb index 69d41c2..5bac7a5 100644 --- a/lib/protoboeuf/codegen.rb +++ b/lib/protoboeuf/codegen.rb @@ -957,6 +957,10 @@ def iv_name(field) "@#{field.name}" end + def setter_name(field) + "self.#{field.name}" + end + def initialize_required_field(field) <<~RUBY #{bounds_check(field, lvar_read(field)).chomp} @@ -1677,7 +1681,8 @@ def decode_code(field) decode_repeated(field) end else - decode_subtype(field, field.type, iv_name(field), "=") + # Use the setter instead of setting the instance variable directly so we get things like integer range checks + decode_subtype(field, field.type, setter_name(field), "=") end end diff --git a/lib/protoboeuf/protobuf/any.rb b/lib/protoboeuf/protobuf/any.rb index 76a2107..eee6391 100644 --- a/lib/protoboeuf/protobuf/any.rb +++ b/lib/protoboeuf/protobuf/any.rb @@ -296,7 +296,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @type_url = + self.type_url = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -419,7 +419,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @value = buff.byteslice(index, value) + self.value = buff.byteslice(index, value) index += value ## END PULL_BYTES @@ -563,18 +563,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/boolvalue.rb b/lib/protoboeuf/protobuf/boolvalue.rb index a06e8a0..e5b7af8 100644 --- a/lib/protoboeuf/protobuf/boolvalue.rb +++ b/lib/protoboeuf/protobuf/boolvalue.rb @@ -232,7 +232,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL BOOLEAN - @value = (buff.getbyte(index) == 1) + self.value = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -358,18 +358,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/bytesvalue.rb b/lib/protoboeuf/protobuf/bytesvalue.rb index fe3e8e3..95f6a0a 100644 --- a/lib/protoboeuf/protobuf/bytesvalue.rb +++ b/lib/protoboeuf/protobuf/bytesvalue.rb @@ -287,7 +287,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @value = buff.byteslice(index, value) + self.value = buff.byteslice(index, value) index += value ## END PULL_BYTES @@ -417,18 +417,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/descriptor.rb b/lib/protoboeuf/protobuf/descriptor.rb index 5adcfd0..1b4f923 100644 --- a/lib/protoboeuf/protobuf/descriptor.rb +++ b/lib/protoboeuf/protobuf/descriptor.rb @@ -541,18 +541,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FileDescriptorProto @@ -1053,7 +1050,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -1176,7 +1174,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @package = + self.package = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -2364,7 +2362,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::FileOptions.allocate.decode_from( buff, index, @@ -2493,7 +2491,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @source_code_info = + self.source_code_info = ProtoBoeuf::Protobuf::SourceCodeInfo.allocate.decode_from( buff, index, @@ -2619,7 +2617,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @syntax = + self.syntax = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -2688,7 +2686,7 @@ def decode_from(buff, index, len) if tag == 0x70 found = true ## PULL_INT64 - @edition = + self.edition = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -3391,18 +3389,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class DescriptorProto @@ -3717,7 +3712,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT32 - @start = + self.start = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -3848,7 +3843,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @end = + self.end = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -4037,7 +4032,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::ExtensionRangeOptions.allocate.decode_from( buff, index, @@ -4243,18 +4238,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end @@ -4543,7 +4535,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT32 - @start = + self.start = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -4674,7 +4666,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @end = + self.end = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -4891,18 +4883,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -5301,7 +5290,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -6243,7 +6233,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::MessageOptions.allocate.decode_from( buff, index, @@ -7091,18 +7081,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class ExtensionRangeOptions @@ -7451,7 +7438,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT32 - @number = + self.number = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -7637,7 +7624,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @full_name = + self.full_name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -7761,7 +7748,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @type = + self.type = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -7830,7 +7817,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL BOOLEAN - @reserved = (buff.getbyte(index) == 1) + self.reserved = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -7897,7 +7884,7 @@ def decode_from(buff, index, len) if tag == 0x30 found = true ## PULL BOOLEAN - @repeated = (buff.getbyte(index) == 1) + self.repeated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -8083,18 +8070,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end module VerificationState @@ -8734,7 +8718,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -8805,7 +8789,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT64 - @verification = + self.verification = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -9162,18 +9146,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FieldDescriptorProto @@ -9823,7 +9804,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -9891,7 +9873,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT32 - @number = + self.number = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -10022,7 +10004,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_INT64 - @label = + self.label = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -10153,7 +10135,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL_INT64 - @type = + self.type = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -10339,7 +10321,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @type_name = + self.type_name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -10463,7 +10445,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @extendee = + self.extendee = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -10587,7 +10569,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @default_value = + self.default_value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -10656,7 +10638,7 @@ def decode_from(buff, index, len) if tag == 0x48 found = true ## PULL_INT32 - @oneof_index = + self.oneof_index = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -10842,7 +10824,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @json_name = + self.json_name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -10969,7 +10951,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::FieldOptions.allocate.decode_from( buff, index, @@ -11040,7 +11022,7 @@ def decode_from(buff, index, len) if tag == 0x88 found = true ## PULL BOOLEAN - @proto3_optional = (buff.getbyte(index) == 1) + self.proto3_optional = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -11363,18 +11345,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class OneofDescriptorProto @@ -11698,7 +11677,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -11824,7 +11804,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::OneofOptions.allocate.decode_from( buff, index, @@ -12006,18 +11986,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class EnumDescriptorProto @@ -12313,7 +12290,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT32 - @start = + self.start = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -12444,7 +12421,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @end = + self.end = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -12661,18 +12638,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -13021,7 +12995,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -13283,7 +13258,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::EnumOptions.allocate.decode_from( buff, index, @@ -13861,18 +13836,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class EnumValueDescriptorProto @@ -14224,7 +14196,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -14292,7 +14265,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @number = + self.number = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -14481,7 +14454,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::EnumValueOptions.allocate.decode_from( buff, index, @@ -14682,18 +14655,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class ServiceDescriptorProto @@ -15026,7 +14996,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -15288,7 +15259,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::ServiceOptions.allocate.decode_from( buff, index, @@ -15524,18 +15495,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class MethodDescriptorProto @@ -15942,7 +15910,8 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) + self.name = + buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value ## END PULL_STRING @@ -16065,7 +16034,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @input_type = + self.input_type = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -16189,7 +16158,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @output_type = + self.output_type = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -16316,7 +16285,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @options = + self.options = ProtoBoeuf::Protobuf::MethodOptions.allocate.decode_from( buff, index, @@ -16387,7 +16356,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL BOOLEAN - @client_streaming = (buff.getbyte(index) == 1) + self.client_streaming = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -16454,7 +16423,7 @@ def decode_from(buff, index, len) if tag == 0x30 found = true ## PULL BOOLEAN - @server_streaming = (buff.getbyte(index) == 1) + self.server_streaming = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -16684,18 +16653,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FileOptions @@ -17420,7 +17386,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @java_package = + self.java_package = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -17544,7 +17510,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @java_outer_classname = + self.java_outer_classname = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -17613,7 +17579,7 @@ def decode_from(buff, index, len) if tag == 0x50 found = true ## PULL BOOLEAN - @java_multiple_files = (buff.getbyte(index) == 1) + self.java_multiple_files = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -17680,7 +17646,7 @@ def decode_from(buff, index, len) if tag == 0xa0 found = true ## PULL BOOLEAN - @java_generate_equals_and_hash = (buff.getbyte(index) == 1) + self.java_generate_equals_and_hash = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -17747,7 +17713,7 @@ def decode_from(buff, index, len) if tag == 0xd8 found = true ## PULL BOOLEAN - @java_string_check_utf8 = (buff.getbyte(index) == 1) + self.java_string_check_utf8 = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -17814,7 +17780,7 @@ def decode_from(buff, index, len) if tag == 0x48 found = true ## PULL_INT64 - @optimize_for = + self.optimize_for = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -18000,7 +17966,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @go_package = + self.go_package = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -18069,7 +18035,7 @@ def decode_from(buff, index, len) if tag == 0x80 found = true ## PULL BOOLEAN - @cc_generic_services = (buff.getbyte(index) == 1) + self.cc_generic_services = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -18136,7 +18102,7 @@ def decode_from(buff, index, len) if tag == 0x88 found = true ## PULL BOOLEAN - @java_generic_services = (buff.getbyte(index) == 1) + self.java_generic_services = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -18203,7 +18169,7 @@ def decode_from(buff, index, len) if tag == 0x90 found = true ## PULL BOOLEAN - @py_generic_services = (buff.getbyte(index) == 1) + self.py_generic_services = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -18270,7 +18236,7 @@ def decode_from(buff, index, len) if tag == 0xb8 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -18337,7 +18303,7 @@ def decode_from(buff, index, len) if tag == 0xf8 found = true ## PULL BOOLEAN - @cc_enable_arenas = (buff.getbyte(index) == 1) + self.cc_enable_arenas = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -18459,7 +18425,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @objc_class_prefix = + self.objc_class_prefix = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -18583,7 +18549,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @csharp_namespace = + self.csharp_namespace = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -18707,7 +18673,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @swift_prefix = + self.swift_prefix = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -18831,7 +18797,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @php_class_prefix = + self.php_class_prefix = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -18955,7 +18921,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @php_namespace = + self.php_namespace = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -19079,7 +19045,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @php_metadata_namespace = + self.php_metadata_namespace = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -19203,7 +19169,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @ruby_package = + self.ruby_package = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -19330,7 +19296,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -19961,18 +19927,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class MessageOptions @@ -20335,7 +20298,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL BOOLEAN - @message_set_wire_format = (buff.getbyte(index) == 1) + self.message_set_wire_format = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -20402,7 +20365,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL BOOLEAN - @no_standard_descriptor_accessor = (buff.getbyte(index) == 1) + self.no_standard_descriptor_accessor = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -20469,7 +20432,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -20536,7 +20499,7 @@ def decode_from(buff, index, len) if tag == 0x38 found = true ## PULL BOOLEAN - @map_entry = (buff.getbyte(index) == 1) + self.map_entry = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -20603,7 +20566,8 @@ def decode_from(buff, index, len) if tag == 0x58 found = true ## PULL BOOLEAN - @deprecated_legacy_json_field_conflicts = (buff.getbyte(index) == 1) + self.deprecated_legacy_json_field_conflicts = + (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -20728,7 +20692,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -21151,18 +21115,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FieldOptions @@ -21437,7 +21398,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT64 - @edition = + self.edition = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -21623,7 +21584,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @value = + self.value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -21773,18 +21734,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end @@ -22094,7 +22052,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @edition_introduced = + self.edition_introduced = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -22225,7 +22183,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT64 - @edition_deprecated = + self.edition_deprecated = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -22411,7 +22369,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @deprecation_warning = + self.deprecation_warning = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -22480,7 +22438,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_INT64 - @edition_removed = + self.edition_removed = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -22730,18 +22688,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end module CType @@ -23354,7 +23309,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @ctype = + self.ctype = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -23485,7 +23440,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL BOOLEAN - @packed = (buff.getbyte(index) == 1) + self.packed = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -23552,7 +23507,7 @@ def decode_from(buff, index, len) if tag == 0x30 found = true ## PULL_INT64 - @jstype = + self.jstype = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -23683,7 +23638,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL BOOLEAN - @lazy = (buff.getbyte(index) == 1) + self.lazy = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -23750,7 +23705,7 @@ def decode_from(buff, index, len) if tag == 0x78 found = true ## PULL BOOLEAN - @unverified_lazy = (buff.getbyte(index) == 1) + self.unverified_lazy = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -23817,7 +23772,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -23884,7 +23839,7 @@ def decode_from(buff, index, len) if tag == 0x50 found = true ## PULL BOOLEAN - @weak = (buff.getbyte(index) == 1) + self.weak = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -23951,7 +23906,7 @@ def decode_from(buff, index, len) if tag == 0x80 found = true ## PULL BOOLEAN - @debug_redact = (buff.getbyte(index) == 1) + self.debug_redact = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -24018,7 +23973,7 @@ def decode_from(buff, index, len) if tag == 0x88 found = true ## PULL_INT64 - @retention = + self.retention = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -24481,7 +24436,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -24610,7 +24565,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @feature_support = + self.feature_support = ProtoBoeuf::Protobuf::FieldOptions::FeatureSupport.allocate.decode_from( buff, index, @@ -25231,18 +25186,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class OneofOptions @@ -25559,7 +25511,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -25918,18 +25870,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class EnumOptions @@ -26252,7 +26201,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL BOOLEAN - @allow_alias = (buff.getbyte(index) == 1) + self.allow_alias = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -26319,7 +26268,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -26386,7 +26335,8 @@ def decode_from(buff, index, len) if tag == 0x30 found = true ## PULL BOOLEAN - @deprecated_legacy_json_field_conflicts = (buff.getbyte(index) == 1) + self.deprecated_legacy_json_field_conflicts = + (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -26511,7 +26461,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -26908,18 +26858,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class EnumValueOptions @@ -27241,7 +27188,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -27366,7 +27313,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -27437,7 +27384,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL BOOLEAN - @debug_redact = (buff.getbyte(index) == 1) + self.debug_redact = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -27562,7 +27509,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @feature_support = + self.feature_support = ProtoBoeuf::Protobuf::FieldOptions::FeatureSupport.allocate.decode_from( buff, index, @@ -27994,18 +27941,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class ServiceOptions @@ -28341,7 +28285,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -28412,7 +28356,7 @@ def decode_from(buff, index, len) if tag == 0x108 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -28781,18 +28725,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class MethodOptions @@ -29123,7 +29064,7 @@ def decode_from(buff, index, len) if tag == 0x108 found = true ## PULL BOOLEAN - @deprecated = (buff.getbyte(index) == 1) + self.deprecated = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -29190,7 +29131,7 @@ def decode_from(buff, index, len) if tag == 0x110 found = true ## PULL_INT64 - @idempotency_level = + self.idempotency_level = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -29379,7 +29320,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @features = + self.features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -29772,18 +29713,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class UninterpretedOption @@ -30086,7 +30024,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @name_part = + self.name_part = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -30154,7 +30092,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL BOOLEAN - @is_extension = (buff.getbyte(index) == 1) + self.is_extension = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -30294,18 +30232,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -30870,7 +30805,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @identifier_value = + self.identifier_value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -30939,7 +30874,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_UINT64 - @positive_int_value = + self.positive_int_value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -31059,7 +30994,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL_INT64 - @negative_int_value = + self.negative_int_value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -31189,7 +31124,7 @@ def decode_from(buff, index, len) end if tag == 0x31 found = true - @double_value = buff.unpack1("E", offset: index) + self.double_value = buff.unpack1("E", offset: index) index += 8 @_bitmask |= 0x0000000000000008 return self if index >= len @@ -31309,7 +31244,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @string_value = buff.byteslice(index, value) + self.string_value = buff.byteslice(index, value) index += value ## END PULL_BYTES @@ -31432,7 +31367,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @aggregate_value = + self.aggregate_value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -31686,18 +31621,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FeatureSet @@ -32205,7 +32137,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @field_presence = + self.field_presence = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -32336,7 +32268,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT64 - @enum_type = + self.enum_type = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -32467,7 +32399,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT64 - @repeated_field_encoding = + self.repeated_field_encoding = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -32598,7 +32530,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_INT64 - @utf8_validation = + self.utf8_validation = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -32729,7 +32661,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL_INT64 - @message_encoding = + self.message_encoding = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -32860,7 +32792,7 @@ def decode_from(buff, index, len) if tag == 0x30 found = true ## PULL_INT64 - @json_format = + self.json_format = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -33153,18 +33085,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class FeatureSetDefaults @@ -33462,7 +33391,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT64 - @edition = + self.edition = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -33651,7 +33580,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @overridable_features = + self.overridable_features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -33780,7 +33709,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @fixed_features = + self.fixed_features = ProtoBoeuf::Protobuf::FeatureSet.allocate.decode_from( buff, index, @@ -34016,18 +33945,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -34424,7 +34350,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_INT64 - @minimum_edition = + self.minimum_edition = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -34555,7 +34481,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL_INT64 - @maximum_edition = + self.maximum_edition = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -34826,18 +34752,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class SourceCodeInfo @@ -35612,7 +35535,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @leading_comments = + self.leading_comments = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -35736,7 +35659,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @trailing_comments = + self.trailing_comments = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -36165,18 +36088,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -36637,18 +36557,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class GeneratedCodeInfo @@ -37289,7 +37206,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @source_file = + self.source_file = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -37358,7 +37275,7 @@ def decode_from(buff, index, len) if tag == 0x18 found = true ## PULL_INT32 - @begin = + self.begin = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -37489,7 +37406,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL_INT32 - @end = + self.end = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -37620,7 +37537,7 @@ def decode_from(buff, index, len) if tag == 0x28 found = true ## PULL_INT64 - @semantic = + self.semantic = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -37935,18 +37852,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end # required field readers @@ -38407,18 +38321,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/doublevalue.rb b/lib/protoboeuf/protobuf/doublevalue.rb index 10e2c00..f522d2a 100644 --- a/lib/protoboeuf/protobuf/doublevalue.rb +++ b/lib/protoboeuf/protobuf/doublevalue.rb @@ -231,7 +231,7 @@ def decode_from(buff, index, len) if tag == 0x9 found = true - @value = buff.unpack1("E", offset: index) + self.value = buff.unpack1("E", offset: index) index += 8 return self if index >= len @@ -352,18 +352,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/duration.rb b/lib/protoboeuf/protobuf/duration.rb index 443b0b2..e4cc124 100644 --- a/lib/protoboeuf/protobuf/duration.rb +++ b/lib/protoboeuf/protobuf/duration.rb @@ -260,7 +260,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @seconds = + self.seconds = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -390,7 +390,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @nanos = + self.nanos = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -606,18 +606,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/field_mask.rb b/lib/protoboeuf/protobuf/field_mask.rb index 32cb6bb..1d899b2 100644 --- a/lib/protoboeuf/protobuf/field_mask.rb +++ b/lib/protoboeuf/protobuf/field_mask.rb @@ -432,18 +432,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/floatvalue.rb b/lib/protoboeuf/protobuf/floatvalue.rb index c26d9fa..add3803 100644 --- a/lib/protoboeuf/protobuf/floatvalue.rb +++ b/lib/protoboeuf/protobuf/floatvalue.rb @@ -231,7 +231,7 @@ def decode_from(buff, index, len) if tag == 0xd found = true - @value = buff.unpack1("e", offset: index) + self.value = buff.unpack1("e", offset: index) index += 4 return self if index >= len @@ -352,18 +352,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/int32value.rb b/lib/protoboeuf/protobuf/int32value.rb index f4d1321..12d7418 100644 --- a/lib/protoboeuf/protobuf/int32value.rb +++ b/lib/protoboeuf/protobuf/int32value.rb @@ -241,7 +241,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT32 - @value = + self.value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -438,18 +438,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/int64value.rb b/lib/protoboeuf/protobuf/int64value.rb index dc39d57..ad3ff2c 100644 --- a/lib/protoboeuf/protobuf/int64value.rb +++ b/lib/protoboeuf/protobuf/int64value.rb @@ -242,7 +242,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @value = + self.value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -439,18 +439,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/stringvalue.rb b/lib/protoboeuf/protobuf/stringvalue.rb index 4484be5..b13bd05 100644 --- a/lib/protoboeuf/protobuf/stringvalue.rb +++ b/lib/protoboeuf/protobuf/stringvalue.rb @@ -287,7 +287,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @value = + self.value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -417,18 +417,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/struct.rb b/lib/protoboeuf/protobuf/struct.rb index 40da67f..90812e4 100644 --- a/lib/protoboeuf/protobuf/struct.rb +++ b/lib/protoboeuf/protobuf/struct.rb @@ -628,18 +628,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class Value @@ -966,7 +963,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @null_value = + self.null_value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -1096,7 +1093,7 @@ def decode_from(buff, index, len) end if tag == 0x11 found = true - @number_value = buff.unpack1("E", offset: index) + self.number_value = buff.unpack1("E", offset: index) index += 8 @kind = :number_value return self if index >= len @@ -1216,7 +1213,7 @@ def decode_from(buff, index, len) raise "integer decoding error" end - @string_value = + self.string_value = buff.byteslice(index, value).force_encoding(Encoding::UTF_8) index += value @@ -1285,7 +1282,7 @@ def decode_from(buff, index, len) if tag == 0x20 found = true ## PULL BOOLEAN - @bool_value = (buff.getbyte(index) == 1) + self.bool_value = (buff.getbyte(index) == 1) index += 1 ## END PULL BOOLEAN @@ -1410,7 +1407,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @struct_value = + self.struct_value = ProtoBoeuf::Protobuf::Struct.allocate.decode_from( buff, index, @@ -1539,7 +1536,7 @@ def decode_from(buff, index, len) ## END PULL_UINT64 - @list_value = + self.list_value = ProtoBoeuf::Protobuf::ListValue.allocate.decode_from( buff, index, @@ -1804,18 +1801,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end class ListValue @@ -2284,18 +2278,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/timestamp.rb b/lib/protoboeuf/protobuf/timestamp.rb index c71ff90..11c5ad9 100644 --- a/lib/protoboeuf/protobuf/timestamp.rb +++ b/lib/protoboeuf/protobuf/timestamp.rb @@ -260,7 +260,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_INT64 - @seconds = + self.seconds = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -390,7 +390,7 @@ def decode_from(buff, index, len) if tag == 0x10 found = true ## PULL_INT32 - @nanos = + self.nanos = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -606,18 +606,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/uint32value.rb b/lib/protoboeuf/protobuf/uint32value.rb index 11b4f63..52f6eec 100644 --- a/lib/protoboeuf/protobuf/uint32value.rb +++ b/lib/protoboeuf/protobuf/uint32value.rb @@ -241,7 +241,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_UINT64 - @value = + self.value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -421,18 +421,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end diff --git a/lib/protoboeuf/protobuf/uint64value.rb b/lib/protoboeuf/protobuf/uint64value.rb index 3360617..9b9b5bd 100644 --- a/lib/protoboeuf/protobuf/uint64value.rb +++ b/lib/protoboeuf/protobuf/uint64value.rb @@ -241,7 +241,7 @@ def decode_from(buff, index, len) if tag == 0x8 found = true ## PULL_UINT64 - @value = + self.value = if (byte0 = buff.getbyte(index)) < 0x80 index += 1 byte0 @@ -421,18 +421,15 @@ def to_json_with_debug(options = {}) # By default the protobuf JSON printer should convert the field name to lowerCamelCase and use that as the JSON name. # See: https://protobuf.dev/programming-guides/json/#json-options private def json_field_name(name) - # new_name = name.gsub(/_[a-z]/) { |m| m.delete_prefix("_").capitalize } return name unless name.include?("_") - - new_name = - name - .split(/_+/) - .each_with_index - .map { |part, i| i.zero? ? part : part.downcase.capitalize } - .join - # TODO FIELD_NAME11 - #new_name == "FIELDName11" ? "fieldName11" : new_name - new_name == "FIELDName11" ? "FIELD_NAME11" : new_name + # Names like FIELD_NAME11 (all caps + underscores + numbers) should remain as-is + return name if name =~ /[A-Zd_]+/ + + name + .split(/_+/) + .each_with_index + .map { |part, i| i.zero? ? part : part.downcase.capitalize } + .join end end end