Module: JSONSL

Defined in:
lib/jsonsl/error.rb,
lib/jsonsl.rb,
lib/jsonsl/version.rb,
ext/jsonsl_ext/jsonsl_ext.c

Overview

Author

Couchbase <[email protected]>

Copyright

2018 Couchbase, Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Classes: Error, RowParser

Constant Summary collapse

VERSION =
'0.1.1'
REVISION =
rb_str_freeze(rb_str_new_cstr(JSONSL_REVISION))

Class Method Summary collapse

Class Method Details

.parse(*args) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'ext/jsonsl_ext/jsonsl_ext.c', line 130

static VALUE jsl_jsonsl_parse(int argc, VALUE *argv, VALUE self)
{
    jsonsl_t jsn;
    VALUE nlevels = Qnil, str = Qnil;

    rb_scan_args(argc, argv, "11", &str, &nlevels);
    Check_Type(str, T_STRING);
    if (nlevels != Qnil) {
        Check_Type(nlevels, T_FIXNUM);
        jsn = jsonsl_new(FIX2INT(nlevels));
    } else {
        jsn = jsonsl_new(JSONSL_MAX_LEVELS);
    }
    jsonsl_reset(jsn);
    jsn->data = (void *)Qnil;
    jsonsl_enable_all_callbacks(jsn);
    jsn->action_callback_PUSH = jsl_jsonsl_push_callback;
    jsn->action_callback_POP = jsl_jsonsl_pop_callback;
    jsn->error_callback = jsl_jsonsl_error_callback;
    jsonsl_feed(jsn, RSTRING_PTR(str), RSTRING_LEN(str));
    if (jsn->level != 0) {
        jsl_raise_msg("unexpected end of data");
    }
    (void)self;
    return (VALUE)jsn->data;
}