Module: CBson
- Defined in:
- ext/cbson/cbson.c
Constant Summary collapse
- VERSION =
ext_version
Class Method Summary collapse
- .deserialize(bson, opts) ⇒ Object
- .max_bson_size ⇒ Object
- .serialize(doc, check_keys, move_id, max_size) ⇒ Object
- .update_max_bson_size(connection) ⇒ Object
Class Method Details
.deserialize(bson, opts) ⇒ Object
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
# File 'ext/cbson/cbson.c', line 981 static VALUE method_deserialize(VALUE self, VALUE bson, VALUE opts) { const char* buffer = RSTRING_PTR(bson); int remaining = RSTRING_LENINT(bson); struct deserialize_opts deserialize_opts; deserialize_opts.compile_regex = 1; if (rb_funcall(opts, rb_intern("has_key?"), 1, ID2SYM(rb_intern("compile_regex"))) == Qtrue && rb_hash_aref(opts, ID2SYM(rb_intern("compile_regex"))) == Qfalse) { deserialize_opts.compile_regex = 0; } // NOTE we just swallow the size and end byte here buffer += 4; remaining -= 5; return elements_to_hash(buffer, remaining, &deserialize_opts); } |
.max_bson_size ⇒ Object
1129 1130 1131 |
# File 'ext/cbson/cbson.c', line 1129 static VALUE method_max_bson_size(VALUE self) { return INT2FIX(max_bson_size); } |
.serialize(doc, check_keys, move_id, max_size) ⇒ Object
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'ext/cbson/cbson.c', line 703 static VALUE method_serialize(VALUE self, VALUE doc, VALUE check_keys, VALUE move_id, VALUE max_size) { VALUE result; bson_buffer_t buffer = bson_buffer_new(); if (buffer == NULL) { rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c"); } bson_buffer_set_max_size(buffer, FIX2INT(max_size)); write_doc(buffer, doc, check_keys, move_id); result = rb_str_new(bson_buffer_get_buffer(buffer), bson_buffer_get_position(buffer)); if (bson_buffer_free(buffer) != 0) { rb_raise(rb_eRuntimeError, "failed to free buffer"); } return result; } |
.update_max_bson_size(connection) ⇒ Object
1124 1125 1126 1127 |
# File 'ext/cbson/cbson.c', line 1124 static VALUE method_update_max_bson_size(VALUE self, VALUE connection) { max_bson_size = FIX2INT(rb_funcall(connection, rb_intern("max_bson_size"), 0)); return INT2FIX(max_bson_size); } |