static mrb_value Packer_write_map_header(mrb_state* mrb, mrb_value self) { mrb_int n; mrb_get_args(mrb, "i", &n); PACKER(mrb, self, pk); msgpack_packer_write_map_header(mrb, pk, n); return self; }
void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v) { /* actual return type of RHASH_SIZE is long (if SIZEOF_LONG == SIZEOF_VOIDP * or long long (if SIZEOF_LONG_LONG == SIZEOF_VOIDP. See st.h. */ unsigned long len = RHASH_SIZE(v); if(len > 0xffffffffUL) { rb_raise(rb_eArgError, "size of array is too long to pack: %ld bytes should be <= %lu", len, 0xffffffffUL); } unsigned int len32 = (unsigned int)len; msgpack_packer_write_map_header(pk, len32); #ifdef RUBINIUS VALUE iter = rb_funcall(v, s_to_iter, 0); VALUE entry = Qnil; while(RTEST(entry = rb_funcall(iter, s_next, 1, entry))) { VALUE key = rb_funcall(entry, s_key, 0); VALUE val = rb_funcall(entry, s_value, 0); write_hash_foreach(key, val, (VALUE) pk); } #else rb_hash_foreach(v, write_hash_foreach, (VALUE) pk); #endif }
static VALUE Packer_write_map_header(VALUE self, VALUE n) { PACKER(self, pk); msgpack_packer_write_map_header(pk, NUM2UINT(n)); return self; }