bson 4.0.0 → 4.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1da958014f886d3397ae3f00264fc2785bd1189b
4
- data.tar.gz: cf112e2192dbf457e3dbea275c2b154a67611aa0
3
+ metadata.gz: 9b61741985de27b81c1e380238f708c60dbdd27a
4
+ data.tar.gz: 7a9c05ebad5025750dc017e2a070f069d4332d7e
5
5
  SHA512:
6
- metadata.gz: 1f78c538b5b3e003a880cd93780f45f389163c629b519284b77ca5304f69a682d15d7cdfdae195e65c1e41e0c5ba85798c2433d283db35b301b64cfec2f14750
7
- data.tar.gz: 9fb5768b82318f3bc316d7e9be975441aa0163ea574111141687972d4bcbb2e4a43905674fa30216a56d914337b5414b033fa131bd2488f60519d9527bbe1bf6
6
+ metadata.gz: b23d67e21e47aef19e4ba38a1f3914bd991f67a80788a94802666752b5f2a87899f3808d37f56c2b00efdc92923ab1b1aa593eb07b56eee32192d4f678317c8f
7
+ data.tar.gz: 9aeac5265f9aece1646ad631124e21d77af48f68a811e91102ee6150fe56384024f60282774995934d39b69e76f991354f23d59dcd8f40b7a387611a58df349d
@@ -69,6 +69,7 @@ static VALUE rb_bson_byte_buffer_put_int64(VALUE self, VALUE i);
69
69
  static VALUE rb_bson_byte_buffer_put_string(VALUE self, VALUE string);
70
70
  static VALUE rb_bson_byte_buffer_read_position(VALUE self);
71
71
  static VALUE rb_bson_byte_buffer_replace_int32(VALUE self, VALUE index, VALUE i);
72
+ static VALUE rb_bson_byte_buffer_rewind(VALUE self);
72
73
  static VALUE rb_bson_byte_buffer_write_position(VALUE self);
73
74
  static VALUE rb_bson_byte_buffer_to_s(VALUE self);
74
75
  static VALUE rb_bson_object_id_generator_next(int argc, VALUE* args, VALUE self);
@@ -92,7 +93,7 @@ static char rb_bson_machine_id_hash[HOST_NAME_HASH_MAX];
92
93
  /**
93
94
  * The counter for incrementing object ids.
94
95
  */
95
- static unsigned int rb_bson_object_id_counter = 0;
96
+ static unsigned int rb_bson_object_id_counter;
96
97
 
97
98
  /**
98
99
  * Initialize the native extension.
@@ -127,6 +128,7 @@ void Init_native()
127
128
  rb_define_method(rb_byte_buffer_class, "put_string", rb_bson_byte_buffer_put_string, 1);
128
129
  rb_define_method(rb_byte_buffer_class, "read_position", rb_bson_byte_buffer_read_position, 0);
129
130
  rb_define_method(rb_byte_buffer_class, "replace_int32", rb_bson_byte_buffer_replace_int32, 2);
131
+ rb_define_method(rb_byte_buffer_class, "rewind!", rb_bson_byte_buffer_rewind, 0);
130
132
  rb_define_method(rb_byte_buffer_class, "write_position", rb_bson_byte_buffer_write_position, 0);
131
133
  rb_define_method(rb_byte_buffer_class, "to_s", rb_bson_byte_buffer_to_s, 0);
132
134
  rb_define_method(rb_bson_object_id_generator_class, "next_object_id", rb_bson_object_id_generator_next, -1);
@@ -136,6 +138,9 @@ void Init_native()
136
138
  gethostname(rb_bson_machine_id, sizeof(rb_bson_machine_id));
137
139
  rb_bson_machine_id[255] = '\0';
138
140
  rb_bson_generate_machine_id(rb_md5_class, rb_bson_machine_id);
141
+
142
+ // Set the object id counter to a random number
143
+ rb_bson_object_id_counter = FIX2INT(rb_funcall(rb_mKernel, rb_intern("rand"), 1, INT2FIX(0x1000000)));
139
144
  }
140
145
 
141
146
  void rb_bson_generate_machine_id(VALUE rb_md5_class, char *rb_bson_machine_id)
@@ -446,6 +451,18 @@ VALUE rb_bson_byte_buffer_replace_int32(VALUE self, VALUE index, VALUE i)
446
451
  return self;
447
452
  }
448
453
 
454
+ /**
455
+ * Reset the read position to the beginning of the byte buffer.
456
+ */
457
+ VALUE rb_bson_byte_buffer_rewind(VALUE self)
458
+ {
459
+ byte_buffer_t *b;
460
+ TypedData_Get_Struct(self, byte_buffer_t, &rb_byte_buffer_data_type, b);
461
+ b->read_position = 0;
462
+
463
+ return self;
464
+ }
465
+
449
466
  /**
450
467
  * Get the write position.
451
468
  */
@@ -331,7 +331,7 @@ module BSON
331
331
  #
332
332
  # @since 2.0.0
333
333
  def initialize
334
- @counter = 0
334
+ @counter = rand(0x1000000)
335
335
  @machine_id = Digest::MD5.digest(Socket.gethostname).unpack("N")[0]
336
336
  @mutex = Mutex.new
337
337
  end
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module BSON
16
- VERSION = "4.0.0"
16
+ VERSION = "4.0.1"
17
17
  end
@@ -442,4 +442,28 @@ describe BSON::ByteBuffer do
442
442
  expect(modified.to_s).to eq("#{exp_first}#{exp_second}")
443
443
  end
444
444
  end
445
+
446
+ describe '#rewind!' do
447
+
448
+ let(:string) do
449
+ "#{BSON::Int32::BSON_TYPE}#{BSON::Int32::BSON_TYPE}"
450
+ end
451
+
452
+ let(:buffer) do
453
+ described_class.new(string)
454
+ end
455
+
456
+ before do
457
+ buffer.get_bytes(1)
458
+ buffer.rewind!
459
+ end
460
+
461
+ it 'resets the read position to 0' do
462
+ expect(buffer.read_position).to eq(0)
463
+ end
464
+
465
+ it 'starts subsequent reads at position 0' do
466
+ expect(buffer.get_bytes(2)).to eq(string)
467
+ end
468
+ end
445
469
  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: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -11,30 +11,8 @@ authors:
11
11
  - Gary Murakami
12
12
  autorequire:
13
13
  bindir: bin
14
- cert_chain:
15
- - |
16
- -----BEGIN CERTIFICATE-----
17
- MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
18
- ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
19
- Y29tMB4XDTE1MDMzMTA5NDIzNVoXDTE2MD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suCo7UZDbFVRns04HLyjVvkj+K/ywIcdKdS0csz5M=
36
- -----END CERTIFICATE-----
37
- date: 2015-12-07 00:00:00.000000000 Z
14
+ cert_chain: []
15
+ date: 2016-01-25 00:00:00.000000000 Z
38
16
  dependencies: []
39
17
  description: A full featured BSON specification implementation, in Ruby
40
18
  email:
@@ -137,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
115
  version: 1.3.6
138
116
  requirements: []
139
117
  rubyforge_project: bson
140
- rubygems_version: 2.4.8
118
+ rubygems_version: 2.4.6
141
119
  signing_key:
142
120
  specification_version: 4
143
121
  summary: Ruby Implementation of the BSON specification
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file