Skip to content

Commit

Permalink
RUBY-1114 rename org.bson package to org.bson_ruby (#307)
Browse files Browse the repository at this point in the history
This is to avoid naming conflicts with the Java driver when loaded concurrently
  • Loading branch information
jamis committed Jul 3, 2023
1 parent 039e4e7 commit f7ffa3f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/bson.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def self.ObjectId(string)
begin
if BSON::Environment.jruby?
require "bson-ruby.jar"
JRuby::Util.load_ext("org.bson.NativeService")
JRuby::Util.load_ext("org.bson_ruby.NativeService")
else
require "bson_native"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.bson;
package org.bson_ruby;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -102,7 +102,7 @@ private enum Mode { READ, WRITE }
* The size of an unsigned 32-bit integer: 2^32 - 1
*/
private static long UINT32_MAX = 4294967295L;

/**
* Instantiate the ByteBuf - this is #allocate in Ruby.
*
Expand Down Expand Up @@ -155,7 +155,7 @@ public IRubyObject initialize(final RubyString value) {
public RubyFixnum getLength(ThreadContext context) {
return new RubyFixnum(context.runtime, getLengthInternal());
}

private int getLengthInternal() {
if (this.mode == Mode.WRITE) {
return this.writePosition;
Expand Down Expand Up @@ -219,7 +219,7 @@ public RubyString toRubyString(ThreadContext context) {
int length = this.getLengthInternal();
byte[] bytes = new byte[length];
buffer_copy.get(bytes, 0, length);

return RubyString.newString(context.runtime, bytes);
}

Expand Down Expand Up @@ -322,7 +322,7 @@ public RubyFixnum getInt32() {

/**
* Get a 32 bit integer from the buffer.
*
*
*/
@JRubyMethod(name = "get_uint32")
public RubyFixnum getUInt32() {
Expand All @@ -334,7 +334,7 @@ public RubyFixnum getUInt32() {
if (temp < 0) {
temp += UINT32_MAX + 1;
}

RubyFixnum int32 = new RubyFixnum(getRuntime(), temp);
this.readPosition += 4;
return int32;
Expand Down Expand Up @@ -526,7 +526,7 @@ public ByteBuf putInt32(ThreadContext context, IRubyObject value) {
* Put an unsigned 32 bit integer onto the buffer.
*
* @param value The integer to write.
*
*
*/
@JRubyMethod(name = "put_uint32")
public ByteBuf putUInt32(ThreadContext context, IRubyObject value) {
Expand All @@ -536,12 +536,12 @@ public ByteBuf putUInt32(ThreadContext context, IRubyObject value) {
ensureBsonWrite(4);

long temp = RubyNumeric.fix2long((RubyFixnum) value);

if (temp > UINT32_MAX || temp < 0) {
throw getRuntime().newRangeError(format("Number %d is out of range [0, 2^32)", temp));
}

// When a long is cast to an int, Java appears to take the bits of the long and
// When a long is cast to an int, Java appears to take the bits of the long and
// use them as is for the int value. For example, if temp is 2^32-1, (int) temp
// would be -1, and if temp is 2^31, (int) temp would be -2^31.
this.buffer.putInt((int) temp);
Expand Down Expand Up @@ -738,7 +738,7 @@ private RubyString getUTF8String(ThreadContext context, final byte[] bytes) {
RubyString str = RubyString.newString(context.runtime, bytes, 0, bytes.length, UTF_8);
// ... hence validate manually:
convertToUtf8(context, str);

return str;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.bson;
package org.bson_ruby;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.bson;
package org.bson_ruby;

import java.lang.management.ManagementFactory;
import java.net.NetworkInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.bson;
package org.bson_ruby;

import java.io.IOException;

Expand Down

0 comments on commit f7ffa3f

Please sign in to comment.