43
# This section deals with extracting constants from the protocol
44
# definition and including them as Perl constants. Not pretty, I know.
45
# Regenerate constants if module available.
46
43
sub generate_constant_includes {
47
my $namespace = shift;
48
my $constant_namespace = $namespace . "::Constants";
49
my $file = $constant_namespace;
55
if (eval { use ExtUtils::Constant qw(WriteConstants); 1 }) {
58
$fragment =~ s/(?:En|De)coder\/?$//;
59
File::Path::mkpath($fragment);
60
print "Generating constant exports for Perl...\n";
61
open my $fh, "<", "srl_protocol.h" or die $!;
62
my (@string_const, @int_const);
64
if (/^#\s*define\s*(SRL_\w+)\s*(.*?)(?:\/\*|$)/) {
65
my ($name, $value) = ($1, $2);
66
next if $name =~ /_H_$/ or $name =~ /SET/ or $value =~ /"/;
67
push @int_const, $name;
72
NAME => $constant_namespace,
75
open my $ofh, ">", $file or die $!;
77
# Genereated code! Do not modify! See inc/Sereal/BuildTools.pm instead
79
package $constant_namespace;
83
use $namespace; our \$VERSION= \$$namespace\::VERSION; # for XSLoading
84
our \@ISA = qw(Exporter);
87
BEGIN { \@EXPORT_OK = qw(
89
print $ofh " $_\n" for (@int_const);
93
foreach my $constname (@EXPORT_OK) {
94
my ($error, $val) = constant($constname);
95
if ($error) { croak($error); }
96
$code .= "sub $constname () {$val}\n";
98
eval "$code\n1;" or do {
99
my $err = $@ || 'Zombie error';
100
die "Failed to generate constant subs: $err\n Code was:\n$code\n";
104
sub SRL_MAGIC_STRING () { "=srl" }
105
sub SRL_MAGIC_STRING_HIGHBIT () { "=\xF3rl" }
106
sub SRL_MAGIC_STRING_HIGHBIT_UTF8 () { "=\xC3\xB3rl" }
110
SRL_MAGIC_STRING_HIGHBIT
111
SRL_MAGIC_STRING_HIGHBIT_UTF8
114
# start autoupdated section - do not modify directly
116
our (%TAG_INFO_HASH, @TAG_INFO_ARRAY);
118
# autoupdated by author_tools/update_from_header.pl do not modify directly!
120
'type_name' => 'POS',
122
'comment' => 'small positive integer - value in low 4 bits (identity)',
128
# autoupdated by author_tools/update_from_header.pl do not modify directly!
130
'type_name' => 'POS',
137
# autoupdated by author_tools/update_from_header.pl do not modify directly!
139
'type_name' => 'POS',
146
# autoupdated by author_tools/update_from_header.pl do not modify directly!
148
'type_name' => 'POS',
155
# autoupdated by author_tools/update_from_header.pl do not modify directly!
157
'type_name' => 'POS',
164
# autoupdated by author_tools/update_from_header.pl do not modify directly!
166
'type_name' => 'POS',
173
# autoupdated by author_tools/update_from_header.pl do not modify directly!
175
'type_name' => 'POS',
182
# autoupdated by author_tools/update_from_header.pl do not modify directly!
184
'type_name' => 'POS',
191
# autoupdated by author_tools/update_from_header.pl do not modify directly!
193
'type_name' => 'POS',
200
# autoupdated by author_tools/update_from_header.pl do not modify directly!
202
'type_name' => 'POS',
209
# autoupdated by author_tools/update_from_header.pl do not modify directly!
211
'type_name' => 'POS',
218
# autoupdated by author_tools/update_from_header.pl do not modify directly!
220
'type_name' => 'POS',
227
# autoupdated by author_tools/update_from_header.pl do not modify directly!
229
'type_name' => 'POS',
236
# autoupdated by author_tools/update_from_header.pl do not modify directly!
238
'type_name' => 'POS',
245
# autoupdated by author_tools/update_from_header.pl do not modify directly!
247
'type_name' => 'POS',
254
# autoupdated by author_tools/update_from_header.pl do not modify directly!
256
'type_name' => 'POS',
258
'comment' => 'small positive integer - value in low 4 bits (identity)',
264
# autoupdated by author_tools/update_from_header.pl do not modify directly!
266
'type_name' => 'NEG',
268
'comment' => 'small negative integer - value in low 4 bits (k+32)',
274
# autoupdated by author_tools/update_from_header.pl do not modify directly!
276
'type_name' => 'NEG',
283
# autoupdated by author_tools/update_from_header.pl do not modify directly!
285
'type_name' => 'NEG',
292
# autoupdated by author_tools/update_from_header.pl do not modify directly!
294
'type_name' => 'NEG',
301
# autoupdated by author_tools/update_from_header.pl do not modify directly!
303
'type_name' => 'NEG',
310
# autoupdated by author_tools/update_from_header.pl do not modify directly!
312
'type_name' => 'NEG',
319
# autoupdated by author_tools/update_from_header.pl do not modify directly!
321
'type_name' => 'NEG',
328
# autoupdated by author_tools/update_from_header.pl do not modify directly!
330
'type_name' => 'NEG',
337
# autoupdated by author_tools/update_from_header.pl do not modify directly!
339
'type_name' => 'NEG',
346
# autoupdated by author_tools/update_from_header.pl do not modify directly!
348
'type_name' => 'NEG',
355
# autoupdated by author_tools/update_from_header.pl do not modify directly!
357
'type_name' => 'NEG',
364
# autoupdated by author_tools/update_from_header.pl do not modify directly!
366
'type_name' => 'NEG',
373
# autoupdated by author_tools/update_from_header.pl do not modify directly!
375
'type_name' => 'NEG',
382
# autoupdated by author_tools/update_from_header.pl do not modify directly!
384
'type_name' => 'NEG',
391
# autoupdated by author_tools/update_from_header.pl do not modify directly!
393
'type_name' => 'NEG',
400
# autoupdated by author_tools/update_from_header.pl do not modify directly!
402
'type_name' => 'NEG',
404
'comment' => 'small negative integer - value in low 4 bits (k+32)',
410
# autoupdated by author_tools/update_from_header.pl do not modify directly!
412
'type_name' => 'VARINT',
413
'comment' => '<VARINT> - Varint variable length integer',
418
# autoupdated by author_tools/update_from_header.pl do not modify directly!
420
'type_name' => 'ZIGZAG',
421
'comment' => '<ZIGZAG-VARINT> - Zigzag variable length integer',
426
# autoupdated by author_tools/update_from_header.pl do not modify directly!
428
'type_name' => 'FLOAT',
429
'comment' => '<IEEE-FLOAT>',
434
# autoupdated by author_tools/update_from_header.pl do not modify directly!
436
'type_name' => 'DOUBLE',
437
'comment' => '<IEEE-DOUBLE>',
442
# autoupdated by author_tools/update_from_header.pl do not modify directly!
444
'type_name' => 'LONG_DOUBLE',
445
'comment' => '<IEEE-LONG-DOUBLE>',
447
'name' => 'LONG_DOUBLE',
450
# autoupdated by author_tools/update_from_header.pl do not modify directly!
452
'type_name' => 'UNDEF',
453
'comment' => 'None - Perl undef var; eg my $var= undef;',
458
# autoupdated by author_tools/update_from_header.pl do not modify directly!
460
'type_name' => 'BINARY',
461
'comment' => '<LEN-VARINT> <BYTES> - binary/(latin1) string',
466
# autoupdated by author_tools/update_from_header.pl do not modify directly!
468
'type_name' => 'STR_UTF8',
469
'comment' => '<LEN-VARINT> <UTF8> - utf8 string',
471
'name' => 'STR_UTF8',
474
# autoupdated by author_tools/update_from_header.pl do not modify directly!
476
'type_name' => 'REFN',
477
'comment' => '<ITEM-TAG> - ref to next item',
482
# autoupdated by author_tools/update_from_header.pl do not modify directly!
484
'type_name' => 'REFP',
485
'comment' => '<OFFSET-VARINT> - ref to previous item stored at offset',
490
# autoupdated by author_tools/update_from_header.pl do not modify directly!
492
'type_name' => 'HASH',
493
'comment' => '<COUNT-VARINT> [<KEY-TAG> <ITEM-TAG> ...] - count followed by key/value pairs',
498
# autoupdated by author_tools/update_from_header.pl do not modify directly!
500
'type_name' => 'ARRAY',
501
'comment' => '<COUNT-VARINT> [<ITEM-TAG> ...] - count followed by items',
506
# autoupdated by author_tools/update_from_header.pl do not modify directly!
508
'type_name' => 'OBJECT',
509
'comment' => '<STR-TAG> <ITEM-TAG> - class, object-item',
514
# autoupdated by author_tools/update_from_header.pl do not modify directly!
516
'type_name' => 'OBJECTV',
517
'comment' => '<OFFSET-VARINT> <ITEM-TAG> - offset of previously used classname tag - object-item',
522
# autoupdated by author_tools/update_from_header.pl do not modify directly!
524
'type_name' => 'ALIAS',
525
'comment' => '<OFFSET-VARINT> - alias to item defined at offset',
530
# autoupdated by author_tools/update_from_header.pl do not modify directly!
532
'type_name' => 'COPY',
533
'comment' => '<OFFSET-VARINT> - copy of item defined at offset',
538
# autoupdated by author_tools/update_from_header.pl do not modify directly!
540
'type_name' => 'WEAKEN',
541
'comment' => '<REF-TAG> - Weaken the following reference',
546
# autoupdated by author_tools/update_from_header.pl do not modify directly!
548
'type_name' => 'REGEXP',
549
'comment' => '<PATTERN-STR-TAG> <MODIFIERS-STR-TAG>',
554
# autoupdated by author_tools/update_from_header.pl do not modify directly!
556
'type_name' => 'OBJECT_FREEZE',
557
'comment' => '<STR-TAG> <ITEM-TAG> - class, object-item. Need to call "THAW" method on class after decoding',
559
'name' => 'OBJECT_FREEZE',
562
# autoupdated by author_tools/update_from_header.pl do not modify directly!
564
'type_name' => 'OBJECTV_FREEZE',
565
'comment' => '<OFFSET-VARINT> <ITEM-TAG> - (OBJECTV_FREEZE is to OBJECT_FREEZE as OBJECTV is to OBJECT)',
567
'name' => 'OBJECTV_FREEZE',
570
# autoupdated by author_tools/update_from_header.pl do not modify directly!
572
'type_name' => 'RESERVED',
574
'comment' => 'reserved',
576
'name' => 'RESERVED_0',
580
# autoupdated by author_tools/update_from_header.pl do not modify directly!
582
'type_name' => 'RESERVED',
585
'name' => 'RESERVED_1',
589
# autoupdated by author_tools/update_from_header.pl do not modify directly!
591
'type_name' => 'RESERVED',
594
'name' => 'RESERVED_2',
598
# autoupdated by author_tools/update_from_header.pl do not modify directly!
600
'type_name' => 'RESERVED',
603
'name' => 'RESERVED_3',
607
# autoupdated by author_tools/update_from_header.pl do not modify directly!
609
'type_name' => 'RESERVED',
612
'name' => 'RESERVED_4',
616
# autoupdated by author_tools/update_from_header.pl do not modify directly!
618
'type_name' => 'CANONICAL_UNDEF',
619
'comment' => 'undef (PL_sv_undef) - "the" Perl undef (see notes)',
621
'name' => 'CANONICAL_UNDEF',
624
# autoupdated by author_tools/update_from_header.pl do not modify directly!
626
'type_name' => 'FALSE',
627
'comment' => 'false (PL_sv_no)',
632
# autoupdated by author_tools/update_from_header.pl do not modify directly!
634
'type_name' => 'TRUE',
635
'comment' => 'true (PL_sv_yes)',
640
# autoupdated by author_tools/update_from_header.pl do not modify directly!
642
'type_name' => 'MANY',
643
'comment' => '<LEN-VARINT> <TYPE-BYTE> <TAG-DATA> - repeated tag (not done yet, will be implemented in version 3)',
648
# autoupdated by author_tools/update_from_header.pl do not modify directly!
650
'type_name' => 'PACKET_START',
651
'comment' => '(first byte of magic string in header)',
653
'name' => 'PACKET_START',
656
# autoupdated by author_tools/update_from_header.pl do not modify directly!
658
'type_name' => 'EXTEND',
659
'comment' => '<BYTE> - for additional tags',
664
# autoupdated by author_tools/update_from_header.pl do not modify directly!
666
'type_name' => 'PAD',
667
'comment' => '(ignored tag, skip to next byte)',
672
# autoupdated by author_tools/update_from_header.pl do not modify directly!
674
'type_name' => 'ARRAYREF',
676
'comment' => '[<ITEM-TAG> ...] - count of items in low 4 bits (ARRAY must be refcnt=1)',
678
'name' => 'ARRAYREF_0',
682
# autoupdated by author_tools/update_from_header.pl do not modify directly!
684
'type_name' => 'ARRAYREF',
687
'name' => 'ARRAYREF_1',
691
# autoupdated by author_tools/update_from_header.pl do not modify directly!
693
'type_name' => 'ARRAYREF',
696
'name' => 'ARRAYREF_2',
700
# autoupdated by author_tools/update_from_header.pl do not modify directly!
702
'type_name' => 'ARRAYREF',
705
'name' => 'ARRAYREF_3',
709
# autoupdated by author_tools/update_from_header.pl do not modify directly!
711
'type_name' => 'ARRAYREF',
714
'name' => 'ARRAYREF_4',
718
# autoupdated by author_tools/update_from_header.pl do not modify directly!
720
'type_name' => 'ARRAYREF',
723
'name' => 'ARRAYREF_5',
727
# autoupdated by author_tools/update_from_header.pl do not modify directly!
729
'type_name' => 'ARRAYREF',
732
'name' => 'ARRAYREF_6',
736
# autoupdated by author_tools/update_from_header.pl do not modify directly!
738
'type_name' => 'ARRAYREF',
741
'name' => 'ARRAYREF_7',
745
# autoupdated by author_tools/update_from_header.pl do not modify directly!
747
'type_name' => 'ARRAYREF',
750
'name' => 'ARRAYREF_8',
754
# autoupdated by author_tools/update_from_header.pl do not modify directly!
756
'type_name' => 'ARRAYREF',
759
'name' => 'ARRAYREF_9',
763
# autoupdated by author_tools/update_from_header.pl do not modify directly!
765
'type_name' => 'ARRAYREF',
768
'name' => 'ARRAYREF_10',
772
# autoupdated by author_tools/update_from_header.pl do not modify directly!
774
'type_name' => 'ARRAYREF',
777
'name' => 'ARRAYREF_11',
781
# autoupdated by author_tools/update_from_header.pl do not modify directly!
783
'type_name' => 'ARRAYREF',
786
'name' => 'ARRAYREF_12',
790
# autoupdated by author_tools/update_from_header.pl do not modify directly!
792
'type_name' => 'ARRAYREF',
795
'name' => 'ARRAYREF_13',
799
# autoupdated by author_tools/update_from_header.pl do not modify directly!
801
'type_name' => 'ARRAYREF',
804
'name' => 'ARRAYREF_14',
808
# autoupdated by author_tools/update_from_header.pl do not modify directly!
810
'type_name' => 'ARRAYREF',
813
'name' => 'ARRAYREF_15',
817
# autoupdated by author_tools/update_from_header.pl do not modify directly!
819
'type_name' => 'HASHREF',
821
'comment' => '[<KEY-TAG> <ITEM-TAG> ...] - count in low 4 bits, key/value pairs (HASH must be refcnt=1)',
823
'name' => 'HASHREF_0',
827
# autoupdated by author_tools/update_from_header.pl do not modify directly!
829
'type_name' => 'HASHREF',
832
'name' => 'HASHREF_1',
836
# autoupdated by author_tools/update_from_header.pl do not modify directly!
838
'type_name' => 'HASHREF',
841
'name' => 'HASHREF_2',
845
# autoupdated by author_tools/update_from_header.pl do not modify directly!
847
'type_name' => 'HASHREF',
850
'name' => 'HASHREF_3',
854
# autoupdated by author_tools/update_from_header.pl do not modify directly!
856
'type_name' => 'HASHREF',
859
'name' => 'HASHREF_4',
863
# autoupdated by author_tools/update_from_header.pl do not modify directly!
865
'type_name' => 'HASHREF',
868
'name' => 'HASHREF_5',
872
# autoupdated by author_tools/update_from_header.pl do not modify directly!
874
'type_name' => 'HASHREF',
877
'name' => 'HASHREF_6',
881
# autoupdated by author_tools/update_from_header.pl do not modify directly!
883
'type_name' => 'HASHREF',
886
'name' => 'HASHREF_7',
890
# autoupdated by author_tools/update_from_header.pl do not modify directly!
892
'type_name' => 'HASHREF',
895
'name' => 'HASHREF_8',
899
# autoupdated by author_tools/update_from_header.pl do not modify directly!
901
'type_name' => 'HASHREF',
904
'name' => 'HASHREF_9',
908
# autoupdated by author_tools/update_from_header.pl do not modify directly!
910
'type_name' => 'HASHREF',
913
'name' => 'HASHREF_10',
917
# autoupdated by author_tools/update_from_header.pl do not modify directly!
919
'type_name' => 'HASHREF',
922
'name' => 'HASHREF_11',
926
# autoupdated by author_tools/update_from_header.pl do not modify directly!
928
'type_name' => 'HASHREF',
931
'name' => 'HASHREF_12',
935
# autoupdated by author_tools/update_from_header.pl do not modify directly!
937
'type_name' => 'HASHREF',
940
'name' => 'HASHREF_13',
944
# autoupdated by author_tools/update_from_header.pl do not modify directly!
946
'type_name' => 'HASHREF',
949
'name' => 'HASHREF_14',
953
# autoupdated by author_tools/update_from_header.pl do not modify directly!
955
'type_name' => 'HASHREF',
958
'name' => 'HASHREF_15',
962
# autoupdated by author_tools/update_from_header.pl do not modify directly!
964
'type_name' => 'SHORT_BINARY',
966
'comment' => '<BYTES> - binary/latin1 string, length encoded in low 5 bits of tag',
968
'name' => 'SHORT_BINARY_0',
972
# autoupdated by author_tools/update_from_header.pl do not modify directly!
974
'type_name' => 'SHORT_BINARY',
977
'name' => 'SHORT_BINARY_1',
981
# autoupdated by author_tools/update_from_header.pl do not modify directly!
983
'type_name' => 'SHORT_BINARY',
986
'name' => 'SHORT_BINARY_2',
990
# autoupdated by author_tools/update_from_header.pl do not modify directly!
992
'type_name' => 'SHORT_BINARY',
995
'name' => 'SHORT_BINARY_3',
999
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1001
'type_name' => 'SHORT_BINARY',
1004
'name' => 'SHORT_BINARY_4',
1008
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1010
'type_name' => 'SHORT_BINARY',
1013
'name' => 'SHORT_BINARY_5',
1017
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1019
'type_name' => 'SHORT_BINARY',
1022
'name' => 'SHORT_BINARY_6',
1026
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1028
'type_name' => 'SHORT_BINARY',
1031
'name' => 'SHORT_BINARY_7',
1035
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1037
'type_name' => 'SHORT_BINARY',
1040
'name' => 'SHORT_BINARY_8',
1044
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1046
'type_name' => 'SHORT_BINARY',
1049
'name' => 'SHORT_BINARY_9',
1053
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1055
'type_name' => 'SHORT_BINARY',
1058
'name' => 'SHORT_BINARY_10',
1062
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1064
'type_name' => 'SHORT_BINARY',
1067
'name' => 'SHORT_BINARY_11',
1071
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1073
'type_name' => 'SHORT_BINARY',
1076
'name' => 'SHORT_BINARY_12',
1080
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1082
'type_name' => 'SHORT_BINARY',
1085
'name' => 'SHORT_BINARY_13',
1089
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1091
'type_name' => 'SHORT_BINARY',
1094
'name' => 'SHORT_BINARY_14',
1098
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1100
'type_name' => 'SHORT_BINARY',
1103
'name' => 'SHORT_BINARY_15',
1107
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1109
'type_name' => 'SHORT_BINARY',
1112
'name' => 'SHORT_BINARY_16',
1116
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1118
'type_name' => 'SHORT_BINARY',
1121
'name' => 'SHORT_BINARY_17',
1125
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1127
'type_name' => 'SHORT_BINARY',
1130
'name' => 'SHORT_BINARY_18',
1134
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1136
'type_name' => 'SHORT_BINARY',
1139
'name' => 'SHORT_BINARY_19',
1143
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1145
'type_name' => 'SHORT_BINARY',
1148
'name' => 'SHORT_BINARY_20',
1152
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1154
'type_name' => 'SHORT_BINARY',
1157
'name' => 'SHORT_BINARY_21',
1161
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1163
'type_name' => 'SHORT_BINARY',
1166
'name' => 'SHORT_BINARY_22',
1170
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1172
'type_name' => 'SHORT_BINARY',
1175
'name' => 'SHORT_BINARY_23',
1179
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1181
'type_name' => 'SHORT_BINARY',
1184
'name' => 'SHORT_BINARY_24',
1188
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1190
'type_name' => 'SHORT_BINARY',
1193
'name' => 'SHORT_BINARY_25',
1197
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1199
'type_name' => 'SHORT_BINARY',
1202
'name' => 'SHORT_BINARY_26',
1206
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1208
'type_name' => 'SHORT_BINARY',
1211
'name' => 'SHORT_BINARY_27',
1215
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1217
'type_name' => 'SHORT_BINARY',
1220
'name' => 'SHORT_BINARY_28',
1224
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1226
'type_name' => 'SHORT_BINARY',
1229
'name' => 'SHORT_BINARY_29',
1233
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1235
'type_name' => 'SHORT_BINARY',
1238
'name' => 'SHORT_BINARY_30',
1242
# autoupdated by author_tools/update_from_header.pl do not modify directly!
1244
'type_name' => 'SHORT_BINARY',
1247
'name' => 'SHORT_BINARY_31',
1252
$TAG_INFO_HASH{chr $_}= $TAG_INFO_ARRAY[$_] for 0 .. 127;
1253
push @EXPORT_OK, qw(%TAG_INFO_HASH @TAG_INFO_ARRAY);
1255
# stop autoupdated section - do not modify directly!
1258
our %EXPORT_TAGS=(all => \@EXPORT_OK);
1263
warn "Please install ExtUtils::Constant since you appear to be running out of the source repository.\n";
1267
47
# Prefer external csnappy and miniz libraries over the bundled ones.