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.7 by root, Sat Oct 26 23:02:55 2013 UTC vs.
Revision 1.9 by root, Sun Oct 27 10:17:12 2013 UTC

8#include <stdio.h> 8#include <stdio.h>
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
14// known tags
15enum cbor_tag
16{
17 // inofficial extensions (pending iana registration)
18 CBOR_TAG_PERL_OBJECT = 256,
19 CBOR_TAG_GENERIC_OBJECT = 257,
20
21 // rfc7049
22 CBOR_TAG_DATETIME = 0, // rfc4287, utf-8
23 CBOR_TAG_TIMESTAMP = 1, // unix timestamp, any
24 CBOR_TAG_POS_BIGNUM = 2, // byte string
25 CBOR_TAG_NEG_BIGNUM = 3, // byte string
26 CBOR_TAG_DECIMAL = 4, // decimal fraction, array
27 CBOR_TAG_BIGFLOAT = 5, // array
28
29 CBOR_TAG_CONV_B64U = 21, // base64url, any
30 CBOR_TAG_CONV_B64 = 22, // base64, any
31 CBOR_TAG_CONV_HEX = 23, // base16, any
32 CBOR_TAG_CBOR = 24, // embedded cbor, byte string
33
34 CBOR_TAG_URI = 32, // URI rfc3986, utf-8
35 CBOR_TAG_B64U = 33, // base64url rfc4648, utf-8
36 CBOR_TAG_B64 = 34, // base6 rfc46484, utf-8
37 CBOR_TAG_REGEX = 35, // regex pcre/ecma262, utf-8
38 CBOR_TAG_MIME = 36, // mime message rfc2045, utf-8
39
40 CBOR_TAG_MAGIC = 55799 // self-describe cbor
41};
13 42
14#define F_SHRINK 0x00000200UL 43#define F_SHRINK 0x00000200UL
15#define F_ALLOW_UNKNOWN 0x00002000UL 44#define F_ALLOW_UNKNOWN 0x00002000UL
16 45
17#define INIT_SIZE 32 // initial scalar size to be allocated 46#define INIT_SIZE 32 // initial scalar size to be allocated
612decode_tagged (dec_t *dec) 641decode_tagged (dec_t *dec)
613{ 642{
614 UV tag = decode_uint (dec); 643 UV tag = decode_uint (dec);
615 SV *sv = decode_sv (dec); 644 SV *sv = decode_sv (dec);
616 645
617 if (tag == 55799) // 2.4.5 Self-Describe CBOR 646 if (tag == CBOR_TAG_MAGIC)
618 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 }
619 656
620 AV *av = newAV (); 657 AV *av = newAV ();
621 av_push (av, newSVuv (tag)); 658 av_push (av, newSVuv (tag));
622 av_push (av, sv); 659 av_push (av, sv);
623 660
624 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash 661 HV *tagged_stash = !CBOR_SLOW || cbor_tagged_stash
625 ? cbor_tagged_stash 662 ? cbor_tagged_stash
626 : gv_stashpv ("CBOR::XS::Tagged" , 1); 663 : gv_stashpv ("CBOR::XS::Tagged" , 1);
627 664
628 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;
629} 670}
630 671
631static SV * 672static SV *
632decode_sv (dec_t *dec) 673decode_sv (dec_t *dec)
633{ 674{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines