static int unpack_field(int ctype, int ptype, char * buffer, struct atom * a, void *out) { if (ctype == CTYPE_ARRAY) { return unpack_array(ptype, buffer, a , out); } if (ctype == CTYPE_PACKED) { pbc_ctx packed; struct context * ctx = (struct context *)packed; int n = _pbcC_open_packed(packed , ptype, (uint8_t *)buffer + a->v.s.start, a->v.s.end - a->v.s.start); if (n<=0) return -1; int i; int r =0; for (i=0;i<n;i++) { r |= unpack_array(ptype , buffer , &(ctx->a[i]) , out); } if (r) return -1; return 0; } switch(ptype) { case PTYPE_DOUBLE: return write_real(ctype, read_double(a), out); case PTYPE_FLOAT: return write_real(ctype, read_float(a), out); case PTYPE_INT64: case PTYPE_UINT64: case PTYPE_INT32: case PTYPE_UINT32: case PTYPE_FIXED32: case PTYPE_FIXED64: case PTYPE_SFIXED32: case PTYPE_SFIXED64: case PTYPE_ENUM: // enum must be integer type in pattern mode case PTYPE_BOOL: return write_integer(ctype, a , out); case PTYPE_SINT32: { struct longlong temp = a->v.i; varint_dezigzag32(&temp); return write_longlong(ctype, &temp , out); } case PTYPE_SINT64: { struct longlong temp = a->v.i; varint_dezigzag64(&temp); return write_longlong(ctype, &temp , out); } case PTYPE_MESSAGE: ((union _pbc_var *)out)->m.buffer = buffer + a->v.s.start; ((union _pbc_var *)out)->m.len = a->v.s.end - a->v.s.start; return 0; case PTYPE_STRING: ((union _pbc_var *)out)->s.str = buffer + a->v.s.start; ((union _pbc_var *)out)->s.len = a->v.s.end - a->v.s.start; return 0; } return -1; }
static int unpack(scanner_t *s, json_t *root, va_list *ap) { switch(s->token) { case '{': return unpack_object(s, root, ap); case '[': return unpack_array(s, root, ap); case 's': if(root && !json_is_string(root)) { set_error(s, "<validation>", "Expected string, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) { const char **target; target = va_arg(*ap, const char **); if(!target) { set_error(s, "<args>", "NULL string argument"); return -1; } if(root) *target = json_string_value(root); } return 0; case 'i': if(root && !json_is_integer(root)) { set_error(s, "<validation>", "Expected integer, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) { int *target = va_arg(*ap, int*); if(root) *target = (int)json_integer_value(root); } return 0; case 'I': if(root && !json_is_integer(root)) { set_error(s, "<validation>", "Expected integer, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) { json_int_t *target = va_arg(*ap, json_int_t*); if(root) *target = json_integer_value(root); }
ptr<pub3::expr_t> msgpack_t::unpack_fix_array () { u_int8_t b; bool ok = get_byte (&b); assert (ok); b ^= 0x90; return unpack_array (b); }
ptr<pub3::expr_t> msgpack_t::unpack_array16 () { consume_byte (); u_int16_t n; bool ok = unpack_int (&n); ptr<pub3::expr_t> ret; if (ok) { ret = unpack_array (n); } return ret; }
static ssize_t dec_array(amqp_value_t *v, mnbytestream_t *bs, int fd) { return unpack_array(bs, fd, &v->value.a); }
static sp_cuarray fun(PyObject* o, int i) { return unpack_array(o); }
static int unpack(scanner_t *s, json_t *root, va_list *ap) { switch(s->token) { case '{': return unpack_object(s, root, ap); case '[': return unpack_array(s, root, ap); case 's': if(!json_is_string(root)) { set_error(s, "<validation>", "Expected string, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) { const char **str; str = va_arg(*ap, const char **); if(!str) { set_error(s, "<args>", "NULL string argument"); return -1; } *str = json_string_value(root); } return 0; case 'i': if(!json_is_integer(root)) { set_error(s, "<validation>", "Expected integer, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, int*) = (int) json_integer_value(root); return 0; case 'I': if(!json_is_integer(root)) { set_error(s, "<validation>", "Expected integer, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, json_int_t*) = json_integer_value(root); return 0; case 'b': if(!json_is_boolean(root)) { set_error(s, "<validation>", "Expected true or false, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, int*) = json_is_true(root); return 0; case 'f': if(!json_is_real(root)) { set_error(s, "<validation>", "Expected real, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, double*) = json_real_value(root); return 0; case 'F': if(!json_is_number(root)) { set_error(s, "<validation>", "Expected real or integer, got %s", type_name(root)); return -1; } if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, double*) = json_number_value(root); return 0; case 'O': if(!(s->flags & JSON_VALIDATE_ONLY)) json_incref(root); /* Fall through */ case 'o': if(!(s->flags & JSON_VALIDATE_ONLY)) *va_arg(*ap, json_t**) = root; return 0; case 'n': /* Never assign, just validate */ if(!json_is_null(root)) { set_error(s, "<validation>", "Expected null, got %s", type_name(root)); return -1; } return 0; default: set_error(s, "<format>", "Unexpected format character '%c'", s->token); return -1; } }