lib/protobuf/generators/field_generator.rb in protobuf-3.7.0.pre2 vs lib/protobuf/generators/field_generator.rb in protobuf-3.7.0.pre3
- old
+ new
@@ -5,13 +5,13 @@
class FieldGenerator < Base
##
# Constants
#
- PROTO_INFINITY_DEFAULT = /^inf$/i.freeze
- PROTO_NEGATIVE_INFINITY_DEFAULT = /^-inf$/i.freeze
- PROTO_NAN_DEFAULT = /^nan$/i.freeze
+ PROTO_INFINITY_DEFAULT = /^inf$/i
+ PROTO_NEGATIVE_INFINITY_DEFAULT = /^-inf$/i
+ PROTO_NAN_DEFAULT = /^nan$/i
RUBY_INFINITY_DEFAULT = '::Float::INFINITY'.freeze
RUBY_NEGATIVE_INFINITY_DEFAULT = '-::Float::INFINITY'.freeze
RUBY_NAN_DEFAULT = '::Float::NAN'.freeze
##
@@ -82,10 +82,17 @@
opts = {}
opts[:default] = default_value if defaulted?
opts[:packed] = 'true' if packed?
opts[:deprecated] = 'true' if deprecated?
opts[:extension] = 'true' if extension?
+ if descriptor.options
+ descriptor.options.each_field do |field_option|
+ next unless descriptor.options.field?(field_option.name)
+ option_value = descriptor.options[field_option.name]
+ opts[field_option.fully_qualified_name] = serialize_value(option_value)
+ end
+ end
opts
end
end
def packed?
@@ -106,10 +113,16 @@
end
private
def enum_default_value
- "#{type_name}::#{verbatim_default_value}"
+ optionally_upcased_default =
+ if ENV.key?('PB_UPCASE_ENUMS')
+ verbatim_default_value.upcase
+ else
+ verbatim_default_value
+ end
+ "#{type_name}::#{optionally_upcased_default}"
end
def float_double_default_value
case verbatim_default_value
when PROTO_INFINITY_DEFAULT then