… | |
… | |
4 | |
4 | |
5 | #include "assert.h" |
5 | #include "assert.h" |
6 | #include "string.h" |
6 | #include "string.h" |
7 | #include "stdlib.h" |
7 | #include "stdlib.h" |
8 | |
8 | |
9 | #define F_ASCII 0x00000001 |
9 | #define F_ASCII 0x00000001UL |
10 | #define F_UTF8 0x00000002 |
10 | #define F_UTF8 0x00000002UL |
11 | #define F_INDENT 0x00000004 |
11 | #define F_INDENT 0x00000004UL |
12 | #define F_CANONICAL 0x00000008 |
12 | #define F_CANONICAL 0x00000008UL |
13 | #define F_SPACE_BEFORE 0x00000010 |
13 | #define F_SPACE_BEFORE 0x00000010UL |
14 | #define F_SPACE_AFTER 0x00000020 |
14 | #define F_SPACE_AFTER 0x00000020UL |
15 | #define F_ALLOW_NONREF 0x00000080 |
15 | #define F_ALLOW_NONREF 0x00000080UL |
16 | #define F_SHRINK 0x00000100 |
16 | #define F_SHRINK 0x00000100UL |
|
|
17 | #define F_MAXDEPTH 0xf8000000UL |
|
|
18 | #define S_MAXDEPTH 27 |
|
|
19 | |
|
|
20 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
|
|
21 | |
|
|
22 | // F_SELFCONVERT? <=> to_json/toJson |
|
|
23 | // F_BLESSED? <=> { $__class__$ => } |
17 | |
24 | |
18 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
25 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
19 | #define F_DEFAULT 0 |
26 | #define F_DEFAULT (12UL << S_MAXDEPTH) |
20 | |
27 | |
21 | #define INIT_SIZE 32 // initial scalar size to be allocated |
28 | #define INIT_SIZE 32 // initial scalar size to be allocated |
22 | #define INDENT_STEP 3 // spaces per indentation level |
29 | #define INDENT_STEP 3 // spaces per indentation level |
23 | |
30 | |
24 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
31 | #define UTF8_MAX_LEN 11 // for perls UTF-X: max. number of octets per character |
25 | #define SHORT_STRING_LEN 256 // special-case strings of up to this size |
32 | #define SHORT_STRING_LEN 512 // special-case strings of up to this size |
26 | |
33 | |
27 | #define SB do { |
34 | #define SB do { |
28 | #define SE } while (0) |
35 | #define SE } while (0) |
29 | |
36 | |
30 | static HV *json_stash; // JSON::XS:: |
37 | static HV *json_stash; // JSON::XS:: |
… | |
… | |
53 | SvPV_renew (sv, SvCUR (sv) + 1); |
60 | SvPV_renew (sv, SvCUR (sv) + 1); |
54 | #endif |
61 | #endif |
55 | } |
62 | } |
56 | } |
63 | } |
57 | |
64 | |
|
|
65 | // decode an utf-8 character and return it, or (UV)-1 in |
|
|
66 | // case of an error. |
|
|
67 | // we special-case "safe" characters from U+80 .. U+7FF, |
|
|
68 | // but use the very good perl function to parse anything else. |
|
|
69 | // note that we never call this function for a ascii codepoints |
|
|
70 | static UV |
|
|
71 | decode_utf8 (unsigned char *s, STRLEN len, STRLEN *clen) |
|
|
72 | { |
|
|
73 | if (s[0] > 0xdf || s[0] < 0xc2) |
|
|
74 | return utf8n_to_uvuni (s, len, clen, UTF8_CHECK_ONLY); |
|
|
75 | else if (len > 1 && s[1] >= 0x80 && s[1] <= 0xbf) |
|
|
76 | { |
|
|
77 | *clen = 2; |
|
|
78 | return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); |
|
|
79 | } |
|
|
80 | else |
|
|
81 | return (UV)-1; |
|
|
82 | } |
|
|
83 | |
58 | ///////////////////////////////////////////////////////////////////////////// |
84 | ///////////////////////////////////////////////////////////////////////////// |
59 | // encoder |
85 | // encoder |
60 | |
86 | |
61 | // structure used for encoding JSON |
87 | // structure used for encoding JSON |
62 | typedef struct |
88 | typedef struct |
63 | { |
89 | { |
64 | char *cur; // SvPVX (sv) + current output position |
90 | char *cur; // SvPVX (sv) + current output position |
65 | char *end; // SvEND (sv) |
91 | char *end; // SvEND (sv) |
66 | SV *sv; // result scalar |
92 | SV *sv; // result scalar |
67 | UV flags; // F_* |
93 | U32 flags; // F_* |
68 | int indent; // indentation level |
94 | U32 indent; // indentation level |
69 | int max_depth; // max. recursion level |
95 | U32 maxdepth; // max. indentation/recursion level |
70 | } enc_t; |
96 | } enc_t; |
71 | |
97 | |
72 | static void |
98 | static void |
73 | need (enc_t *enc, STRLEN len) |
99 | need (enc_t *enc, STRLEN len) |
74 | { |
100 | { |
… | |
… | |
133 | STRLEN clen; |
159 | STRLEN clen; |
134 | UV uch; |
160 | UV uch; |
135 | |
161 | |
136 | if (is_utf8) |
162 | if (is_utf8) |
137 | { |
163 | { |
138 | uch = utf8n_to_uvuni (str, end - str, &clen, UTF8_CHECK_ONLY); |
164 | //uch = utf8n_to_uvuni (str, end - str, &clen, UTF8_CHECK_ONLY); |
|
|
165 | uch = decode_utf8 (str, end - str, &clen); |
139 | if (clen == (STRLEN)-1) |
166 | if (clen == (STRLEN)-1) |
140 | croak ("malformed or illegal unicode character in string [%.11s], cannot convert to JSON", str); |
167 | croak ("malformed or illegal unicode character in string [%.11s], cannot convert to JSON", str); |
141 | } |
168 | } |
142 | else |
169 | else |
143 | { |
170 | { |
… | |
… | |
241 | static void |
268 | static void |
242 | encode_av (enc_t *enc, AV *av) |
269 | encode_av (enc_t *enc, AV *av) |
243 | { |
270 | { |
244 | int i, len = av_len (av); |
271 | int i, len = av_len (av); |
245 | |
272 | |
|
|
273 | if (enc->indent >= enc->maxdepth) |
|
|
274 | croak ("data structure too deep (hit recursion limit)"); |
|
|
275 | |
246 | encode_ch (enc, '['); encode_nl (enc); |
276 | encode_ch (enc, '['); encode_nl (enc); |
247 | ++enc->indent; |
277 | ++enc->indent; |
248 | |
278 | |
249 | for (i = 0; i <= len; ++i) |
279 | for (i = 0; i <= len; ++i) |
250 | { |
280 | { |
… | |
… | |
315 | |
345 | |
316 | static void |
346 | static void |
317 | encode_hv (enc_t *enc, HV *hv) |
347 | encode_hv (enc_t *enc, HV *hv) |
318 | { |
348 | { |
319 | int count, i; |
349 | int count, i; |
|
|
350 | |
|
|
351 | if (enc->indent >= enc->maxdepth) |
|
|
352 | croak ("data structure too deep (hit recursion limit)"); |
320 | |
353 | |
321 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
354 | encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; |
322 | |
355 | |
323 | if ((count = hv_iterinit (hv))) |
356 | if ((count = hv_iterinit (hv))) |
324 | { |
357 | { |
… | |
… | |
393 | } |
426 | } |
394 | |
427 | |
395 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
428 | --enc->indent; encode_indent (enc); encode_ch (enc, '}'); |
396 | } |
429 | } |
397 | |
430 | |
|
|
431 | // encode objects, arrays and special \0=false and \1=true values. |
|
|
432 | static void |
|
|
433 | encode_rv (enc_t *enc, SV *sv) |
|
|
434 | { |
|
|
435 | SvGETMAGIC (sv); |
|
|
436 | |
|
|
437 | svtype svt = SvTYPE (sv); |
|
|
438 | |
|
|
439 | if (svt == SVt_PVHV) |
|
|
440 | encode_hv (enc, (HV *)sv); |
|
|
441 | else if (svt == SVt_PVAV) |
|
|
442 | encode_av (enc, (AV *)sv); |
|
|
443 | else if (svt < SVt_PVAV) |
|
|
444 | { |
|
|
445 | if (SvNIOK (sv) && SvIV (sv) == 0) |
|
|
446 | encode_str (enc, "false", 5, 0); |
|
|
447 | else if (SvNIOK (sv) && SvIV (sv) == 1) |
|
|
448 | encode_str (enc, "true", 4, 0); |
|
|
449 | else |
|
|
450 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
|
|
451 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
452 | } |
|
|
453 | else |
|
|
454 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
455 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
|
|
456 | } |
|
|
457 | |
398 | static void |
458 | static void |
399 | encode_sv (enc_t *enc, SV *sv) |
459 | encode_sv (enc_t *enc, SV *sv) |
400 | { |
460 | { |
401 | SvGETMAGIC (sv); |
461 | SvGETMAGIC (sv); |
402 | |
462 | |
… | |
… | |
421 | SvIsUV(sv) |
481 | SvIsUV(sv) |
422 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
482 | ? snprintf (enc->cur, 64, "%"UVuf, (UV)SvUVX (sv)) |
423 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
483 | : snprintf (enc->cur, 64, "%"IVdf, (IV)SvIVX (sv)); |
424 | } |
484 | } |
425 | else if (SvROK (sv)) |
485 | else if (SvROK (sv)) |
426 | { |
486 | encode_rv (enc, SvRV (sv)); |
427 | SV *rv = SvRV (sv); |
|
|
428 | |
|
|
429 | if (enc->indent >= enc->max_depth) |
|
|
430 | croak ("data structure too deep (hit recursion limit)"); |
|
|
431 | |
|
|
432 | switch (SvTYPE (rv)) |
|
|
433 | { |
|
|
434 | case SVt_PVAV: encode_av (enc, (AV *)rv); break; |
|
|
435 | case SVt_PVHV: encode_hv (enc, (HV *)rv); break; |
|
|
436 | |
|
|
437 | default: |
|
|
438 | croak ("encountered %s, but JSON can only represent references to arrays or hashes", |
|
|
439 | SvPV_nolen (sv)); |
|
|
440 | } |
|
|
441 | } |
|
|
442 | else if (!SvOK (sv)) |
487 | else if (!SvOK (sv)) |
443 | encode_str (enc, "null", 4, 0); |
488 | encode_str (enc, "null", 4, 0); |
444 | else |
489 | else |
445 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
490 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
446 | SvPV_nolen (sv), SvFLAGS (sv)); |
491 | SvPV_nolen (sv), SvFLAGS (sv)); |
447 | } |
492 | } |
448 | |
493 | |
449 | static SV * |
494 | static SV * |
450 | encode_json (SV *scalar, UV flags) |
495 | encode_json (SV *scalar, U32 flags) |
451 | { |
496 | { |
452 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
497 | if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) |
453 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
498 | croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); |
454 | |
499 | |
455 | enc_t enc; |
500 | enc_t enc; |
456 | enc.flags = flags; |
501 | enc.flags = flags; |
457 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
502 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
458 | enc.cur = SvPVX (enc.sv); |
503 | enc.cur = SvPVX (enc.sv); |
459 | enc.end = SvEND (enc.sv); |
504 | enc.end = SvEND (enc.sv); |
460 | enc.indent = 0; |
505 | enc.indent = 0; |
461 | enc.max_depth = 0x7fffffffUL; |
506 | enc.maxdepth = DEC_DEPTH (flags); |
462 | |
507 | |
463 | SvPOK_only (enc.sv); |
508 | SvPOK_only (enc.sv); |
464 | encode_sv (&enc, scalar); |
509 | encode_sv (&enc, scalar); |
465 | |
510 | |
466 | if (!(flags & (F_ASCII | F_UTF8))) |
511 | if (!(flags & (F_ASCII | F_UTF8))) |
… | |
… | |
481 | typedef struct |
526 | typedef struct |
482 | { |
527 | { |
483 | char *cur; // current parser pointer |
528 | char *cur; // current parser pointer |
484 | char *end; // end of input string |
529 | char *end; // end of input string |
485 | const char *err; // parse error, if != 0 |
530 | const char *err; // parse error, if != 0 |
486 | UV flags; // F_* |
531 | U32 flags; // F_* |
|
|
532 | U32 depth; // recursion depth |
|
|
533 | U32 maxdepth; // recursion depth limit |
487 | } dec_t; |
534 | } dec_t; |
488 | |
535 | |
489 | static void |
536 | static void |
490 | decode_ws (dec_t *dec) |
537 | decode_ws (dec_t *dec) |
491 | { |
538 | { |
… | |
… | |
500 | ++dec->cur; |
547 | ++dec->cur; |
501 | } |
548 | } |
502 | } |
549 | } |
503 | |
550 | |
504 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
551 | #define ERR(reason) SB dec->err = reason; goto fail; SE |
|
|
552 | |
505 | #define EXPECT_CH(ch) SB \ |
553 | #define EXPECT_CH(ch) SB \ |
506 | if (*dec->cur != ch) \ |
554 | if (*dec->cur != ch) \ |
507 | ERR (# ch " expected"); \ |
555 | ERR (# ch " expected"); \ |
508 | ++dec->cur; \ |
556 | ++dec->cur; \ |
509 | SE |
557 | SE |
|
|
558 | |
|
|
559 | #define DEC_INC_DEPTH if (++dec->depth > dec->maxdepth) ERR ("json datastructure exceeds maximum nesting level (set a higher max_depth)") |
|
|
560 | #define DEC_DEC_DEPTH --dec->depth |
510 | |
561 | |
511 | static SV *decode_sv (dec_t *dec); |
562 | static SV *decode_sv (dec_t *dec); |
512 | |
563 | |
513 | static signed char decode_hexdigit[256]; |
564 | static signed char decode_hexdigit[256]; |
514 | |
565 | |
… | |
… | |
619 | else if (ch >= 0x80) |
670 | else if (ch >= 0x80) |
620 | { |
671 | { |
621 | --dec->cur; |
672 | --dec->cur; |
622 | |
673 | |
623 | STRLEN clen; |
674 | STRLEN clen; |
624 | UV uch = utf8n_to_uvuni (dec->cur, dec->end - dec->cur, &clen, UTF8_CHECK_ONLY); |
675 | UV uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); |
625 | if (clen == (STRLEN)-1) |
676 | if (clen == (STRLEN)-1) |
626 | ERR ("malformed UTF-8 character in JSON string"); |
677 | ERR ("malformed UTF-8 character in JSON string"); |
627 | |
678 | |
628 | do |
679 | do |
629 | { |
680 | { |
… | |
… | |
758 | static SV * |
809 | static SV * |
759 | decode_av (dec_t *dec) |
810 | decode_av (dec_t *dec) |
760 | { |
811 | { |
761 | AV *av = newAV (); |
812 | AV *av = newAV (); |
762 | |
813 | |
|
|
814 | DEC_INC_DEPTH; |
763 | decode_ws (dec); |
815 | decode_ws (dec); |
|
|
816 | |
764 | if (*dec->cur == ']') |
817 | if (*dec->cur == ']') |
765 | ++dec->cur; |
818 | ++dec->cur; |
766 | else |
819 | else |
767 | for (;;) |
820 | for (;;) |
768 | { |
821 | { |
… | |
… | |
786 | ERR (", or ] expected while parsing array"); |
839 | ERR (", or ] expected while parsing array"); |
787 | |
840 | |
788 | ++dec->cur; |
841 | ++dec->cur; |
789 | } |
842 | } |
790 | |
843 | |
|
|
844 | DEC_DEC_DEPTH; |
791 | return newRV_noinc ((SV *)av); |
845 | return newRV_noinc ((SV *)av); |
792 | |
846 | |
793 | fail: |
847 | fail: |
794 | SvREFCNT_dec (av); |
848 | SvREFCNT_dec (av); |
|
|
849 | DEC_DEC_DEPTH; |
795 | return 0; |
850 | return 0; |
796 | } |
851 | } |
797 | |
852 | |
798 | static SV * |
853 | static SV * |
799 | decode_hv (dec_t *dec) |
854 | decode_hv (dec_t *dec) |
800 | { |
855 | { |
801 | HV *hv = newHV (); |
856 | HV *hv = newHV (); |
802 | |
857 | |
|
|
858 | DEC_INC_DEPTH; |
803 | decode_ws (dec); |
859 | decode_ws (dec); |
|
|
860 | |
804 | if (*dec->cur == '}') |
861 | if (*dec->cur == '}') |
805 | ++dec->cur; |
862 | ++dec->cur; |
806 | else |
863 | else |
807 | for (;;) |
864 | for (;;) |
808 | { |
865 | { |
… | |
… | |
821 | { |
878 | { |
822 | SvREFCNT_dec (key); |
879 | SvREFCNT_dec (key); |
823 | goto fail; |
880 | goto fail; |
824 | } |
881 | } |
825 | |
882 | |
826 | //TODO: optimise |
|
|
827 | hv_store_ent (hv, key, value, 0); |
883 | hv_store_ent (hv, key, value, 0); |
|
|
884 | SvREFCNT_dec (key); |
828 | |
885 | |
829 | decode_ws (dec); |
886 | decode_ws (dec); |
830 | |
887 | |
831 | if (*dec->cur == '}') |
888 | if (*dec->cur == '}') |
832 | { |
889 | { |
… | |
… | |
838 | ERR (", or } expected while parsing object/hash"); |
895 | ERR (", or } expected while parsing object/hash"); |
839 | |
896 | |
840 | ++dec->cur; |
897 | ++dec->cur; |
841 | } |
898 | } |
842 | |
899 | |
|
|
900 | DEC_DEC_DEPTH; |
843 | return newRV_noinc ((SV *)hv); |
901 | return newRV_noinc ((SV *)hv); |
844 | |
902 | |
845 | fail: |
903 | fail: |
846 | SvREFCNT_dec (hv); |
904 | SvREFCNT_dec (hv); |
|
|
905 | DEC_DEC_DEPTH; |
847 | return 0; |
906 | return 0; |
848 | } |
907 | } |
849 | |
908 | |
850 | static SV * |
909 | static SV * |
851 | decode_sv (dec_t *dec) |
910 | decode_sv (dec_t *dec) |
… | |
… | |
903 | fail: |
962 | fail: |
904 | return 0; |
963 | return 0; |
905 | } |
964 | } |
906 | |
965 | |
907 | static SV * |
966 | static SV * |
908 | decode_json (SV *string, UV flags) |
967 | decode_json (SV *string, U32 flags) |
909 | { |
968 | { |
910 | SV *sv; |
969 | SV *sv; |
911 | |
970 | |
912 | if (flags & F_UTF8) |
971 | if (flags & F_UTF8) |
913 | sv_utf8_downgrade (string, 0); |
972 | sv_utf8_downgrade (string, 0); |
… | |
… | |
915 | sv_utf8_upgrade (string); |
974 | sv_utf8_upgrade (string); |
916 | |
975 | |
917 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
976 | SvGROW (string, SvCUR (string) + 1); // should basically be a NOP |
918 | |
977 | |
919 | dec_t dec; |
978 | dec_t dec; |
920 | dec.flags = flags; |
979 | dec.flags = flags; |
921 | dec.cur = SvPVX (string); |
980 | dec.cur = SvPVX (string); |
922 | dec.end = SvEND (string); |
981 | dec.end = SvEND (string); |
923 | dec.err = 0; |
982 | dec.err = 0; |
|
|
983 | dec.depth = 0; |
|
|
984 | dec.maxdepth = DEC_DEPTH (dec.flags); |
924 | |
985 | |
|
|
986 | *dec.end = 0; // this should basically be a nop, too, but make sure its there |
925 | sv = decode_sv (&dec); |
987 | sv = decode_sv (&dec); |
926 | |
988 | |
927 | if (!sv) |
989 | if (!sv) |
928 | { |
990 | { |
929 | IV offset = dec.flags & F_UTF8 |
991 | IV offset = dec.flags & F_UTF8 |
… | |
… | |
962 | BOOT: |
1024 | BOOT: |
963 | { |
1025 | { |
964 | int i; |
1026 | int i; |
965 | |
1027 | |
966 | memset (decode_hexdigit, 0xff, 256); |
1028 | memset (decode_hexdigit, 0xff, 256); |
|
|
1029 | |
967 | for (i = 10; i--; ) |
1030 | for (i = 0; i < 256; ++i) |
968 | decode_hexdigit ['0' + i] = i; |
1031 | decode_hexdigit [i] = |
969 | |
1032 | i >= '0' && i <= '9' ? i - '0' |
970 | for (i = 7; i--; ) |
1033 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
971 | { |
1034 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
972 | decode_hexdigit ['a' + i] = 10 + i; |
1035 | : -1; |
973 | decode_hexdigit ['A' + i] = 10 + i; |
|
|
974 | } |
|
|
975 | |
1036 | |
976 | json_stash = gv_stashpv ("JSON::XS", 1); |
1037 | json_stash = gv_stashpv ("JSON::XS", 1); |
977 | } |
1038 | } |
978 | |
1039 | |
979 | PROTOTYPES: DISABLE |
1040 | PROTOTYPES: DISABLE |
… | |
… | |
1006 | RETVAL = newSVsv (self); |
1067 | RETVAL = newSVsv (self); |
1007 | } |
1068 | } |
1008 | OUTPUT: |
1069 | OUTPUT: |
1009 | RETVAL |
1070 | RETVAL |
1010 | |
1071 | |
|
|
1072 | SV *max_depth (SV *self, int max_depth = 0x80000000UL) |
|
|
1073 | CODE: |
|
|
1074 | { |
|
|
1075 | UV *uv = SvJSON (self); |
|
|
1076 | UV log2 = 0; |
|
|
1077 | |
|
|
1078 | if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; |
|
|
1079 | |
|
|
1080 | while ((1UL << log2) < max_depth) |
|
|
1081 | ++log2; |
|
|
1082 | |
|
|
1083 | *uv = *uv & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); |
|
|
1084 | |
|
|
1085 | RETVAL = newSVsv (self); |
|
|
1086 | } |
|
|
1087 | OUTPUT: |
|
|
1088 | RETVAL |
|
|
1089 | |
1011 | void encode (SV *self, SV *scalar) |
1090 | void encode (SV *self, SV *scalar) |
1012 | PPCODE: |
1091 | PPCODE: |
1013 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1092 | XPUSHs (encode_json (scalar, *SvJSON (self))); |
1014 | |
1093 | |
1015 | void decode (SV *self, SV *jsonstr) |
1094 | void decode (SV *self, SV *jsonstr) |
… | |
… | |
1017 | XPUSHs (decode_json (jsonstr, *SvJSON (self))); |
1096 | XPUSHs (decode_json (jsonstr, *SvJSON (self))); |
1018 | |
1097 | |
1019 | PROTOTYPES: ENABLE |
1098 | PROTOTYPES: ENABLE |
1020 | |
1099 | |
1021 | void to_json (SV *scalar) |
1100 | void to_json (SV *scalar) |
|
|
1101 | ALIAS: |
|
|
1102 | objToJson = 0 |
1022 | PPCODE: |
1103 | PPCODE: |
1023 | XPUSHs (encode_json (scalar, F_UTF8)); |
1104 | XPUSHs (encode_json (scalar, F_DEFAULT | F_UTF8)); |
1024 | |
1105 | |
1025 | void from_json (SV *jsonstr) |
1106 | void from_json (SV *jsonstr) |
|
|
1107 | ALIAS: |
|
|
1108 | jsonToObj = 0 |
1026 | PPCODE: |
1109 | PPCODE: |
1027 | XPUSHs (decode_json (jsonstr, F_UTF8)); |
1110 | XPUSHs (decode_json (jsonstr, F_DEFAULT | F_UTF8)); |
1028 | |
1111 | |