bson 4.14.1-java → 5.0.0-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/README.md +4 -4
- data/Rakefile +5 -0
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +57 -31
- data/lib/bson/big_decimal.rb +16 -6
- data/lib/bson/binary.rb +255 -128
- data/lib/bson/boolean.rb +1 -0
- data/lib/bson/code.rb +9 -11
- data/lib/bson/code_with_scope.rb +8 -10
- data/lib/bson/config.rb +1 -27
- data/lib/bson/date.rb +2 -1
- data/lib/bson/date_time.rb +2 -1
- data/lib/bson/db_pointer.rb +11 -12
- data/lib/bson/dbref.rb +11 -9
- data/lib/bson/decimal128/builder.rb +9 -8
- data/lib/bson/decimal128.rb +33 -109
- data/lib/bson/document.rb +1 -0
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error/bson_decode_error.rb +11 -0
- data/lib/bson/error/ext_json_parse_error.rb +11 -0
- data/lib/bson/error/illegal_key.rb +23 -0
- data/lib/bson/error/invalid_binary_type.rb +37 -0
- data/lib/bson/error/invalid_dbref_argument.rb +12 -0
- data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
- data/lib/bson/error/invalid_decimal128_range.rb +27 -0
- data/lib/bson/error/invalid_decimal128_string.rb +26 -0
- data/lib/bson/error/invalid_key.rb +24 -0
- data/lib/bson/error/invalid_object_id.rb +11 -0
- data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
- data/lib/bson/error/unrepresentable_precision.rb +19 -0
- data/lib/bson/error/unserializable_class.rb +13 -0
- data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
- data/lib/bson/error/unsupported_type.rb +11 -0
- data/lib/bson/error.rb +16 -28
- data/lib/bson/ext_json.rb +1 -0
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +2 -1
- data/lib/bson/hash.rb +127 -72
- data/lib/bson/int32.rb +16 -4
- data/lib/bson/int64.rb +16 -4
- data/lib/bson/integer.rb +3 -4
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +7 -9
- data/lib/bson/min_key.rb +7 -9
- data/lib/bson/nil_class.rb +1 -0
- data/lib/bson/object.rb +5 -25
- data/lib/bson/object_id.rb +75 -121
- data/lib/bson/open_struct.rb +3 -2
- data/lib/bson/regexp.rb +35 -64
- data/lib/bson/registry.rb +2 -6
- data/lib/bson/specialized.rb +2 -1
- data/lib/bson/string.rb +4 -27
- data/lib/bson/symbol.rb +22 -19
- data/lib/bson/time.rb +2 -1
- data/lib/bson/time_with_zone.rb +13 -1
- data/lib/bson/timestamp.rb +2 -1
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +14 -0
- data/lib/bson/version.rb +2 -1
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +3 -2
- data/spec/bson/array_spec.rb +19 -60
- data/spec/bson/big_decimal_spec.rb +16 -4
- data/spec/bson/binary_spec.rb +83 -74
- data/spec/bson/binary_uuid_spec.rb +1 -0
- data/spec/bson/boolean_spec.rb +1 -0
- data/spec/bson/byte_buffer_read_spec.rb +1 -0
- data/spec/bson/byte_buffer_spec.rb +1 -0
- data/spec/bson/byte_buffer_write_spec.rb +1 -0
- data/spec/bson/code_spec.rb +5 -3
- data/spec/bson/code_with_scope_spec.rb +5 -3
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +1 -0
- data/spec/bson/date_time_spec.rb +1 -0
- data/spec/bson/dbref_legacy_spec.rb +20 -3
- data/spec/bson/dbref_spec.rb +9 -9
- data/spec/bson/decimal128_spec.rb +249 -14
- data/spec/bson/document_as_spec.rb +1 -0
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/ext_json_parse_spec.rb +1 -0
- data/spec/bson/false_class_spec.rb +8 -0
- data/spec/bson/float_spec.rb +8 -3
- data/spec/bson/hash_as_spec.rb +1 -0
- data/spec/bson/hash_spec.rb +87 -75
- data/spec/bson/int32_spec.rb +21 -6
- data/spec/bson/int64_spec.rb +21 -6
- data/spec/bson/integer_spec.rb +45 -13
- data/spec/bson/json_spec.rb +1 -0
- data/spec/bson/max_key_spec.rb +5 -3
- data/spec/bson/min_key_spec.rb +5 -3
- data/spec/bson/nil_class_spec.rb +1 -0
- data/spec/bson/object_id_spec.rb +43 -4
- data/spec/bson/object_spec.rb +2 -1
- data/spec/bson/open_struct_spec.rb +14 -71
- data/spec/bson/raw_spec.rb +9 -15
- data/spec/bson/regexp_spec.rb +4 -3
- data/spec/bson/registry_spec.rb +2 -1
- data/spec/bson/string_spec.rb +13 -38
- data/spec/bson/symbol_raw_spec.rb +25 -0
- data/spec/bson/symbol_spec.rb +15 -18
- data/spec/bson/time_spec.rb +1 -0
- data/spec/bson/time_with_zone_spec.rb +1 -0
- data/spec/bson/timestamp_spec.rb +1 -0
- data/spec/bson/true_class_spec.rb +8 -0
- data/spec/bson/undefined_spec.rb +27 -0
- data/spec/bson_spec.rb +1 -0
- data/spec/runners/common_driver.rb +6 -5
- data/spec/runners/corpus.rb +6 -0
- data/spec/runners/corpus_legacy.rb +1 -0
- data/spec/shared/lib/mrss/constraints.rb +8 -16
- data/spec/shared/lib/mrss/docker_runner.rb +30 -3
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +68 -85
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/server.sh +73 -24
- data/spec/shared/shlib/set_env.sh +39 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_tests/common_driver_spec.rb +9 -4
- data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
- data/spec/spec_tests/corpus_spec.rb +13 -3
- data/spec/spec_tests/data/corpus/binary.json +5 -0
- data/spec/spec_tests/data/corpus/code.json +13 -13
- data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
- data/spec/spec_tests/data/corpus/document.json +20 -0
- data/spec/spec_tests/data/corpus/symbol.json +7 -7
- data/spec/spec_tests/data/corpus/top.json +18 -3
- data/spec/support/shared_examples.rb +28 -5
- data/spec/support/spec_config.rb +1 -0
- data/spec/support/utils.rb +49 -1
- data.tar.gz.sig +0 -0
- metadata +166 -141
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a402a1cf7ac93f6d12ed5acaad7ae5aa04fe0dacdfb7571392d09d35f6eaf9b
|
4
|
+
data.tar.gz: e3afd667f703c5cd401ef6231a4cf055fd835908546ba4b6503e7418beafc57c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a555961d750296ea66c0808edef55c1e2a5dcd24ff8761e0497ab671c8fe9dbc2d44f4e8ada2b2b0ec642ae347d62abe3358dc0f55cc5c81563900cd5cfb6b
|
7
|
+
data.tar.gz: '049eed7dbb37c42142a468566d44ee531f0a4ac0ac585d4e3a67b9e0ddcd3ba26c90e4f50650ec3544b5a51cb73a55c9882409c58ea6cebfb937cebe2f3b10af'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -10,19 +10,19 @@ An implementation of the BSON specification in Ruby.
|
|
10
10
|
Compatibility
|
11
11
|
-------------
|
12
12
|
|
13
|
-
BSON is tested against MRI (2.
|
13
|
+
BSON is tested against MRI (2.6) and JRuby (9.2+).
|
14
14
|
|
15
15
|
Documentation
|
16
16
|
-------------
|
17
17
|
|
18
18
|
Current documentation can be found
|
19
|
-
[here](
|
19
|
+
[here](https://www.mongodb.com/docs/ruby-driver/current/bson-tutorials/).
|
20
20
|
|
21
21
|
API Documentation
|
22
22
|
-----------------
|
23
23
|
|
24
|
-
The [API Documentation](https://
|
25
|
-
located at
|
24
|
+
The [API Documentation](https://www.mongodb.com/docs/ruby-driver/master/api/) is
|
25
|
+
located at mongodb.com/docs.
|
26
26
|
|
27
27
|
BSON Specification
|
28
28
|
------------------
|
data/Rakefile
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# rubocop:todo all
|
3
|
+
|
1
4
|
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
5
|
#
|
3
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -32,6 +35,8 @@ if jruby?
|
|
32
35
|
ext.name = "bson-ruby"
|
33
36
|
ext.ext_dir = "src"
|
34
37
|
ext.lib_dir = "lib"
|
38
|
+
ext.target_version = ENV['TARGET_VERSION'] if ENV['TARGET_VERSION']
|
39
|
+
ext.source_version = ENV['SOURCE_VERSION'] if ENV['SOURCE_VERSION']
|
35
40
|
end
|
36
41
|
else
|
37
42
|
require "rake/extensiontask"
|
data/lib/bson/active_support.rb
CHANGED
data/lib/bson/array.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
3
4
|
#
|
4
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,8 +14,8 @@
|
|
13
14
|
# See the License for the specific language governing permissions and
|
14
15
|
# limitations under the License.
|
15
16
|
|
17
|
+
# The top-level BSON module.
|
16
18
|
module BSON
|
17
|
-
|
18
19
|
# Injects behaviour for encoding and decoding arrays to
|
19
20
|
# and from raw bytes as specified by the BSON spec.
|
20
21
|
#
|
@@ -22,7 +23,6 @@ module BSON
|
|
22
23
|
#
|
23
24
|
# @since 2.0.0
|
24
25
|
module Array
|
25
|
-
|
26
26
|
# An array is type 0x04 in the BSON spec.
|
27
27
|
#
|
28
28
|
# @since 2.0.0
|
@@ -41,19 +41,21 @@ module BSON
|
|
41
41
|
# @see http://bsonspec.org/#/specification
|
42
42
|
#
|
43
43
|
# @since 2.0.0
|
44
|
-
def to_bson(buffer = ByteBuffer.new
|
44
|
+
def to_bson(buffer = ByteBuffer.new)
|
45
45
|
if buffer.respond_to?(:put_array)
|
46
|
-
buffer.put_array(self
|
46
|
+
buffer.put_array(self)
|
47
47
|
else
|
48
48
|
position = buffer.length
|
49
49
|
buffer.put_int32(0)
|
50
50
|
each_with_index do |value, index|
|
51
51
|
unless value.respond_to?(:bson_type)
|
52
|
-
raise Error::UnserializableClass,
|
52
|
+
raise Error::UnserializableClass,
|
53
|
+
"Array element at position #{index} does not define its BSON serialized type: #{value}"
|
53
54
|
end
|
55
|
+
|
54
56
|
buffer.put_byte(value.bson_type)
|
55
57
|
buffer.put_cstring(index.to_s)
|
56
|
-
value.to_bson(buffer
|
58
|
+
value.to_bson(buffer)
|
57
59
|
end
|
58
60
|
buffer.put_byte(NULL_BYTE)
|
59
61
|
buffer.replace_int32(position, buffer.length - position)
|
@@ -68,13 +70,13 @@ module BSON
|
|
68
70
|
#
|
69
71
|
# @note This is used for repairing legacy bson data.
|
70
72
|
#
|
71
|
-
# @raise [ BSON::
|
73
|
+
# @raise [ BSON::Error::InvalidObjectId ] If the array is not 12 elements.
|
72
74
|
#
|
73
75
|
# @return [ String ] The raw object id bytes.
|
74
76
|
#
|
75
77
|
# @since 2.0.0
|
76
78
|
def to_bson_object_id
|
77
|
-
ObjectId.repair(self) { pack(
|
79
|
+
ObjectId.repair(self) { pack('C*') }
|
78
80
|
end
|
79
81
|
|
80
82
|
# Converts the array to a normalized value in a BSON document.
|
@@ -86,7 +88,7 @@ module BSON
|
|
86
88
|
#
|
87
89
|
# @since 3.0.0
|
88
90
|
def to_bson_normalized_value
|
89
|
-
map
|
91
|
+
map(&:to_bson_normalized_value)
|
90
92
|
end
|
91
93
|
|
92
94
|
# Converts this object to a representation directly serializable to
|
@@ -105,10 +107,15 @@ module BSON
|
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
110
|
+
# Class-level methods to be added to the Array class.
|
108
111
|
module ClassMethods
|
109
|
-
|
110
112
|
# Deserialize the array from BSON.
|
111
113
|
#
|
114
|
+
# @note If the argument cannot be parsed, an exception will be raised
|
115
|
+
# and the argument will be left in an undefined state. The caller
|
116
|
+
# must explicitly call `rewind` on the buffer before trying to parse
|
117
|
+
# it again.
|
118
|
+
#
|
112
119
|
# @param [ ByteBuffer ] buffer The byte buffer.
|
113
120
|
#
|
114
121
|
# @option options [ nil | :bson ] :mode Decoding mode to use.
|
@@ -116,43 +123,62 @@ module BSON
|
|
116
123
|
# @return [ Array ] The decoded array.
|
117
124
|
#
|
118
125
|
# @see http://bsonspec.org/#/specification
|
119
|
-
#
|
120
|
-
# @since 2.0.0
|
121
126
|
def from_bson(buffer, **options)
|
122
127
|
if buffer.respond_to?(:get_array)
|
123
128
|
buffer.get_array(**options)
|
124
129
|
else
|
125
|
-
|
130
|
+
parse_array_from_buffer(buffer, **options)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
# Parse an array from the buffer.
|
137
|
+
#
|
138
|
+
# @param [ ByteBuf ] buffer the buffer to read from
|
139
|
+
# @param [ Hash ] options the optional keyword arguments
|
140
|
+
#
|
141
|
+
# @return [ Array ] the array that was parsed
|
142
|
+
#
|
143
|
+
# @raise [ BSON::Error::BSONDecodeError ] if the expected number of
|
144
|
+
# bytes were not read from the buffer
|
145
|
+
def parse_array_from_buffer(buffer, **options)
|
146
|
+
new.tap do |array|
|
126
147
|
start_position = buffer.read_position
|
127
148
|
expected_byte_size = buffer.get_int32
|
128
|
-
|
129
|
-
buffer.get_cstring
|
130
|
-
cls = BSON::Registry.get(type)
|
131
|
-
value = if options.empty?
|
132
|
-
cls.from_bson(buffer)
|
133
|
-
else
|
134
|
-
cls.from_bson(buffer, **options)
|
135
|
-
end
|
136
|
-
array << value
|
137
|
-
end
|
149
|
+
parse_array_elements_from_buffer(array, buffer, **options)
|
138
150
|
actual_byte_size = buffer.read_position - start_position
|
139
151
|
if actual_byte_size != expected_byte_size
|
140
|
-
raise Error::BSONDecodeError,
|
152
|
+
raise Error::BSONDecodeError,
|
153
|
+
"Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
|
141
154
|
end
|
142
|
-
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Parse a sequence of array elements from the buffer.
|
159
|
+
#
|
160
|
+
# @param [ Array ] array the array to populate
|
161
|
+
# @param [ ByteBuf ] buffer the buffer to read from
|
162
|
+
# @param [ Hash ] options the optional keyword arguments
|
163
|
+
def parse_array_elements_from_buffer(array, buffer, **options)
|
164
|
+
while (type = buffer.get_byte) != NULL_BYTE
|
165
|
+
buffer.get_cstring
|
166
|
+
cls = BSON::Registry.get(type)
|
167
|
+
value = if options.empty?
|
168
|
+
cls.from_bson(buffer)
|
169
|
+
else
|
170
|
+
cls.from_bson(buffer, **options)
|
171
|
+
end
|
172
|
+
array << value
|
143
173
|
end
|
144
174
|
end
|
145
175
|
end
|
146
176
|
|
147
177
|
# Register this type when the module is loaded.
|
148
|
-
#
|
149
|
-
# @since 2.0.0
|
150
178
|
Registry.register(BSON_TYPE, ::Array)
|
151
179
|
end
|
152
180
|
|
153
181
|
# Enrich the core Array class with this module.
|
154
|
-
|
155
|
-
|
156
|
-
::Array.send(:include, Array)
|
157
|
-
::Array.send(:extend, Array::ClassMethods)
|
182
|
+
::Array.include Array
|
183
|
+
::Array.extend Array::ClassMethods
|
158
184
|
end
|
data/lib/bson/big_decimal.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# rubocop:todo all
|
2
3
|
# Copyright (C) 2009-2021 MongoDB Inc.
|
3
4
|
#
|
4
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -21,7 +22,7 @@ module BSON
|
|
21
22
|
# @see http://bsonspec.org/#/specification
|
22
23
|
module BigDecimal
|
23
24
|
|
24
|
-
# BigDecimals are serialized as Decimal128s under the hood. A Decimal128
|
25
|
+
# BigDecimals are serialized as Decimal128s under the hood. A Decimal128
|
25
26
|
# is type 0x13 in the BSON spec.
|
26
27
|
BSON_TYPE = ::String.new(19.chr, encoding: BINARY).freeze
|
27
28
|
|
@@ -33,8 +34,8 @@ module BSON
|
|
33
34
|
# @return [ BSON::ByteBuffer ] The buffer with the encoded object.
|
34
35
|
#
|
35
36
|
# @see http://bsonspec.org/#/specification
|
36
|
-
def to_bson(buffer = ByteBuffer.new
|
37
|
-
BSON::Decimal128.new(to_s).to_bson(buffer
|
37
|
+
def to_bson(buffer = ByteBuffer.new)
|
38
|
+
BSON::Decimal128.new(to_s).to_bson(buffer)
|
38
39
|
end
|
39
40
|
|
40
41
|
# Get the BSON type for BigDecimal. This is the same BSON type as
|
@@ -45,7 +46,8 @@ module BSON
|
|
45
46
|
|
46
47
|
module ClassMethods
|
47
48
|
|
48
|
-
# Deserialize the BigDecimal from raw BSON bytes.
|
49
|
+
# Deserialize the BigDecimal from raw BSON bytes. If the :mode option
|
50
|
+
# is set to BSON, this will return a BSON::Decimal128
|
49
51
|
#
|
50
52
|
# @example Get the BigDecimal from BSON.
|
51
53
|
# BigDecimal.from_bson(bson)
|
@@ -54,11 +56,19 @@ module BSON
|
|
54
56
|
#
|
55
57
|
# @option options [ nil | :bson ] :mode Decoding mode to use.
|
56
58
|
#
|
57
|
-
# @return [ BigDecimal ] The decimal object.
|
59
|
+
# @return [ BigDecimal | BSON::Decimal128 ] The decimal object.
|
58
60
|
def from_bson(buffer, **options)
|
59
|
-
Decimal128.from_bson(buffer, **options)
|
61
|
+
dec128 = Decimal128.from_bson(buffer, **options)
|
62
|
+
if options[:mode] == :bson
|
63
|
+
dec128
|
64
|
+
else
|
65
|
+
dec128.to_d
|
66
|
+
end
|
60
67
|
end
|
61
68
|
end
|
69
|
+
|
70
|
+
# Register this type when the module is loaded.
|
71
|
+
Registry.register(BSON_TYPE, ::BigDecimal)
|
62
72
|
end
|
63
73
|
|
64
74
|
# Enrich the core BigDecimal class with this module.
|