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.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +4 -4
  4. data/Rakefile +5 -0
  5. data/lib/bson/active_support.rb +1 -0
  6. data/lib/bson/array.rb +57 -31
  7. data/lib/bson/big_decimal.rb +16 -6
  8. data/lib/bson/binary.rb +255 -128
  9. data/lib/bson/boolean.rb +1 -0
  10. data/lib/bson/code.rb +9 -11
  11. data/lib/bson/code_with_scope.rb +8 -10
  12. data/lib/bson/config.rb +1 -27
  13. data/lib/bson/date.rb +2 -1
  14. data/lib/bson/date_time.rb +2 -1
  15. data/lib/bson/db_pointer.rb +11 -12
  16. data/lib/bson/dbref.rb +11 -9
  17. data/lib/bson/decimal128/builder.rb +9 -8
  18. data/lib/bson/decimal128.rb +33 -109
  19. data/lib/bson/document.rb +1 -0
  20. data/lib/bson/environment.rb +1 -0
  21. data/lib/bson/error/bson_decode_error.rb +11 -0
  22. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  23. data/lib/bson/error/illegal_key.rb +23 -0
  24. data/lib/bson/error/invalid_binary_type.rb +37 -0
  25. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  26. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  27. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  28. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  29. data/lib/bson/error/invalid_key.rb +24 -0
  30. data/lib/bson/error/invalid_object_id.rb +11 -0
  31. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  32. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  33. data/lib/bson/error/unserializable_class.rb +13 -0
  34. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  35. data/lib/bson/error/unsupported_type.rb +11 -0
  36. data/lib/bson/error.rb +16 -28
  37. data/lib/bson/ext_json.rb +1 -0
  38. data/lib/bson/false_class.rb +2 -1
  39. data/lib/bson/float.rb +2 -1
  40. data/lib/bson/hash.rb +127 -72
  41. data/lib/bson/int32.rb +16 -4
  42. data/lib/bson/int64.rb +16 -4
  43. data/lib/bson/integer.rb +3 -4
  44. data/lib/bson/json.rb +1 -0
  45. data/lib/bson/max_key.rb +7 -9
  46. data/lib/bson/min_key.rb +7 -9
  47. data/lib/bson/nil_class.rb +1 -0
  48. data/lib/bson/object.rb +5 -25
  49. data/lib/bson/object_id.rb +75 -121
  50. data/lib/bson/open_struct.rb +3 -2
  51. data/lib/bson/regexp.rb +35 -64
  52. data/lib/bson/registry.rb +2 -6
  53. data/lib/bson/specialized.rb +2 -1
  54. data/lib/bson/string.rb +4 -27
  55. data/lib/bson/symbol.rb +22 -19
  56. data/lib/bson/time.rb +2 -1
  57. data/lib/bson/time_with_zone.rb +13 -1
  58. data/lib/bson/timestamp.rb +2 -1
  59. data/lib/bson/true_class.rb +2 -1
  60. data/lib/bson/undefined.rb +14 -0
  61. data/lib/bson/version.rb +2 -1
  62. data/lib/bson-ruby.jar +0 -0
  63. data/lib/bson.rb +3 -2
  64. data/spec/bson/array_spec.rb +19 -60
  65. data/spec/bson/big_decimal_spec.rb +16 -4
  66. data/spec/bson/binary_spec.rb +83 -74
  67. data/spec/bson/binary_uuid_spec.rb +1 -0
  68. data/spec/bson/boolean_spec.rb +1 -0
  69. data/spec/bson/byte_buffer_read_spec.rb +1 -0
  70. data/spec/bson/byte_buffer_spec.rb +1 -0
  71. data/spec/bson/byte_buffer_write_spec.rb +1 -0
  72. data/spec/bson/code_spec.rb +5 -3
  73. data/spec/bson/code_with_scope_spec.rb +5 -3
  74. data/spec/bson/config_spec.rb +1 -35
  75. data/spec/bson/date_spec.rb +1 -0
  76. data/spec/bson/date_time_spec.rb +1 -0
  77. data/spec/bson/dbref_legacy_spec.rb +20 -3
  78. data/spec/bson/dbref_spec.rb +9 -9
  79. data/spec/bson/decimal128_spec.rb +249 -14
  80. data/spec/bson/document_as_spec.rb +1 -0
  81. data/spec/bson/document_spec.rb +1 -1
  82. data/spec/bson/ext_json_parse_spec.rb +1 -0
  83. data/spec/bson/false_class_spec.rb +8 -0
  84. data/spec/bson/float_spec.rb +8 -3
  85. data/spec/bson/hash_as_spec.rb +1 -0
  86. data/spec/bson/hash_spec.rb +87 -75
  87. data/spec/bson/int32_spec.rb +21 -6
  88. data/spec/bson/int64_spec.rb +21 -6
  89. data/spec/bson/integer_spec.rb +45 -13
  90. data/spec/bson/json_spec.rb +1 -0
  91. data/spec/bson/max_key_spec.rb +5 -3
  92. data/spec/bson/min_key_spec.rb +5 -3
  93. data/spec/bson/nil_class_spec.rb +1 -0
  94. data/spec/bson/object_id_spec.rb +43 -4
  95. data/spec/bson/object_spec.rb +2 -1
  96. data/spec/bson/open_struct_spec.rb +14 -71
  97. data/spec/bson/raw_spec.rb +9 -15
  98. data/spec/bson/regexp_spec.rb +4 -3
  99. data/spec/bson/registry_spec.rb +2 -1
  100. data/spec/bson/string_spec.rb +13 -38
  101. data/spec/bson/symbol_raw_spec.rb +25 -0
  102. data/spec/bson/symbol_spec.rb +15 -18
  103. data/spec/bson/time_spec.rb +1 -0
  104. data/spec/bson/time_with_zone_spec.rb +1 -0
  105. data/spec/bson/timestamp_spec.rb +1 -0
  106. data/spec/bson/true_class_spec.rb +8 -0
  107. data/spec/bson/undefined_spec.rb +27 -0
  108. data/spec/bson_spec.rb +1 -0
  109. data/spec/runners/common_driver.rb +6 -5
  110. data/spec/runners/corpus.rb +6 -0
  111. data/spec/runners/corpus_legacy.rb +1 -0
  112. data/spec/shared/lib/mrss/constraints.rb +8 -16
  113. data/spec/shared/lib/mrss/docker_runner.rb +30 -3
  114. data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
  115. data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
  116. data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
  117. data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
  118. data/spec/shared/lib/mrss/session_registry.rb +69 -0
  119. data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
  120. data/spec/shared/lib/mrss/utils.rb +28 -6
  121. data/spec/shared/share/Dockerfile.erb +68 -85
  122. data/spec/shared/shlib/config.sh +27 -0
  123. data/spec/shared/shlib/server.sh +73 -24
  124. data/spec/shared/shlib/set_env.sh +39 -1
  125. data/spec/spec_helper.rb +1 -0
  126. data/spec/spec_tests/common_driver_spec.rb +9 -4
  127. data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
  128. data/spec/spec_tests/corpus_spec.rb +13 -3
  129. data/spec/spec_tests/data/corpus/binary.json +5 -0
  130. data/spec/spec_tests/data/corpus/code.json +13 -13
  131. data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
  132. data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
  133. data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
  134. data/spec/spec_tests/data/corpus/document.json +20 -0
  135. data/spec/spec_tests/data/corpus/symbol.json +7 -7
  136. data/spec/spec_tests/data/corpus/top.json +18 -3
  137. data/spec/support/shared_examples.rb +28 -5
  138. data/spec/support/spec_config.rb +1 -0
  139. data/spec/support/utils.rb +49 -1
  140. data.tar.gz.sig +0 -0
  141. metadata +166 -141
  142. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f4951837e5f28b97a1f50f8ec70be9b0459c5edbd2d10afb459ee474997e9e0
4
- data.tar.gz: d5748994a56696ee51d2a5194808fb1da8281fa423afe1fbfbb2369bf2e72448
3
+ metadata.gz: 4a402a1cf7ac93f6d12ed5acaad7ae5aa04fe0dacdfb7571392d09d35f6eaf9b
4
+ data.tar.gz: e3afd667f703c5cd401ef6231a4cf055fd835908546ba4b6503e7418beafc57c
5
5
  SHA512:
6
- metadata.gz: c8bfcd9352906e92e0930178a86e3dda9360f85f33220dfeb3fee430db2d14bb8df4b13480d3210877725ed70a0328e84a9948dc8dc0bfbd34a6a678711becd2
7
- data.tar.gz: 003bc34bdab69009c5d16cbaf73db1e764ac1d70b7313f9a650a8c88be63a0151f32debc5d145ade96e4db40807a49b26b1e7a7a92dcaeb786898ce831da4538
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.5) and JRuby (9.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](http://docs.mongodb.org/ecosystem/tutorial/ruby-bson-tutorial/#ruby-bson-tutorial).
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://api.mongodb.com/bson-ruby/current/) is
25
- located at api.mongodb.com.
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"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:todo all
2
3
  # Copyright (C) 2018-2020 MongoDB Inc.
3
4
  #
4
5
  # Licensed under the Apache License, Version 2.0 (the "License");
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, validating_keys = Config.validating_keys?)
44
+ def to_bson(buffer = ByteBuffer.new)
45
45
  if buffer.respond_to?(:put_array)
46
- buffer.put_array(self, validating_keys)
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, "Array element at position #{index} does not define its BSON serialized type: #{value}"
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, validating_keys)
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::ObjectId::Invalid ] If the array is not 12 elements.
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("C*") }
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 { |value| value.to_bson_normalized_value }
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
- array = new
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
- while (type = buffer.get_byte) != NULL_BYTE
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, "Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
152
+ raise Error::BSONDecodeError,
153
+ "Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
141
154
  end
142
- array
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
- # @since 2.0.0
156
- ::Array.send(:include, Array)
157
- ::Array.send(:extend, Array::ClassMethods)
182
+ ::Array.include Array
183
+ ::Array.extend Array::ClassMethods
158
184
  end
@@ -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, validating_keys = Config.validating_keys?)
37
- BSON::Decimal128.new(to_s).to_bson(buffer, validating_keys)
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).to_big_decimal
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.