diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index 06132fb..8a78bd5 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -197,6 +197,16 @@ static int write_element(VALUE key, VALUE value, VALUE extra) { buffer_write_bytes(buffer, RSTRING(string_data)->ptr, length); break; } + if (strcmp(cls, "XGen::Mongo::Driver::ObjectID") == 0) { + write_name_and_type(buffer, key, 0x07); + VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0); + int i; + for (i = 0; i < 12; i++) { + char byte = (char)FIX2INT(RARRAY(as_array)->ptr[i]); + buffer_write_bytes(buffer, &byte, 1); + } + break; + } if (strcmp(cls, "XGen::Mongo::Driver::Undefined") == 0) { write_name_and_type(buffer, key, 0x06); break; diff --git a/lib/mongo/util/byte_buffer.rb b/lib/mongo/util/byte_buffer.rb index 9939238..7b539cb 100644 --- a/lib/mongo/util/byte_buffer.rb +++ b/lib/mongo/util/byte_buffer.rb @@ -100,7 +100,11 @@ class ByteBuffer if one_byte @buf[start] else - @buf[start, len] + if @buf.respond_to? "unpack" + @buf[start, len].unpack("C*") + else + @buf[start, len] + end end end