protobuf 2.4.1 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/protobuf/message.rb +18 -16
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/message_spec.rb +12 -0
- metadata +3 -3
data/lib/protobuf/message.rb
CHANGED
@@ -35,7 +35,7 @@ module Protobuf
|
|
35
35
|
raise TagCollisionError, %!{Field number #{tag} has already been used in "#{self.name}" by field "#{fname}".!
|
36
36
|
end
|
37
37
|
|
38
|
-
field_definition = Field.build(self, rule, type, fname, tag, options)
|
38
|
+
field_definition = ::Protobuf::Field.build(self, rule, type, fname, tag, options)
|
39
39
|
field_name_hash[fname] = tag
|
40
40
|
field_array[tag] = field_definition
|
41
41
|
end
|
@@ -160,24 +160,15 @@ module Protobuf
|
|
160
160
|
|
161
161
|
def each_field_for_serialization
|
162
162
|
all_fields.each do |field|
|
163
|
-
next unless
|
163
|
+
next unless _field_must_be_serialized?(field)
|
164
164
|
|
165
165
|
value = @values[field.name]
|
166
166
|
|
167
|
-
if
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
if has_field?(field.name) || field.required?
|
175
|
-
if value.present? || [true, false].include?(value)
|
176
|
-
yield(field, value)
|
177
|
-
else
|
178
|
-
# Only way you can get here is if you are required and not present
|
179
|
-
raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}"
|
180
|
-
end
|
167
|
+
if value.present? || [true, false].include?(value)
|
168
|
+
yield(field, value)
|
169
|
+
else
|
170
|
+
# Only way you can get here is if you are required and not present
|
171
|
+
raise ::Protobuf::SerializationError, "#{field.name} is required on #{field.message_class}"
|
181
172
|
end
|
182
173
|
end
|
183
174
|
end
|
@@ -347,6 +338,17 @@ module Protobuf
|
|
347
338
|
object
|
348
339
|
end
|
349
340
|
|
341
|
+
def _field_must_be_serialized?(field)
|
342
|
+
return true if field.required?
|
343
|
+
|
344
|
+
if field.repeated? && has_field?(field.name)
|
345
|
+
@values[field.name].compact!
|
346
|
+
@values.delete(field.name) if @values[field.name].empty?
|
347
|
+
end
|
348
|
+
|
349
|
+
return has_field?(field.name)
|
350
|
+
end
|
351
|
+
|
350
352
|
# Encode key and value, and write to +stream+.
|
351
353
|
def write_pair(stream, field, value)
|
352
354
|
key = (field.tag << 3) | field.wire_type
|
data/lib/protobuf/version.rb
CHANGED
@@ -31,6 +31,18 @@ describe Protobuf::Message do
|
|
31
31
|
}.to raise_error(Protobuf::SerializationError, /required/i)
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
context "repeated fields" do
|
36
|
+
let(:message) { ::Test::Resource.new(:name => "something") }
|
37
|
+
let(:stream) { StringIO.new }
|
38
|
+
|
39
|
+
it "does not raise an error when repeated fields are []" do
|
40
|
+
expect {
|
41
|
+
message.repeated_enum = []
|
42
|
+
message.serialize_to(stream)
|
43
|
+
}.to_not raise_error
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
describe "boolean predicate methods" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -499,7 +499,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
499
499
|
version: '0'
|
500
500
|
segments:
|
501
501
|
- 0
|
502
|
-
hash: -
|
502
|
+
hash: -3586960575258099872
|
503
503
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
504
504
|
none: false
|
505
505
|
requirements:
|
@@ -508,7 +508,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
508
508
|
version: '0'
|
509
509
|
segments:
|
510
510
|
- 0
|
511
|
-
hash: -
|
511
|
+
hash: -3586960575258099872
|
512
512
|
requirements: []
|
513
513
|
rubyforge_project:
|
514
514
|
rubygems_version: 1.8.24
|