/*
 * Document-method: Array#to_msgpack
 *
 * call-seq:
 *   array.to_msgpack(out = '') -> String
 *
 * Serializes the Array into raw bytes.
 * This calls to_msgpack method reflectively for internal elements.
 */
static VALUE MessagePack_Array_to_msgpack(int argc, VALUE *argv, VALUE self)
{
        ARG_BUFFER(out, argc, argv);
        // FIXME check sizeof(long) > sizeof(unsigned int) && RARRAY_LEN(self) > UINT_MAX
        unsigned int ary_length = (unsigned int)RARRAY_LEN(self);
        unsigned int i = 0;
        msgpack_pack_array(out, ary_length);
        for(; i < ary_length; ++i) {
                VALUE p = rb_ary_entry(self, i);
                rb_funcall(p, s_to_msgpack, 1, out);
        }
        return out;
}