… | |
… | |
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 | { |
… | |
… | |
1422 | shrink = F_SHRINK |
1422 | shrink = F_SHRINK |
1423 | allow_unknown = F_ALLOW_UNKNOWN |
1423 | allow_unknown = F_ALLOW_UNKNOWN |
1424 | allow_sharing = F_ALLOW_SHARING |
1424 | allow_sharing = F_ALLOW_SHARING |
1425 | allow_cycles = F_ALLOW_CYCLES |
1425 | allow_cycles = F_ALLOW_CYCLES |
1426 | pack_strings = F_PACK_STRINGS |
1426 | pack_strings = F_PACK_STRINGS |
|
|
1427 | text_keys = F_TEXT_KEYS |
1427 | utf8_strings = F_UTF8_STRINGS |
1428 | text_strings = F_TEXT_STRINGS |
1428 | validate_utf8 = F_VALIDATE_UTF8 |
1429 | validate_utf8 = F_VALIDATE_UTF8 |
1429 | PPCODE: |
1430 | PPCODE: |
1430 | { |
1431 | { |
1431 | if (enable) |
1432 | if (enable) |
1432 | self->flags |= ix; |
1433 | self->flags |= ix; |
… | |
… | |
1441 | get_shrink = F_SHRINK |
1442 | get_shrink = F_SHRINK |
1442 | get_allow_unknown = F_ALLOW_UNKNOWN |
1443 | get_allow_unknown = F_ALLOW_UNKNOWN |
1443 | get_allow_sharing = F_ALLOW_SHARING |
1444 | get_allow_sharing = F_ALLOW_SHARING |
1444 | get_allow_cycles = F_ALLOW_CYCLES |
1445 | get_allow_cycles = F_ALLOW_CYCLES |
1445 | get_pack_strings = F_PACK_STRINGS |
1446 | get_pack_strings = F_PACK_STRINGS |
|
|
1447 | get_text_keys = F_TEXT_KEYS |
|
|
1448 | get_text_strings = F_TEXT_STRINGS |
1446 | get_validate_utf8 = F_VALIDATE_UTF8 |
1449 | get_validate_utf8 = F_VALIDATE_UTF8 |
1447 | PPCODE: |
1450 | PPCODE: |
1448 | XPUSHs (boolSV (self->flags & ix)); |
1451 | XPUSHs (boolSV (self->flags & ix)); |
1449 | |
1452 | |
1450 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |
1453 | void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) |