/** * Document-method: MessagePack::Unpacker#each * * call-seq: * unpacker.each {|object| } * * Deserializes objects repeatedly. This calls *fill* method automatically. * * UnpackError is throw when parse error is occured. * This method raises exceptions that *fill* method raises. */ static VALUE MessagePack_Unpacker_each(VALUE self) { UNPACKER(self, mp); int ret; #ifdef RETURN_ENUMERATOR RETURN_ENUMERATOR(self, 0, 0); #endif while(1) { if(mp->user.buffer.used <= mp->user.offset) { do_fill: { VALUE len = MessagePack_Unpacker_fill(self); if(len == Qnil || FIX2LONG(len) == 0) { break; } } } ret = template_execute_wrap_each(mp, mp->user.buffer.ptr, mp->user.buffer.used, &mp->user.offset); if(ret < 0) { rb_raise(eUnpackError, "parse error."); } else if(ret > 0) { VALUE data = template_data(mp); template_init(mp); rb_yield(data); } else { goto do_fill; } } try_free_buffer(mp, 0); return Qnil; }