| 1 |
static inline int unpack_container_header(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off) |
| 2 |
{ |
| 3 |
assert(len >= *off); |
| 4 |
uint32_t size; |
| 5 |
const unsigned char *const p = (unsigned char*)data + *off; |
| 6 |
|
| 7 |
#define inc_offset(inc) \ |
| 8 |
if (len - *off < inc) \ |
| 9 |
return 0; \ |
| 10 |
*off += inc; |
| 11 |
|
| 12 |
switch (*p) { |
| 13 |
case var_offset: |
| 14 |
inc_offset(3); |
| 15 |
size = _msgpack_load16(uint16_t, p + 1); |
| 16 |
break; |
| 17 |
case var_offset + 1: |
| 18 |
inc_offset(5); |
| 19 |
size = _msgpack_load32(uint32_t, p + 1); |
| 20 |
break; |
| 21 |
#ifdef USE_CASE_RANGE |
| 22 |
case fixed_offset + 0x0 ... fixed_offset + 0xf: |
| 23 |
#else |
| 24 |
case fixed_offset + 0x0: |
| 25 |
case fixed_offset + 0x1: |
| 26 |
case fixed_offset + 0x2: |
| 27 |
case fixed_offset + 0x3: |
| 28 |
case fixed_offset + 0x4: |
| 29 |
case fixed_offset + 0x5: |
| 30 |
case fixed_offset + 0x6: |
| 31 |
case fixed_offset + 0x7: |
| 32 |
case fixed_offset + 0x8: |
| 33 |
case fixed_offset + 0x9: |
| 34 |
case fixed_offset + 0xa: |
| 35 |
case fixed_offset + 0xb: |
| 36 |
case fixed_offset + 0xc: |
| 37 |
case fixed_offset + 0xd: |
| 38 |
case fixed_offset + 0xe: |
| 39 |
case fixed_offset + 0xf: |
| 40 |
#endif |
| 41 |
++*off; |
| 42 |
size = ((unsigned int)*p) & 0x0f; |
| 43 |
break; |
| 44 |
default: |
| 45 |
PyErr_SetString(PyExc_ValueError, "Unexpected type header on stream"); |
| 46 |
return -1; |
| 47 |
} |
| 48 |
|
| 49 |
if (unpack_callback_uint32(&ctx->user, size, &ctx->stack[0].obj) < 0) |
| 50 |
return -1; |
| 51 |
|
| 52 |
return 1; |
| 53 |
} |
| 54 |
|