… | |
… | |
100 | #define F_SHRINK 0x00000001UL |
100 | #define F_SHRINK 0x00000001UL |
101 | #define F_ALLOW_UNKNOWN 0x00000002UL |
101 | #define F_ALLOW_UNKNOWN 0x00000002UL |
102 | #define F_ALLOW_SHARING 0x00000004UL |
102 | #define F_ALLOW_SHARING 0x00000004UL |
103 | #define F_ALLOW_CYCLES 0x00000008UL |
103 | #define F_ALLOW_CYCLES 0x00000008UL |
104 | #define F_PACK_STRINGS 0x00000010UL |
104 | #define F_PACK_STRINGS 0x00000010UL |
105 | #define F_UTF8_STRINGS 0x00000020UL |
|
|
106 | #define F_UTF8_KEYS 0x00000040UL |
105 | #define F_TEXT_KEYS 0x00000020UL |
|
|
106 | #define F_TEXT_STRINGS 0x00000040UL |
107 | #define F_VALIDATE_UTF8 0x00000080UL |
107 | #define F_VALIDATE_UTF8 0x00000080UL |
108 | |
108 | |
109 | #define INIT_SIZE 32 // initial scalar size to be allocated |
109 | #define INIT_SIZE 32 // initial scalar size to be allocated |
110 | |
110 | |
111 | #define SB do { |
111 | #define SB do { |
… | |
… | |
317 | need (enc, len); |
317 | need (enc, len); |
318 | memcpy (enc->cur, str, len); |
318 | memcpy (enc->cur, str, len); |
319 | enc->cur += len; |
319 | enc->cur += len; |
320 | } |
320 | } |
321 | |
321 | |
322 | ecb_inline |
322 | ecb_inline void |
323 | encode_strref (enc_t *enc, int upgrade_utf8, int utf8, char *str, STRLEN len) |
323 | encode_strref (enc_t *enc, int upgrade_utf8, int utf8, char *str, STRLEN len) |
324 | { |
324 | { |
325 | if (ecb_expect_false (enc->cbor.flags & F_PACK_STRINGS)) |
325 | if (ecb_expect_false (enc->cbor.flags & F_PACK_STRINGS)) |
326 | { |
326 | { |
327 | SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1); |
327 | SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1); |
… | |
… | |
395 | while ((he = hv_iternext (hv))) |
395 | while ((he = hv_iternext (hv))) |
396 | { |
396 | { |
397 | if (HeKLEN (he) == HEf_SVKEY) |
397 | if (HeKLEN (he) == HEf_SVKEY) |
398 | encode_sv (enc, HeSVKEY (he)); |
398 | encode_sv (enc, HeSVKEY (he)); |
399 | else |
399 | else |
400 | encode_strref (enc, enc->cbor.flags & (F_UTF8_KEYS | F_UTF8_STRINGS), HeKUTF8 (he), HeKEY (he), HeKLEN (he)); |
400 | encode_strref (enc, enc->cbor.flags & (F_TEXT_KEYS | F_TEXT_STRINGS), HeKUTF8 (he), HeKEY (he), HeKLEN (he)); |
401 | |
401 | |
402 | encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he)); |
402 | encode_sv (enc, ecb_expect_false (mg) ? hv_iterval (hv, he) : HeVAL (he)); |
403 | } |
403 | } |
404 | |
404 | |
405 | if (mg) |
405 | if (mg) |
… | |
… | |
592 | |
592 | |
593 | if (SvPOKp (sv)) |
593 | if (SvPOKp (sv)) |
594 | { |
594 | { |
595 | STRLEN len; |
595 | STRLEN len; |
596 | char *str = SvPV (sv, len); |
596 | char *str = SvPV (sv, len); |
597 | encode_strref (enc, enc->cbor.flags & F_UTF8_STRINGS, SvUTF8 (sv), str, len); |
597 | encode_strref (enc, enc->cbor.flags & F_TEXT_STRINGS, SvUTF8 (sv), str, len); |
598 | } |
598 | } |
599 | else if (SvNOKp (sv)) |
599 | else if (SvNOKp (sv)) |
600 | encode_nv (enc, sv); |
600 | encode_nv (enc, sv); |
601 | else if (SvIOKp (sv)) |
601 | else if (SvIOKp (sv)) |
602 | { |
602 | { |
… | |
… | |
942 | sv = newRV_noinc (decode_sv (dec)); |
942 | sv = newRV_noinc (decode_sv (dec)); |
943 | break; |
943 | break; |
944 | |
944 | |
945 | case CBOR_TAG_STRINGREF_NAMESPACE: |
945 | case CBOR_TAG_STRINGREF_NAMESPACE: |
946 | { |
946 | { |
|
|
947 | // do nmot use SAVETMPS/FREETMPS, as these will |
|
|
948 | // erase mortalised caches, e.g. "shareable" |
947 | ENTER; SAVETMPS; |
949 | ENTER; |
948 | |
950 | |
949 | SAVESPTR (dec->stringref); |
951 | SAVESPTR (dec->stringref); |
950 | dec->stringref = (AV *)sv_2mortal ((SV *)newAV ()); |
952 | dec->stringref = (AV *)sv_2mortal ((SV *)newAV ()); |
951 | |
953 | |
952 | sv = decode_sv (dec); |
954 | sv = decode_sv (dec); |
953 | |
955 | |
954 | FREETMPS; LEAVE; |
956 | LEAVE; |
955 | } |
957 | } |
956 | break; |
958 | break; |
957 | |
959 | |
958 | case CBOR_TAG_STRINGREF: |
960 | case CBOR_TAG_STRINGREF: |
959 | { |
961 | { |
… | |
… | |
1422 | shrink = F_SHRINK |
1424 | shrink = F_SHRINK |
1423 | allow_unknown = F_ALLOW_UNKNOWN |
1425 | allow_unknown = F_ALLOW_UNKNOWN |
1424 | allow_sharing = F_ALLOW_SHARING |
1426 | allow_sharing = F_ALLOW_SHARING |
1425 | allow_cycles = F_ALLOW_CYCLES |
1427 | allow_cycles = F_ALLOW_CYCLES |
1426 | pack_strings = F_PACK_STRINGS |
1428 | pack_strings = F_PACK_STRINGS |
|
|
1429 | text_keys = F_TEXT_KEYS |
1427 | utf8_strings = F_UTF8_STRINGS |
1430 | text_strings = F_TEXT_STRINGS |
1428 | validate_utf8 = F_VALIDATE_UTF8 |
1431 | validate_utf8 = F_VALIDATE_UTF8 |
1429 | PPCODE: |
1432 | PPCODE: |
1430 | { |
1433 | { |
1431 | if (enable) |
1434 | if (enable) |
1432 | self->flags |= ix; |
1435 | self->flags |= ix; |
… | |
… | |
1441 | get_shrink = F_SHRINK |
1444 | get_shrink = F_SHRINK |
1442 | get_allow_unknown = F_ALLOW_UNKNOWN |
1445 | get_allow_unknown = F_ALLOW_UNKNOWN |
1443 | get_allow_sharing = F_ALLOW_SHARING |
1446 | get_allow_sharing = F_ALLOW_SHARING |
1444 | get_allow_cycles = F_ALLOW_CYCLES |
1447 | get_allow_cycles = F_ALLOW_CYCLES |
1445 | get_pack_strings = F_PACK_STRINGS |
1448 | get_pack_strings = F_PACK_STRINGS |
|
|
1449 | get_text_keys = F_TEXT_KEYS |
|
|
1450 | get_text_strings = F_TEXT_STRINGS |
1446 | get_validate_utf8 = F_VALIDATE_UTF8 |
1451 | get_validate_utf8 = F_VALIDATE_UTF8 |
1447 | PPCODE: |
1452 | PPCODE: |
1448 | XPUSHs (boolSV (self->flags & ix)); |
1453 | XPUSHs (boolSV (self->flags & ix)); |
1449 | |
1454 | |
1450 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |
1455 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |