protobuf-cucumber 3.10.4 → 3.10.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protobuf/field/int64_field.rb +7 -0
- data/lib/protobuf/field/sint64_field.rb +7 -0
- data/lib/protobuf/field/uint64_field.rb +7 -0
- data/lib/protobuf/message.rb +8 -4
- data/lib/protobuf/version.rb +1 -1
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/int64_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +26 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +26 -0
- data/spec/lib/protobuf/message_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc5a3e75ddaabfabd15289e76ddf4c16ae40a5a8107c515d8cb605a90bf51716
|
4
|
+
data.tar.gz: 6feeaf6f26b112f74b117155eafd1219b2407e9b3c23b8bbdbcfe865498924a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f489187daae60da534b03eec2ba25e2cb5800d3e27496e5340e4a18bf3573f5dda1e0986bc87e79d3e85ccd477b8ce022c275135e4c863443b1accba1962cb9
|
7
|
+
data.tar.gz: cb46bbeeac294ba9a5dd7b70d2a01b9ebbd3e742ff64ca1ae72d78d36bef9afd1c4c4d417be19d8c1052416c952952ac0872c75f00347df45eb00e5a2819b882
|
data/lib/protobuf/message.rb
CHANGED
@@ -158,7 +158,7 @@ module Protobuf
|
|
158
158
|
def to_json_hash(options = {})
|
159
159
|
result = {}
|
160
160
|
|
161
|
-
|
161
|
+
proto3 = options[:proto3] || options[:lower_camel_case]
|
162
162
|
|
163
163
|
@values.each_key do |field_name|
|
164
164
|
value = self[field_name]
|
@@ -169,13 +169,17 @@ module Protobuf
|
|
169
169
|
hashed_value = if value.respond_to?(:to_json_hash_value) && !field.is_a?(::Protobuf::Field::EnumField)
|
170
170
|
value.to_json_hash_value(options)
|
171
171
|
elsif field.respond_to?(:json_encode)
|
172
|
-
field.json_encode(value)
|
172
|
+
field.json_encode(value, options)
|
173
173
|
else
|
174
174
|
value
|
175
175
|
end
|
176
176
|
|
177
|
-
|
178
|
-
|
177
|
+
if proto3 && (hashed_value.nil? || value == field.default)
|
178
|
+
result.delete(field.name)
|
179
|
+
else
|
180
|
+
key = proto3 ? field.name.to_s.camelize(:lower).to_sym : field.name
|
181
|
+
result[key] = hashed_value
|
182
|
+
end
|
179
183
|
end
|
180
184
|
|
181
185
|
result
|
data/lib/protobuf/version.rb
CHANGED
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Fixed64Field do
|
|
4
4
|
|
5
5
|
it_behaves_like :packable_field, described_class
|
6
6
|
|
7
|
+
let(:message) do
|
8
|
+
Class.new(::Protobuf::Message) do
|
9
|
+
optional :fixed64, :some_field, 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://developers.google.com/protocol-buffers/docs/proto3#json
|
14
|
+
describe '.{to_json, from_json}' do
|
15
|
+
it 'serialises 0' do
|
16
|
+
instance = message.new(some_field: 0)
|
17
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
18
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'serialises max value' do
|
22
|
+
instance = message.new(some_field: described_class.max)
|
23
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"18446744073709551615"}')
|
24
|
+
expect(instance.to_json).to eq('{"some_field":18446744073709551615}')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'serialises min value' do
|
28
|
+
instance = message.new(some_field: described_class.min)
|
29
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
30
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
31
|
+
end
|
32
|
+
end
|
7
33
|
end
|
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Int64Field do
|
|
4
4
|
|
5
5
|
it_behaves_like :packable_field, described_class
|
6
6
|
|
7
|
+
let(:message) do
|
8
|
+
Class.new(::Protobuf::Message) do
|
9
|
+
optional :int64, :some_field, 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://developers.google.com/protocol-buffers/docs/proto3#json
|
14
|
+
describe '.{to_json, from_json}' do
|
15
|
+
it 'serialises 0' do
|
16
|
+
instance = message.new(some_field: 0)
|
17
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
18
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'serialises max value' do
|
22
|
+
instance = message.new(some_field: described_class.max)
|
23
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
|
24
|
+
expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'serialises min value' do
|
28
|
+
instance = message.new(some_field: described_class.min)
|
29
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
|
30
|
+
expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
|
31
|
+
end
|
32
|
+
end
|
7
33
|
end
|
@@ -6,4 +6,30 @@ RSpec.describe Protobuf::Field::Sfixed64Field do
|
|
6
6
|
let(:value) { [-1, 0, 1] }
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:message) do
|
10
|
+
Class.new(::Protobuf::Message) do
|
11
|
+
optional :sfixed64, :some_field, 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# https://developers.google.com/protocol-buffers/docs/proto3#json
|
16
|
+
describe '.{to_json, from_json}' do
|
17
|
+
it 'serialises 0' do
|
18
|
+
instance = message.new(some_field: 0)
|
19
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
20
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'serialises max value' do
|
24
|
+
instance = message.new(some_field: described_class.max)
|
25
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
|
26
|
+
expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'serialises min value as string' do
|
30
|
+
instance = message.new(some_field: described_class.min)
|
31
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
|
32
|
+
expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
|
33
|
+
end
|
34
|
+
end
|
9
35
|
end
|
@@ -6,4 +6,30 @@ RSpec.describe Protobuf::Field::Sint64Field do
|
|
6
6
|
let(:value) { [-1, 0, 1] }
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:message) do
|
10
|
+
Class.new(::Protobuf::Message) do
|
11
|
+
optional :sint64, :some_field, 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# https://developers.google.com/protocol-buffers/docs/proto3#json
|
16
|
+
describe '.{to_json, from_json}' do
|
17
|
+
it 'serialises 0' do
|
18
|
+
instance = message.new(some_field: 0)
|
19
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
20
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'serialises max value as string' do
|
24
|
+
instance = message.new(some_field: described_class.max)
|
25
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"9223372036854775807"}')
|
26
|
+
expect(instance.to_json).to eq('{"some_field":9223372036854775807}')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'serialises min value as string' do
|
30
|
+
instance = message.new(some_field: described_class.min)
|
31
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"-9223372036854775808"}')
|
32
|
+
expect(instance.to_json).to eq('{"some_field":-9223372036854775808}')
|
33
|
+
end
|
34
|
+
end
|
9
35
|
end
|
@@ -4,4 +4,30 @@ RSpec.describe Protobuf::Field::Uint64Field do
|
|
4
4
|
|
5
5
|
it_behaves_like :packable_field, described_class
|
6
6
|
|
7
|
+
let(:message) do
|
8
|
+
Class.new(::Protobuf::Message) do
|
9
|
+
optional :uint64, :some_field, 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://developers.google.com/protocol-buffers/docs/proto3#json
|
14
|
+
describe '.{to_json, from_json}' do
|
15
|
+
it 'serialises 0' do
|
16
|
+
instance = message.new(some_field: 0)
|
17
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
18
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'serialises max value' do
|
22
|
+
instance = message.new(some_field: described_class.max)
|
23
|
+
expect(instance.to_json(proto3: true)).to eq('{"someField":"18446744073709551615"}')
|
24
|
+
expect(instance.to_json).to eq('{"some_field":18446744073709551615}')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'serialises min value' do
|
28
|
+
instance = message.new(some_field: described_class.min)
|
29
|
+
expect(instance.to_json(proto3: true)).to eq('{}')
|
30
|
+
expect(instance.to_json).to eq('{"some_field":0}')
|
31
|
+
end
|
32
|
+
end
|
7
33
|
end
|
@@ -438,14 +438,14 @@ RSpec.describe Protobuf::Message do
|
|
438
438
|
specify { expect(subject.to_json).to eq '{"widget_bytes":["Bo0xSFAXOmI="]}' }
|
439
439
|
end
|
440
440
|
|
441
|
-
context 'using lower
|
441
|
+
context 'using proto3 produces lower case field names' do
|
442
442
|
let(:bytes) { "\x06\x8D1HP\x17:b".force_encoding(Encoding::ASCII_8BIT) }
|
443
443
|
|
444
444
|
subject do
|
445
445
|
::Test::ResourceFindRequest.new(:widget_bytes => [bytes])
|
446
446
|
end
|
447
447
|
|
448
|
-
specify { expect(subject.to_json(:
|
448
|
+
specify { expect(subject.to_json(:proto3 => true)).to eq '{"widgetBytes":["Bo0xSFAXOmI="]}' }
|
449
449
|
end
|
450
450
|
end
|
451
451
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protobuf-cucumber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.10.
|
4
|
+
version: 3.10.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BJ Neilsen
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2020-
|
14
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|