bson 3.2.7 → 4.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +2 -10
  5. data/ext/bson/native-endian.h +120 -0
  6. data/ext/bson/native.c +547 -581
  7. data/lib/bson.rb +0 -1
  8. data/lib/bson/array.rb +15 -14
  9. data/lib/bson/binary.rb +13 -13
  10. data/lib/bson/boolean.rb +3 -3
  11. data/lib/bson/code.rb +5 -8
  12. data/lib/bson/code_with_scope.rb +10 -13
  13. data/lib/bson/date.rb +2 -2
  14. data/lib/bson/date_time.rb +2 -2
  15. data/lib/bson/document.rb +33 -0
  16. data/lib/bson/false_class.rb +2 -2
  17. data/lib/bson/float.rb +5 -11
  18. data/lib/bson/hash.rb +15 -14
  19. data/lib/bson/int32.rb +8 -9
  20. data/lib/bson/int64.rb +3 -9
  21. data/lib/bson/integer.rb +6 -20
  22. data/lib/bson/nil_class.rb +4 -16
  23. data/lib/bson/object.rb +1 -1
  24. data/lib/bson/object_id.rb +14 -16
  25. data/lib/bson/regexp.rb +7 -7
  26. data/lib/bson/specialized.rb +6 -6
  27. data/lib/bson/string.rb +7 -91
  28. data/lib/bson/symbol.rb +8 -7
  29. data/lib/bson/time.rb +5 -5
  30. data/lib/bson/timestamp.rb +8 -6
  31. data/lib/bson/true_class.rb +2 -2
  32. data/lib/bson/undefined.rb +1 -26
  33. data/lib/bson/version.rb +1 -1
  34. data/spec/bson/array_spec.rb +1 -1
  35. data/spec/bson/byte_buffer_spec.rb +445 -0
  36. data/spec/bson/code_with_scope_spec.rb +3 -7
  37. data/spec/bson/document_spec.rb +66 -10
  38. data/spec/bson/hash_spec.rb +5 -5
  39. data/spec/bson/int32_spec.rb +7 -5
  40. data/spec/bson/integer_spec.rb +1 -6
  41. data/spec/bson/object_id_spec.rb +2 -39
  42. data/spec/bson/regexp_spec.rb +1 -1
  43. data/spec/bson/string_spec.rb +2 -204
  44. data/spec/bson/symbol_spec.rb +2 -17
  45. data/spec/support/shared_examples.rb +3 -26
  46. metadata +13 -11
  47. metadata.gz.sig +0 -0
  48. data/lib/bson/encodable.rb +0 -86
@@ -20,7 +20,7 @@ describe Symbol do
20
20
 
21
21
  let(:type) { 14.chr }
22
22
  let(:obj) { :test }
23
- let(:bson) { "#{5.to_bson}test#{BSON::NULL_BYTE}" }
23
+ let(:bson) { "#{5.to_bson.to_s}test#{BSON::NULL_BYTE}" }
24
24
 
25
25
  it_behaves_like "a bson element"
26
26
  it_behaves_like "a serializable bson element"
@@ -31,25 +31,10 @@ describe Symbol do
31
31
  describe "#to_bson_key" do
32
32
 
33
33
  let(:symbol) { :test }
34
- let(:encoded) { symbol.to_s + BSON::NULL_BYTE }
35
- let(:previous_content) { 'previous_content'.force_encoding(BSON::BINARY) }
34
+ let(:encoded) { symbol.to_s }
36
35
 
37
36
  it "returns the encoded string" do
38
37
  expect(symbol.to_bson_key).to eq(encoded)
39
38
  end
40
-
41
- it "appends to optional previous content" do
42
- expect(symbol.to_bson_key(previous_content)).to eq(previous_content << encoded)
43
- end
44
-
45
- context 'when the symbol contains a null byte' do
46
- let(:symbol) { :"test#{BSON::NULL_BYTE}ing" }
47
-
48
- it 'raises an error' do
49
- expect {
50
- symbol.to_bson_key
51
- }.to raise_error(ArgumentError)
52
- end
53
- end
54
39
  end
55
40
  end
@@ -38,23 +38,15 @@ end
38
38
 
39
39
  shared_examples_for "a serializable bson element" do
40
40
 
41
- let(:previous_content) do
42
- 'previous_content'.force_encoding(BSON::BINARY)
43
- end
44
-
45
41
  it "serializes to bson" do
46
- expect(obj.to_bson).to eq(bson)
47
- end
48
-
49
- it "serializes to bson by appending" do
50
- expect(obj.to_bson(previous_content)).to eq(previous_content << bson)
42
+ expect(obj.to_bson.to_s).to eq(bson)
51
43
  end
52
44
  end
53
45
 
54
46
  shared_examples_for "a deserializable bson element" do
55
47
 
56
48
  let(:io) do
57
- StringIO.new(bson)
49
+ BSON::ByteBuffer.new(bson)
58
50
  end
59
51
 
60
52
  let(:result) do
@@ -64,21 +56,6 @@ shared_examples_for "a deserializable bson element" do
64
56
  it "deserializes from bson" do
65
57
  expect(result).to eq(obj)
66
58
  end
67
-
68
- context 'when io#readbyte returns a String' do
69
-
70
- let(:io) do
71
- AlternateIO.new(bson)
72
- end
73
-
74
- let(:result) do
75
- described_class.from_bson(io)
76
- end
77
-
78
- it "deserializes from bson" do
79
- expect(result).to eq(obj)
80
- end
81
- end
82
59
  end
83
60
 
84
61
  shared_examples_for "a JSON serializable object" do
@@ -108,7 +85,7 @@ shared_examples_for "a document able to handle utf-8" do
108
85
 
109
86
  it "serializes and deserializes properly" do
110
87
  expect(
111
- BSON::Document.from_bson(StringIO.new(document.to_bson))
88
+ BSON::Document.from_bson(BSON::ByteBuffer.new(document.to_bson.to_s))
112
89
  ).to eq(document)
113
90
  end
114
91
  end
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: 3.2.7
4
+ version: 4.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -16,7 +16,7 @@ cert_chain:
16
16
  -----BEGIN CERTIFICATE-----
17
17
  MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
18
18
  ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
19
- Y29tMB4XDTE3MDcwMzE0NTAxOFoXDTE4MDcwMzE0NTAxOFowQjEUMBIGA1UEAwwL
19
+ Y29tMB4XDTE1MDMzMTA5NDIzNVoXDTE2MDMzMDA5NDIzNVowQjEUMBIGA1UEAwwL
20
20
  ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
21
21
  ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBB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pa8
35
+ BRsuCo7UZDbFVRns04HLyjVvkj+K/ywIcdKdS0csz5M=
36
36
  -----END CERTIFICATE-----
37
- date: 2017-07-03 00:00:00.000000000 Z
37
+ date: 2015-10-28 00:00:00.000000000 Z
38
38
  dependencies: []
39
39
  description: A full featured BSON specification implementation, in Ruby
40
40
  email:
@@ -51,6 +51,7 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - ext/bson/extconf.rb
54
+ - ext/bson/native-endian.h
54
55
  - ext/bson/native.c
55
56
  - lib/bson.rb
56
57
  - lib/bson/array.rb
@@ -61,7 +62,6 @@ files:
61
62
  - lib/bson/date.rb
62
63
  - lib/bson/date_time.rb
63
64
  - lib/bson/document.rb
64
- - lib/bson/encodable.rb
65
65
  - lib/bson/environment.rb
66
66
  - lib/bson/false_class.rb
67
67
  - lib/bson/float.rb
@@ -88,6 +88,7 @@ files:
88
88
  - spec/bson/array_spec.rb
89
89
  - spec/bson/binary_spec.rb
90
90
  - spec/bson/boolean_spec.rb
91
+ - spec/bson/byte_buffer_spec.rb
91
92
  - spec/bson/code_spec.rb
92
93
  - spec/bson/code_with_scope_spec.rb
93
94
  - spec/bson/date_spec.rb
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: 1.3.6
137
138
  requirements: []
138
139
  rubyforge_project: bson
139
- rubygems_version: 2.6.11
140
+ rubygems_version: 2.4.6
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Ruby Implementation of the BSON specification
@@ -144,6 +145,7 @@ test_files:
144
145
  - spec/bson/array_spec.rb
145
146
  - spec/bson/binary_spec.rb
146
147
  - spec/bson/boolean_spec.rb
148
+ - spec/bson/byte_buffer_spec.rb
147
149
  - spec/bson/code_spec.rb
148
150
  - spec/bson/code_with_scope_spec.rb
149
151
  - spec/bson/date_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,86 +0,0 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module BSON
16
-
17
- # Defines behaviour around objects that can be encoded.
18
- #
19
- # @since 2.0.0
20
- module Encodable
21
-
22
- # A 4 byte placeholder that would be replaced by a length at a later point.
23
- #
24
- # @since 2.0.0
25
- PLACEHOLDER = 0.to_bson.freeze
26
-
27
- # Adjustment value for total number of document bytes.
28
- #
29
- # @since 2.0.0
30
- BSON_ADJUST = 0.freeze
31
-
32
- # Adjustment value for total number of string bytes.
33
- #
34
- # @since 2.0.0
35
- STRING_ADJUST = -4.freeze
36
-
37
- # Encodes BSON to raw bytes, for types that require the length of the
38
- # entire bytes to be present as the first word of the encoded string. This
39
- # includes Hash, CodeWithScope.
40
- #
41
- # @example Encode the BSON with placeholder bytes.
42
- # hash.encode_with_placeholder_and_null(BSON_ADJUST, encoded) do |encoded|
43
- # each do |field, value|
44
- # value.to_bson(encoded)
45
- # end
46
- # end
47
- #
48
- # @param [ Integer ] adjust The number of bytes to adjust with.
49
- # @param [ String ] encoded The string to encode.
50
- #
51
- # @return [ String ] The encoded string.
52
- #
53
- # @since 2.0.0
54
- def encode_with_placeholder_and_null(adjust, encoded = ''.force_encoding(BINARY))
55
- pos = encoded.bytesize
56
- encoded << PLACEHOLDER
57
- yield(encoded)
58
- encoded << NULL_BYTE
59
- encoded.set_int32(pos, encoded.bytesize - pos + adjust)
60
- encoded
61
- end
62
-
63
- # Encodes binary data with a generic placeholder value to be written later
64
- # once all bytes have been written.
65
- #
66
- # @example Encode the BSON with placeholder bytes.
67
- # string.encode_binary_data_with_placeholder(encoded) do |encoded|
68
- # each do |field, value|
69
- # value.to_bson(encoded)
70
- # end
71
- # end
72
- #
73
- # @param [ String ] encoded The string to encode.
74
- #
75
- # @return [ String ] The encoded string.
76
- #
77
- # @since 2.0.0
78
- def encode_binary_data_with_placeholder(encoded = ''.force_encoding(BINARY))
79
- pos = encoded.bytesize
80
- encoded << PLACEHOLDER
81
- yield(encoded)
82
- encoded.set_int32(pos, encoded.bytesize - pos - 5)
83
- encoded
84
- end
85
- end
86
- end