bson 4.2.2-java → 4.3.0.beta-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson/array.rb +22 -14
- data/lib/bson/hash.rb +22 -14
- data/lib/bson/registry.rb +2 -2
- data/lib/bson/symbol.rb +1 -1
- data/lib/bson/timestamp.rb +24 -0
- data/lib/bson/version.rb +1 -1
- data/lib/bson_native.bundle +0 -0
- data/spec/bson/byte_buffer_spec.rb +21 -7
- data/spec/bson/document_spec.rb +18 -0
- data/spec/bson/timestamp_spec.rb +55 -0
- data/spec/spec_helper.rb +1 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6468d11868cf8ba4f947d6f2b6d0405762b22cd3
|
4
|
+
data.tar.gz: 88de4d6bc5e84d4b69a9b2899eaa467b1f18fbf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eaba01e1207c6fc15100a18ba1cd88a67ac976af7d65261d7cc219932dbedede2541a41def203ba3b4153c3acf87c5d51bf0b779fa9372e64743753c231b594
|
7
|
+
data.tar.gz: c29071d4429eb583e57620481eca61efda789dbcd19723fc1bbde761c9bc6b747fe5421aebfa7174e9db7ca231e572f514820c27d7d958af4b79a4a830ee1b5b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/bson-ruby.jar
CHANGED
Binary file
|
data/lib/bson/array.rb
CHANGED
@@ -41,15 +41,19 @@ module BSON
|
|
41
41
|
#
|
42
42
|
# @since 2.0.0
|
43
43
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
buffer.
|
48
|
-
buffer.
|
49
|
-
value
|
44
|
+
if buffer.respond_to?(:put_array)
|
45
|
+
buffer.put_array(self, validating_keys)
|
46
|
+
else
|
47
|
+
position = buffer.length
|
48
|
+
buffer.put_int32(0)
|
49
|
+
each_with_index do |value, index|
|
50
|
+
buffer.put_byte(value.bson_type)
|
51
|
+
buffer.put_cstring(index.to_s)
|
52
|
+
value.to_bson(buffer, validating_keys)
|
53
|
+
end
|
54
|
+
buffer.put_byte(NULL_BYTE)
|
55
|
+
buffer.replace_int32(position, buffer.length - position)
|
50
56
|
end
|
51
|
-
buffer.put_byte(NULL_BYTE)
|
52
|
-
buffer.replace_int32(position, buffer.length - position)
|
53
57
|
end
|
54
58
|
|
55
59
|
# Convert the array to an object id. This will only work for arrays of size
|
@@ -93,13 +97,17 @@ module BSON
|
|
93
97
|
#
|
94
98
|
# @since 2.0.0
|
95
99
|
def from_bson(buffer)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
if buffer.respond_to?(:get_array)
|
101
|
+
buffer.get_array
|
102
|
+
else
|
103
|
+
array = new
|
104
|
+
buffer.get_int32 # throw away the length
|
105
|
+
while (type = buffer.get_byte) != NULL_BYTE
|
106
|
+
buffer.get_cstring
|
107
|
+
array << BSON::Registry.get(type).from_bson(buffer)
|
108
|
+
end
|
109
|
+
array
|
101
110
|
end
|
102
|
-
array
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
data/lib/bson/hash.rb
CHANGED
@@ -38,15 +38,19 @@ module BSON
|
|
38
38
|
#
|
39
39
|
# @since 2.0.0
|
40
40
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
buffer.
|
45
|
-
buffer.
|
46
|
-
|
41
|
+
if buffer.respond_to?(:put_hash)
|
42
|
+
buffer.put_hash(self, validating_keys)
|
43
|
+
else
|
44
|
+
position = buffer.length
|
45
|
+
buffer.put_int32(0)
|
46
|
+
each do |field, value|
|
47
|
+
buffer.put_byte(value.bson_type)
|
48
|
+
buffer.put_cstring(field.to_bson_key(validating_keys))
|
49
|
+
value.to_bson(buffer, validating_keys)
|
50
|
+
end
|
51
|
+
buffer.put_byte(NULL_BYTE)
|
52
|
+
buffer.replace_int32(position, buffer.length - position)
|
47
53
|
end
|
48
|
-
buffer.put_byte(NULL_BYTE)
|
49
|
-
buffer.replace_int32(position, buffer.length - position)
|
50
54
|
end
|
51
55
|
|
52
56
|
# Converts the hash to a normalized value in a BSON document.
|
@@ -73,13 +77,17 @@ module BSON
|
|
73
77
|
#
|
74
78
|
# @since 2.0.0
|
75
79
|
def from_bson(buffer)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
if buffer.respond_to?(:get_hash)
|
81
|
+
buffer.get_hash
|
82
|
+
else
|
83
|
+
hash = Document.allocate
|
84
|
+
buffer.get_int32 # Throw away the size.
|
85
|
+
while (type = buffer.get_byte) != NULL_BYTE
|
86
|
+
field = buffer.get_cstring
|
87
|
+
hash.store(field, BSON::Registry.get(type, field).from_bson(buffer))
|
88
|
+
end
|
89
|
+
hash
|
81
90
|
end
|
82
|
-
hash
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
data/lib/bson/registry.rb
CHANGED
@@ -40,7 +40,7 @@ module BSON
|
|
40
40
|
#
|
41
41
|
# @since 2.0.0
|
42
42
|
def get(byte, field = nil)
|
43
|
-
if type = MAPPINGS[byte]
|
43
|
+
if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord])
|
44
44
|
type
|
45
45
|
else
|
46
46
|
handle_unsupported_type!(byte, field)
|
@@ -59,7 +59,7 @@ module BSON
|
|
59
59
|
#
|
60
60
|
# @since 2.0.0
|
61
61
|
def register(byte, type)
|
62
|
-
MAPPINGS.
|
62
|
+
MAPPINGS[byte.ord] = type
|
63
63
|
define_type_reader(type)
|
64
64
|
end
|
65
65
|
|
data/lib/bson/symbol.rb
CHANGED
@@ -105,7 +105,7 @@ module BSON
|
|
105
105
|
# Register this type when the module is loaded.
|
106
106
|
#
|
107
107
|
# @since 2.0.0
|
108
|
-
Registry::MAPPINGS.
|
108
|
+
Registry::MAPPINGS[BSON_TYPE.ord] = ::Symbol
|
109
109
|
end
|
110
110
|
|
111
111
|
# Enrich the core Symbol class with this module.
|
data/lib/bson/timestamp.rb
CHANGED
@@ -21,12 +21,18 @@ module BSON
|
|
21
21
|
# @since 2.0.0
|
22
22
|
class Timestamp
|
23
23
|
include JSON
|
24
|
+
include Comparable
|
24
25
|
|
25
26
|
# A timestamp is type 0x11 in the BSON spec.
|
26
27
|
#
|
27
28
|
# @since 2.0.0
|
28
29
|
BSON_TYPE = 17.chr.force_encoding(BINARY).freeze
|
29
30
|
|
31
|
+
# Error message if an object other than a Timestamp is compared with this object.
|
32
|
+
#
|
33
|
+
# @since 4.3.0
|
34
|
+
COMPARISON_ERROR_MESSAGE = 'comparison of %s with Timestamp failed'.freeze
|
35
|
+
|
30
36
|
# @!attribute seconds
|
31
37
|
# @return [ Integer ] The number of seconds.
|
32
38
|
# @since 2.0.0
|
@@ -52,6 +58,24 @@ module BSON
|
|
52
58
|
seconds == other.seconds && increment == other.increment
|
53
59
|
end
|
54
60
|
|
61
|
+
# Determine if this timestamp is greater or less than another object.
|
62
|
+
#
|
63
|
+
# @example Compare the timestamp.
|
64
|
+
# timestamp < other
|
65
|
+
#
|
66
|
+
# @param [ Object ] other The object to compare against.
|
67
|
+
#
|
68
|
+
# @return [ true, false ] The result of the comparison.
|
69
|
+
#
|
70
|
+
# @since 4.3.0
|
71
|
+
def <=>(other)
|
72
|
+
raise ArgumentError.new(COMPARISON_ERROR_MESSAGE % other.class) unless other.is_a?(Timestamp)
|
73
|
+
return 0 if self == other
|
74
|
+
a = [ seconds, increment ]
|
75
|
+
b = [ other.seconds, other.increment ]
|
76
|
+
[ a, b ].sort[0] == a ? -1 : 1
|
77
|
+
end
|
78
|
+
|
55
79
|
# Get the timestamp as JSON hash data.
|
56
80
|
#
|
57
81
|
# @example Get the timestamp as a JSON hash.
|
data/lib/bson/version.rb
CHANGED
Binary file
|
@@ -152,16 +152,30 @@ describe BSON::ByteBuffer do
|
|
152
152
|
|
153
153
|
describe '#length' do
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
context 'when the byte buffer is initialized with no bytes' do
|
156
|
+
|
157
|
+
let(:buffer) do
|
158
|
+
described_class.new
|
159
|
+
end
|
160
|
+
|
161
|
+
before do
|
162
|
+
buffer.put_int32(5)
|
163
|
+
end
|
158
164
|
|
159
|
-
|
160
|
-
|
165
|
+
it 'returns the length of the buffer' do
|
166
|
+
expect(buffer.length).to eq(4)
|
167
|
+
end
|
161
168
|
end
|
162
169
|
|
163
|
-
|
164
|
-
|
170
|
+
context 'when the byte buffer is initialized with some bytes' do
|
171
|
+
|
172
|
+
let(:buffer) do
|
173
|
+
described_class.new("#{BSON::Int32::BSON_TYPE}#{BSON::Int32::BSON_TYPE}")
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns the length' do
|
177
|
+
expect(buffer.length).to eq(2)
|
178
|
+
end
|
165
179
|
end
|
166
180
|
end
|
167
181
|
|
data/spec/bson/document_spec.rb
CHANGED
@@ -756,6 +756,24 @@ describe BSON::Document do
|
|
756
756
|
end
|
757
757
|
end
|
758
758
|
|
759
|
+
context "when the hash contains an array of hashes" do
|
760
|
+
let(:obj) do
|
761
|
+
described_class["key",[{"a" => 1}, {"b" => 2}]]
|
762
|
+
end
|
763
|
+
|
764
|
+
let(:bson) do
|
765
|
+
"#{45.to_bson}#{Array::BSON_TYPE}key#{BSON::NULL_BYTE}" +
|
766
|
+
"#{35.to_bson}"+
|
767
|
+
"#{BSON::Document::BSON_TYPE}0#{BSON::NULL_BYTE}#{12.to_bson}#{BSON::Int32::BSON_TYPE}a#{BSON::NULL_BYTE}#{1.to_bson}#{BSON::NULL_BYTE}" +
|
768
|
+
"#{BSON::Document::BSON_TYPE}1#{BSON::NULL_BYTE}#{12.to_bson}#{BSON::Int32::BSON_TYPE}b#{BSON::NULL_BYTE}#{2.to_bson}#{BSON::NULL_BYTE}" +
|
769
|
+
"#{BSON::NULL_BYTE}" +
|
770
|
+
"#{BSON::NULL_BYTE}"
|
771
|
+
end
|
772
|
+
|
773
|
+
it_behaves_like "a serializable bson element"
|
774
|
+
it_behaves_like "a deserializable bson element"
|
775
|
+
end
|
776
|
+
|
759
777
|
context "when the hash is a single level" do
|
760
778
|
|
761
779
|
let(:obj) do
|
data/spec/bson/timestamp_spec.rb
CHANGED
@@ -48,6 +48,61 @@ describe BSON::Timestamp do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
+
describe "#<=>" do
|
52
|
+
|
53
|
+
let(:timestamp) do
|
54
|
+
described_class.new(1, 10)
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the objects are equal" do
|
58
|
+
|
59
|
+
let(:other) { described_class.new(1, 10) }
|
60
|
+
|
61
|
+
it "returns 0" do
|
62
|
+
expect(timestamp).to eq(other)
|
63
|
+
expect(timestamp < other).to be(false)
|
64
|
+
expect(timestamp > other).to be(false)
|
65
|
+
expect(timestamp >= other).to be(true)
|
66
|
+
expect(timestamp <= other).to be(true)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the first object is less than the second" do
|
71
|
+
|
72
|
+
let(:other) { described_class.new(1, 15) }
|
73
|
+
|
74
|
+
it "returns -1" do
|
75
|
+
expect(timestamp <=> other).to be(-1)
|
76
|
+
expect(timestamp < other).to be(true)
|
77
|
+
expect(timestamp > other).to be(false)
|
78
|
+
expect(timestamp >= other).to be(false)
|
79
|
+
expect(timestamp <= other).to be(true)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when the first object is greater than the second" do
|
84
|
+
|
85
|
+
let(:other) { described_class.new(1, 5) }
|
86
|
+
|
87
|
+
it "returns 1" do
|
88
|
+
expect(timestamp <=> other).to be(1)
|
89
|
+
expect(timestamp < other).to be(false)
|
90
|
+
expect(timestamp > other).to be(true)
|
91
|
+
expect(timestamp >= other).to be(true)
|
92
|
+
expect(timestamp <= other).to be(false)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when the other object is not a timestamp" do
|
97
|
+
|
98
|
+
it "raises an ArgumentError" do
|
99
|
+
expect {
|
100
|
+
timestamp < 1
|
101
|
+
}.to raise_exception(ArgumentError)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
51
106
|
describe "#as_json" do
|
52
107
|
|
53
108
|
let(:object) do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0.beta
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
UgLdYyyGANc+TOKLFmx0eAJlCljAurbX7ctO2XI0f1AUdEYSqGzut+datXK/9nwQ
|
35
35
|
FACf8zd11PEds/Opai2Qp4aOBgaxXhhFG357umy1vRs=
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date: 2017-
|
37
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
38
38
|
dependencies: []
|
39
39
|
description: A full featured BSON specification implementation, in Ruby
|
40
40
|
email:
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/bson/true_class.rb
|
87
87
|
- lib/bson/undefined.rb
|
88
88
|
- lib/bson/version.rb
|
89
|
+
- lib/bson_native.bundle
|
89
90
|
- spec/bson/array_spec.rb
|
90
91
|
- spec/bson/binary_spec.rb
|
91
92
|
- spec/bson/boolean_spec.rb
|
metadata.gz.sig
CHANGED
Binary file
|