static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self) { VALUE io = Qnil; VALUE options = Qnil; if(argc == 0 || (argc == 1 && argv[0] == Qnil)) { /* Qnil */ } else if(argc == 1) { VALUE v = argv[0]; if(rb_type(v) == T_HASH) { options = v; } else { io = v; } } else if(argc == 2) { io = argv[0]; options = argv[1]; if(rb_type(options) != T_HASH) { rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(io)); } } else { rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc); } BUFFER(self, b); MessagePack_Buffer_set_options(b, io, options); return self; }
VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self) { VALUE io = Qnil; VALUE options = Qnil; if(argc == 0 || (argc == 1 && argv[0] == Qnil)) { /* Qnil */ } else if(argc == 1) { VALUE v = argv[0]; if(rb_type(v) == T_HASH) { options = v; if(rb_type(options) != T_HASH) { rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options)); } } else { io = v; } } else if(argc == 2) { io = argv[0]; options = argv[1]; if(rb_type(options) != T_HASH) { rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options)); } } else { rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); } UNPACKER(self, uk); MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options); if(options != Qnil) { VALUE v; v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys"))); msgpack_unpacker_set_symbolized_keys(uk, RTEST(v)); v = rb_hash_aref(options, ID2SYM(rb_intern("allow_unknown_ext"))); msgpack_unpacker_set_allow_unknown_ext(uk, RTEST(v)); } return self; }
VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self) { VALUE io = Qnil; VALUE options = Qnil; if(argc == 0 || (argc == 1 && argv[0] == Qnil)) { /* Qnil */ } else if(argc == 1) { VALUE v = argv[0]; if(rb_type(v) == T_HASH) { options = v; } else { io = v; } } else if(argc == 2) { io = argv[0]; options = argv[1]; if(rb_type(options) != T_HASH) { rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options)); } } else { rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); } PACKER(self, pk); MessagePack_Buffer_set_options(PACKER_BUFFER_(pk), io, options); if(options != Qnil) { VALUE v; v = rb_hash_aref(options, ID2SYM(rb_intern("compatibility_mode"))); msgpack_packer_set_compat(pk, RTEST(v)); } return self; }