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.44 by root, Tue Feb 18 22:12:12 2014 UTC vs.
Revision 1.49 by root, Mon Feb 8 04:11:11 2016 UTC

324 324
325 ++enc->depth; 325 ++enc->depth;
326 326
327 encode_uint (enc, MAJOR_ARRAY, len + 1); 327 encode_uint (enc, MAJOR_ARRAY, len + 1);
328 328
329 if (SvMAGICAL (av))
329 for (i = 0; i <= len; ++i) 330 for (i = 0; i <= len; ++i)
330 { 331 {
331 SV **svp = av_fetch (av, i, 0); 332 SV **svp = av_fetch (av, i, 0);
332 encode_sv (enc, svp ? *svp : &PL_sv_undef); 333 encode_sv (enc, svp ? *svp : &PL_sv_undef);
333 } 334 }
335 else
336 for (i = 0; i <= len; ++i)
337 {
338 SV *sv = AvARRAY (av)[i];
339 encode_sv (enc, sv ? sv : &PL_sv_undef);
340 }
334 341
335 --enc->depth; 342 --enc->depth;
336} 343}
337 344
338static void 345static void
577} 584}
578 585
579static SV * 586static SV *
580encode_cbor (SV *scalar, CBOR *cbor) 587encode_cbor (SV *scalar, CBOR *cbor)
581{ 588{
582 enc_t enc = { }; 589 enc_t enc = { 0 };
583 590
584 enc.cbor = *cbor; 591 enc.cbor = *cbor;
585 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 592 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
586 enc.cur = SvPVX (enc.sv); 593 enc.cur = SvPVX (enc.sv);
587 enc.end = SvEND (enc.sv); 594 enc.end = SvEND (enc.sv);
742 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) 749 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8))
743 { 750 {
744 I32 len = decode_uint (dec); 751 I32 len = decode_uint (dec);
745 char *key = (char *)dec->cur; 752 char *key = (char *)dec->cur;
746 753
754 WANT (len);
747 dec->cur += len; 755 dec->cur += len;
748 756
749 hv_store (hv, key, len, decode_sv (dec), 0); 757 hv_store (hv, key, len, decode_sv (dec), 0);
750 758
751 return; 759 return;
752 } 760 }
753 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) 761 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8))
754 { 762 {
755 I32 len = decode_uint (dec); 763 I32 len = decode_uint (dec);
756 char *key = (char *)dec->cur; 764 char *key = (char *)dec->cur;
757 765
766 WANT (len);
758 dec->cur += len; 767 dec->cur += len;
759 768
760 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) 769 if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8))
761 if (!is_utf8_string (key, len)) 770 if (!is_utf8_string (key, len))
762 ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); 771 ERR ("corrupted CBOR data (invalid UTF-8 in map key)");
1156} 1165}
1157 1166
1158static SV * 1167static SV *
1159decode_cbor (SV *string, CBOR *cbor, char **offset_return) 1168decode_cbor (SV *string, CBOR *cbor, char **offset_return)
1160{ 1169{
1161 dec_t dec = { }; 1170 dec_t dec = { 0 };
1162 SV *sv; 1171 SV *sv;
1163 STRLEN len; 1172 STRLEN len;
1164 char *data = SvPVbyte (string, len); 1173 char *data = SvPVbyte (string, len);
1165 1174
1166 if (len > cbor->max_size && cbor->max_size) 1175 if (len > cbor->max_size && cbor->max_size)
1257 1266
1258 int major = *p >> MAJOR_SHIFT; 1267 int major = *p >> MAJOR_SHIFT;
1259 1268
1260 switch (major) 1269 switch (major)
1261 { 1270 {
1271 case MAJOR_TAG >> MAJOR_SHIFT:
1272 ++count; // tags merely prefix another value
1273 break;
1274
1262 case MAJOR_BYTES >> MAJOR_SHIFT: 1275 case MAJOR_BYTES >> MAJOR_SHIFT:
1263 case MAJOR_TEXT >> MAJOR_SHIFT: 1276 case MAJOR_TEXT >> MAJOR_SHIFT:
1264 case MAJOR_ARRAY >> MAJOR_SHIFT: 1277 case MAJOR_ARRAY >> MAJOR_SHIFT:
1265 case MAJOR_MAP >> MAJOR_SHIFT: 1278 case MAJOR_MAP >> MAJOR_SHIFT:
1266 { 1279 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines