decoder for data_timestamp

This commit is contained in:
Mike Dirolf 2009-04-22 13:49:56 -04:00
parent 1312c70677
commit 02b37f6e48
3 changed files with 24 additions and 0 deletions

View File

@ -611,6 +611,16 @@ static VALUE get_value(const char* buffer, int* position, int type) {
*position += 4;
break;
}
case 17:
{
int i;
int j;
memcpy(&i, buffer + *position, 4);
memcpy(&j, buffer + *position + 4, 4);
value = rb_ary_new3(2, LL2NUM(i), LL2NUM(j));
*position += 8;
break;
}
default:
{
rb_raise(rb_eTypeError, "no c decoder for this type yet (%d)", type);

View File

@ -46,6 +46,7 @@ class BSON
SYMBOL = 14
CODE_W_SCOPE = 15
NUMBER_INT = 16
TIMESTAMP = 17
MAXKEY = 127
if RUBY_VERSION >= '1.9'
@ -199,6 +200,10 @@ class BSON
when CODE_W_SCOPE
key = deserialize_cstr(@buf)
doc[key] = deserialize_code_w_scope_data(@buf)
when TIMESTAMP
key = deserialize_cstr(@buf)
doc[key] = [deserialize_number_int_data(@buf),
deserialize_number_int_data(@buf)]
when EOO
break
else

View File

@ -181,6 +181,15 @@ class BSONTest < Test::Unit::TestCase
assert_equal '_id', roundtrip.keys.first
end
def test_timestamp
val = {"test" => [4, 20]}
assert_equal val, @b.deserialize([0x13, 0x00, 0x00, 0x00,
0x11, 0x74, 0x65, 0x73,
0x74, 0x00, 0x04, 0x00,
0x00, 0x00, 0x14, 0x00,
0x00, 0x00, 0x00])
end
def test_do_not_change_original_object
val = OrderedHash.new
val['not_id'] = 1