Class: CBOR::Unpacker
- Inherits:
-
Object
- Object
- CBOR::Unpacker
- Defined in:
- ext/cbor/unpacker_class.c
Instance Method Summary collapse
- #buffer ⇒ Object
- #each ⇒ Object
-
#feed(data) ⇒ Object
rb_define_method(cMessagePack_Unpacker, “peek_next_type”, Unpacker_peek_next_type, 0); // TODO.
- #feed_each(data) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #read ⇒ Object (also: #unpack)
- #read_array_header ⇒ Object
- #read_map_header ⇒ Object
- #reset ⇒ Object
- #skip ⇒ Object
- #skip_nil ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/cbor/unpacker_class.c', line 70
static VALUE Unpacker_initialize(int argc, VALUE* argv, VALUE self)
{
VALUE io = Qnil;
VALUE options = Qnil;
if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
/* Qnil */
} else if(argc == 1) {
VALUE v = argv[0];
if(rb_type(v) == T_HASH) {
options = v;
} else {
io = v;
}
} else if(argc == 2) {
io = argv[0];
options = argv[1];
if(rb_type(options) != T_HASH) {
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
}
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
}
UNPACKER(self, uk);
if(io != Qnil || options != Qnil) {
MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, options);
if (options != Qnil) {
VALUE v;
v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys")));
uk->keys_as_symbols = RTEST(v);
}
}
// TODO options
return self;
}
|
Instance Method Details
#buffer ⇒ Object
128 129 130 131 132 |
# File 'ext/cbor/unpacker_class.c', line 128
static VALUE Unpacker_buffer(VALUE self)
{
UNPACKER(self, uk);
return uk->buffer_ref;
}
|
#each ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/cbor/unpacker_class.c', line 271
static VALUE Unpacker_each(VALUE self)
{
UNPACKER(self, uk);
#ifdef RETURN_ENUMERATOR
RETURN_ENUMERATOR(self, 0, 0);
#endif
if(msgpack_buffer_has_io(UNPACKER_BUFFER_(uk))) {
/* rescue EOFError only if io is set */
return rb_rescue2(Unpacker_each_impl, self,
Unpacker_rescue_EOFError, self,
rb_eEOFError, NULL);
} else {
return Unpacker_each_impl(self);
}
}
|
#feed(data) ⇒ Object
rb_define_method(cMessagePack_Unpacker, “peek_next_type”, Unpacker_peek_next_type, 0); // TODO
230 231 232 233 234 235 236 237 238 239 |
# File 'ext/cbor/unpacker_class.c', line 230
static VALUE Unpacker_feed(VALUE self, VALUE data)
{
UNPACKER(self, uk);
StringValue(data);
msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), data);
return self;
}
|
#feed_each(data) ⇒ Object
289 290 291 292 293 294 |
# File 'ext/cbor/unpacker_class.c', line 289
static VALUE Unpacker_feed_each(VALUE self, VALUE data)
{
// TODO optimize
Unpacker_feed(self, data);
return Unpacker_each(self);
}
|
#read ⇒ Object Also known as: unpack
134 135 136 137 138 139 140 141 142 143 144 |
# File 'ext/cbor/unpacker_class.c', line 134
static VALUE Unpacker_read(VALUE self)
{
UNPACKER(self, uk);
int r = msgpack_unpacker_read(uk, 0);
if(r < 0) {
raise_unpacker_error(r);
}
return msgpack_unpacker_get_last_object(uk);
}
|
#read_array_header ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/cbor/unpacker_class.c', line 173
static VALUE Unpacker_read_array_header(VALUE self)
{
UNPACKER(self, uk);
uint64_t size;
int r = msgpack_unpacker_read_array_header(uk, &size);
if(r < 0) {
raise_unpacker_error(r);
}
return rb_ull2inum(size);
}
|
#read_map_header ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'ext/cbor/unpacker_class.c', line 186
static VALUE Unpacker_read_map_header(VALUE self)
{
UNPACKER(self, uk);
uint64_t size;
int r = msgpack_unpacker_read_map_header(uk, &size);
if(r < 0) {
raise_unpacker_error((int)r);
}
return rb_ull2inum(size);
}
|
#reset ⇒ Object
296 297 298 299 300 301 302 303 |
# File 'ext/cbor/unpacker_class.c', line 296
static VALUE Unpacker_reset(VALUE self)
{
UNPACKER(self, uk);
msgpack_unpacker_reset(uk);
return Qnil;
}
|
#skip ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'ext/cbor/unpacker_class.c', line 146
static VALUE Unpacker_skip(VALUE self)
{
UNPACKER(self, uk);
int r = msgpack_unpacker_skip(uk, 0);
if(r < 0) {
raise_unpacker_error(r);
}
return Qnil;
}
|
#skip_nil ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'ext/cbor/unpacker_class.c', line 158
static VALUE Unpacker_skip_nil(VALUE self)
{
UNPACKER(self, uk);
int r = msgpack_unpacker_skip_nil(uk);
if(r < 0) {
raise_unpacker_error(r);
}
if(r) {
return Qtrue;
}
return Qfalse;
}
|