Class: Yajl::Projector
Instance Method Summary collapse
-
#initialize(stream, read_bufsize = 4096) ⇒ Projector
constructor
A new instance of Projector.
- #project(schema) ⇒ Object
Constructor Details
#initialize(stream, read_bufsize = 4096) ⇒ Projector
Returns a new instance of Projector.
27 28 29 30 |
# File 'lib/yajl.rb', line 27 def initialize(stream, read_bufsize=4096) @stream = stream @buffer_size = read_bufsize end |
Instance Method Details
#project(schema) ⇒ Object
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'ext/yajl/yajl_ext.c', line 985 static VALUE rb_yajl_projector_project(VALUE self, VALUE schema) { VALUE stream = rb_iv_get(self, "@stream"); long buffer_size = FIX2LONG(rb_iv_get(self, "@buffer_size")); VALUE buffer = rb_str_new(0, buffer_size); struct yajl_event_stream_s parser = { .funcs = &rb_alloc_funcs, .stream = stream, .buffer = buffer, .offset = (unsigned int)buffer_size, .lexer = yajl_lex_alloc(&rb_alloc_funcs, 0, 1), }; yajl_event_t event = yajl_event_stream_next(&parser, 1); RB_GC_GUARD(stream); RB_GC_GUARD(buffer); VALUE result; int state = 0; if (event.token == yajl_tok_left_brace || event.token == yajl_tok_left_bracket) { VALUE args[3]; args[0] = (VALUE)&parser; args[1] = schema; args[2] = (VALUE)&event; result = rb_protect(rb_protected_yajl_projector_filter, (VALUE)args, &state); } else { yajl_lex_free(parser.lexer); rb_raise(cParseError, "expected left bracket or brace, actually read %s", yajl_tok_name(event.token)); } yajl_lex_free(parser.lexer); if (state) rb_jump_tag(state); return result; } |