@@ -408,15 +408,78 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
408408#undef construct_cb
409409}
410410
411+ #undef SWITCH_RANGE_BEGIN
412+ #undef SWITCH_RANGE
413+ #undef SWITCH_RANGE_DEFAULT
414+ #undef SWITCH_RANGE_END
411415#undef push_simple_value
412416#undef push_fixed_value
413417#undef push_variable_value
414418#undef again_fixed_trail
415419#undef again_fixed_trail_if_zero
416420#undef start_container
417421
422+ template <unsigned int fixed_offset, unsigned int var_offset>
423+ msgpack_unpack_func (int , _container_header)(msgpack_unpack_struct (_context)* ctx, const char * data, size_t len, size_t * off)
424+ {
425+ assert (len >= *off);
426+ uint32_t size;
427+ const unsigned char *const p = (unsigned char *)data + *off;
428+
429+ #define inc_offset (inc ) \
430+ if (len - *off < inc) \
431+ return 0 ; \
432+ *off += inc;
433+
434+ switch (*p) {
435+ case var_offset:
436+ inc_offset (3 );
437+ size = _msgpack_load16 (uint16_t , p + 1 );
438+ break ;
439+ case var_offset + 1 :
440+ inc_offset (5 );
441+ size = _msgpack_load32 (uint32_t , p + 1 );
442+ break ;
443+ #ifdef USE_CASE_RANGE
444+ case fixed_offset + 0x0 ... fixed_offset + 0xf :
445+ #else
446+ case fixed_offset + 0x0 :
447+ case fixed_offset + 0x1 :
448+ case fixed_offset + 0x2 :
449+ case fixed_offset + 0x3 :
450+ case fixed_offset + 0x4 :
451+ case fixed_offset + 0x5 :
452+ case fixed_offset + 0x6 :
453+ case fixed_offset + 0x7 :
454+ case fixed_offset + 0x8 :
455+ case fixed_offset + 0x9 :
456+ case fixed_offset + 0xa :
457+ case fixed_offset + 0xb :
458+ case fixed_offset + 0xc :
459+ case fixed_offset + 0xd :
460+ case fixed_offset + 0xe :
461+ case fixed_offset + 0xf :
462+ #endif
463+ ++*off;
464+ size = ((unsigned int )*p) & 0x0f ;
465+ break ;
466+ default :
467+ PyErr_SetString (PyExc_ValueError, " Unexpected type header on stream" );
468+ return -1 ;
469+ }
470+ msgpack_unpack_callback (_uint32)(&ctx->user , size, &ctx->stack [0 ].obj );
471+ return 1 ;
472+ }
473+
474+ #undef SWITCH_RANGE_BEGIN
475+ #undef SWITCH_RANGE
476+ #undef SWITCH_RANGE_DEFAULT
477+ #undef SWITCH_RANGE_END
478+
418479static const execute_fn template_construct = &template_execute<true >;
419480static const execute_fn template_skip = &template_execute<false >;
481+ static const execute_fn read_array_header = &template_container_header<0x90 , 0xdc >;
482+ static const execute_fn read_map_header = &template_container_header<0x80 , 0xde >;
420483
421484#undef msgpack_unpack_func
422485#undef msgpack_unpack_callback
0 commit comments