Method: Yajl::Parser#parse_chunk

Defined in:
ext/yajl/yajl_ext.c

#parse_chunk(chunk) ⇒ Object

call-seq: parse_chunk(string_chunk)

string_chunk can be a partial or full JSON string to push on the parser.

This method will throw an exception if the on_parse_complete callback hasn’t been assigned yet. The on_parse_complete callback assignment is required so the user can handle objects that have been parsed off the stream as they’re found.



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'ext/yajl/yajl_ext.c', line 594

static VALUE rb_yajl_parser_parse_chunk(VALUE self, VALUE chunk) {
    yajl_parser_wrapper * wrapper;
    unsigned int len;

    GetParser(self, wrapper);
    if (NIL_P(chunk)) {
        rb_raise(cParseError, "Can't parse a nil string.");
    }

    if (wrapper->parse_complete_callback != Qnil) {
        const char * cptr = RSTRING_PTR(chunk);
        len = (unsigned int)RSTRING_LEN(chunk);
        yajl_parse_chunk((const unsigned char*)cptr, len, wrapper->parser);
    } else {
        rb_raise(cParseError, "The on_parse_complete callback isn't setup, parsing useless.");
    }

    return Qnil;
}