ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.8 by root, Sun Oct 27 10:12:01 2013 UTC vs.
Revision 1.9 by root, Sun Oct 27 10:17:12 2013 UTC

9#include <limits.h> 9#include <limits.h>
10#include <float.h> 10#include <float.h>
11 11
12#include "ecb.h" 12#include "ecb.h"
13 13
14// known tags, rfc7049 14// known tags
15enum cbor_tag 15enum cbor_tag
16{ 16{
17 // inofficial extensions (pending iana registration)
18 CBOR_TAG_PERL_OBJECT = 256,
19 CBOR_TAG_GENERIC_OBJECT = 257,
20
21 // rfc7049
17 CBOR_TAG_DATETIME = 0, // rfc4287, utf-8 22 CBOR_TAG_DATETIME = 0, // rfc4287, utf-8
18 CBOR_TAG_TIMESTAMP = 1, // unix timestamp, any 23 CBOR_TAG_TIMESTAMP = 1, // unix timestamp, any
19 CBOR_TAG_POS_BIGNUM = 2, // byte string 24 CBOR_TAG_POS_BIGNUM = 2, // byte string
20 CBOR_TAG_NEG_BIGNUM = 3, // byte string 25 CBOR_TAG_NEG_BIGNUM = 3, // byte string
21 CBOR_TAG_DECIMAL = 4, // decimal fraction, array 26 CBOR_TAG_DECIMAL = 4, // decimal fraction, array
22 CBOR_TAG_BIGFLOAT = 5, // array 27 CBOR_TAG_BIGFLOAT = 5, // array
23 28
24 CBOR_TAG_CONV_B64U = 21, // base64url, any 29 CBOR_TAG_CONV_B64U = 21, // base64url, any
25 CBOR_TAG_CONV_B64 = 22, // base64, any 30 CBOR_TAG_CONV_B64 = 22, // base64, any
26 CBOR_TAG_CONV_HEX = 23, // base16, any 31 CBOR_TAG_CONV_HEX = 23, // base16, any
27 CBOR_TAG_CBOR = 24, // embedded cbor, byte string 32 CBOR_TAG_CBOR = 24, // embedded cbor, byte string
28 33
29 CBOR_TAG_URI = 32, // URI rfc3986, utf-8 34 CBOR_TAG_URI = 32, // URI rfc3986, utf-8
30 CBOR_TAG_B64U = 33, // base64url rfc4648, utf-8 35 CBOR_TAG_B64U = 33, // base64url rfc4648, utf-8
31 CBOR_TAG_B64 = 34, // base6 rfc46484, utf-8 36 CBOR_TAG_B64 = 34, // base6 rfc46484, utf-8
32 CBOR_TAG_REGEX = 35, // regex pcre/ecma262, utf-8 37 CBOR_TAG_REGEX = 35, // regex pcre/ecma262, utf-8
33 CBOR_TAG_MIME = 36, // mime message rfc2045, utf-8 38 CBOR_TAG_MIME = 36, // mime message rfc2045, utf-8
34 39
35 CBOR_TAG_MAGIC = 55799 40 CBOR_TAG_MAGIC = 55799 // self-describe cbor
36}; 41};
37 42
38#define F_SHRINK 0x00000200UL 43#define F_SHRINK 0x00000200UL
39#define F_ALLOW_UNKNOWN 0x00002000UL 44#define F_ALLOW_UNKNOWN 0x00002000UL
40 45
636decode_tagged (dec_t *dec) 641decode_tagged (dec_t *dec)
637{ 642{
638 UV tag = decode_uint (dec); 643 UV tag = decode_uint (dec);
639 SV *sv = decode_sv (dec); 644 SV *sv = decode_sv (dec);
640 645
641 if (tag == CBOR_TAG_MAGIC) // 2.4.5 Self-Describe CBOR 646 if (tag == CBOR_TAG_MAGIC)
642 return sv; 647 return sv;
648
649 if (tag == CBOR_TAG_PERL_OBJECT)
650 {
651 if (!SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
652 ERR ("corrupted CBOR data (non-array perl object)");
653
654 // TODO
655 }
643 656
644 AV *av = newAV (); 657 AV *av = newAV ();
645 av_push (av, newSVuv (tag)); 658 av_push (av, newSVuv (tag));
646 av_push (av, sv); 659 av_push (av, sv);
647 660
648 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 661 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
649 ? cbor_tagged_stash 662 ? cbor_tagged_stash
650 : gv_stashpv ("CBOR::XS::Tagged" , 1); 663 : gv_stashpv ("CBOR::XS::Tagged" , 1);
651 664
652 return sv_bless (newRV_noinc ((SV *)av), tagged_stash); 665 return sv_bless (newRV_noinc ((SV *)av), tagged_stash);
666
667fail:
668 SvREFCNT_dec (sv);
669 return &PL_sv_undef;
653} 670}
654 671
655static SV * 672static SV *
656decode_sv (dec_t *dec) 673decode_sv (dec_t *dec)
657{ 674{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines