Module: CBson
- Defined in:
- ext/cbson/cbson.c
Constant Summary collapse
- VERSION =
ext_version
Class Method Summary collapse
Class Method Details
.deserialize(bson) ⇒ Object
820 821 822 823 824 825 826 827 828 829 |
# File 'ext/cbson/cbson.c', line 820
static VALUE method_deserialize(VALUE self, VALUE bson) {
const char* buffer = RSTRING_PTR(bson);
int remaining = RSTRING_LEN(bson);
// NOTE we just swallow the size and end byte here
buffer += 4;
remaining -= 5;
return elements_to_hash(buffer, remaining);
}
|
.serialize(doc, check_keys, move_id) ⇒ Object
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'ext/cbson/cbson.c', line 541
static VALUE method_serialize(VALUE self, VALUE doc, VALUE check_keys, VALUE move_id) {
VALUE result;
buffer_t buffer = buffer_new();
if (buffer == NULL) {
rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c");
}
write_doc(buffer, doc, check_keys, move_id);
result = rb_str_new(buffer_get_buffer(buffer), buffer_get_position(buffer));
if (buffer_free(buffer) != 0) {
rb_raise(rb_eRuntimeError, "failed to free buffer");
}
return result;
}
|