@@ -102,6 +102,16 @@ STATIC uint32_t read4(msgpack_stream_t *s) {
102
102
return res ;
103
103
}
104
104
105
+ STATIC uint64_t read8 (msgpack_stream_t * s ) {
106
+ uint64_t res = 0 ;
107
+ read (s , & res , 8 );
108
+ int n = 1 ;
109
+ if (* (char * )& n == 1 ) {
110
+ res = __builtin_bswap64 (res );
111
+ }
112
+ return res ;
113
+ }
114
+
105
115
STATIC size_t read_size (msgpack_stream_t * s , uint8_t len_index ) {
106
116
size_t res = 0 ;
107
117
switch (len_index ) {
@@ -207,7 +217,7 @@ STATIC void pack_bin(msgpack_stream_t *s, const uint8_t *data, size_t len) {
207
217
}
208
218
}
209
219
210
- STATIC void pack_ext (msgpack_stream_t * s , int8_t code , const uint8_t * data , size_t len ) {
220
+ STATIC void pack_ext (msgpack_stream_t * s , int8_t code , const uint8_t * data , size_t len ) {
211
221
if (len == 1 ) {
212
222
write1 (s , 0xd4 );
213
223
} else if (len == 2 ) {
@@ -424,22 +434,39 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
424
434
return unpack_bytes (s , read_size (s , code - 0xc4 ));
425
435
}
426
436
case 0xcc : // uint8
437
+ return MP_OBJ_NEW_SMALL_INT ((uint8_t )read1 (s ));
427
438
case 0xd0 : // int8
428
439
return MP_OBJ_NEW_SMALL_INT ((int8_t )read1 (s ));
429
440
case 0xcd : // uint16
441
+ return MP_OBJ_NEW_SMALL_INT ((uint16_t )read2 (s ));
430
442
case 0xd1 : // int16
431
443
return MP_OBJ_NEW_SMALL_INT ((int16_t )read2 (s ));
432
444
case 0xce : // uint32
445
+ return mp_obj_new_int_from_uint ((uint32_t )read4 (s ));
433
446
case 0xd2 : // int32
434
- return MP_OBJ_NEW_SMALL_INT ((int32_t )read4 (s ));
435
- case 0xca : {
436
- union Float { mp_float_t f ;
437
- uint32_t u ;
447
+ return mp_obj_new_int ((int32_t )read4 (s ));
448
+ case 0xcf : // uint 64
449
+ return mp_obj_new_int_from_ull ((uint64_t )read8 (s ));
450
+ case 0xd3 : // int 64
451
+ return mp_obj_new_int_from_ll ((int64_t )read8 (s ));
452
+ case 0xca : { // float
453
+ union Float {
454
+ mp_float_t f ;
455
+ uint32_t u ;
438
456
};
439
457
union Float data ;
440
458
data .u = read4 (s );
441
459
return mp_obj_new_float (data .f );
442
460
}
461
+ case 0xcb : { // double
462
+ union Double {
463
+ uint64_t u ;
464
+ double d ;
465
+ };
466
+ union Double data ;
467
+ data .u = read8 (s );
468
+ return mp_obj_new_float_from_d (data .d );
469
+ }
443
470
case 0xd9 :
444
471
case 0xda :
445
472
case 0xdb : {
@@ -483,11 +510,8 @@ STATIC mp_obj_t unpack(msgpack_stream_t *s, mp_obj_t ext_hook, bool use_list) {
483
510
// ext 8, 16, 32
484
511
return unpack_ext (s , read_size (s , code - 0xc7 ), ext_hook );
485
512
case 0xc1 : // never used
486
- case 0xcb : // float 64
487
- case 0xcf : // uint 64
488
- case 0xd3 : // int 64
489
513
default :
490
- mp_raise_NotImplementedError (translate ("64 bit types " ));
514
+ mp_raise_ValueError (translate ("Invalid format " ));
491
515
}
492
516
}
493
517
0 commit comments