Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class File < ::Protobuf::Message; end



##
# File Options
#
set_option :java_package, "com.google.protobuf.compiler"
set_option :java_outer_classname, "PluginProtos"


##
# Message Fields
#
Expand Down
1 change: 0 additions & 1 deletion lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class Location
repeated ::Google::Protobuf::SourceCodeInfo::Location, :location, 1
end


end

end
Expand Down
9 changes: 7 additions & 2 deletions lib/protobuf/field/varint_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def self.encode(value, use_cache = true)
##
# Public Instance Methods
#

def acceptable?(val)
int_val = coerce!(val)
int_val = if val.is_a?(Integer)
return true if val >= 0 && val < INT32_MAX # return quickly for smallest integer size, hot code path
val
else
coerce!(val)
end

int_val >= self.class.min && int_val <= self.class.max
rescue
false
Expand Down
24 changes: 19 additions & 5 deletions spec/lib/protobuf/generators/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ def compile
end

it 'serializes messages' do
output_string = <<-STRING
{ :foo => "space",
:bar => [{
:foo => "station",
:bar => { :foo => "orbit" },
:boom => 123,
:goat => ::MyEnum::FOO,
:bam => false,
:fire => 3.5 }],
:boom => 456,
:goat => ::MyEnum::BOO,
:bam => true, :fire => 1.2 }
STRING

output_string.lstrip!
output_string.rstrip!
output_string.delete!("\n")
output_string.squeeze!(" ")
expect(generator.serialize_value(MyMessage3.new(
:foo => 'space',
:bar => [MyMessage2.new(
Expand All @@ -125,11 +143,7 @@ def compile
:goat => MyEnum::BOO,
:bam => true,
:fire => 1.2,
))).to eq(
'{ :foo => "space", :bar => [{ '\
':foo => "station", :bar => { :foo => "orbit" }, :boom => 123, :goat => ::MyEnum::FOO, :bam => false, :fire => 3.5 '\
'}], :boom => 456, :goat => ::MyEnum::BOO, :bam => true, :fire => 1.2 }'
)
))).to eq(output_string)
end

it 'serializes enums' do
Expand Down