X-Git-Url: http://git.shiar.nl/wormy.git/blobdiff_plain/aac9f02cab2d03379669c2f278d62330151d44e0..5f543f9395f3a885ee9b751e98d069b9ed54f885:/Parse/Binary/Nested.pm diff --git a/Parse/Binary/Nested.pm b/Parse/Binary/Nested.pm index 9bac394..872ccaa 100644 --- a/Parse/Binary/Nested.pm +++ b/Parse/Binary/Nested.pm @@ -5,7 +5,7 @@ use warnings; use Carp; -our $VERSION = '1.00'; +our $VERSION = '1.01'; sub new { my ($class, $format) = @_; @@ -26,6 +26,7 @@ sub template { : $count."X[$count]$count/($value)"; } else { + $value =~ s/=\d*//g; # hardcoded values $value =~ s/^C(a)(\d+)/$1 . ($2 + 1)/e; # length prefix } $value; @@ -53,6 +54,10 @@ sub convert { elsif ($template =~ /^(?:[xX]\d*)*$/) { next; # no values } + elsif ($template =~ /=(\d+)?/) { + $res{$field} = $1; + next; + } $res{$field} = shift @$data; } return \%res; @@ -117,6 +122,21 @@ to its length. This behaviour is very similar to C<(C/a@x$length)>, except that it never reads more than the given number of bytes. +=item * + +Hardcoded values can be inserted using C<=$number> values. +This can for example be useful to retain forwards-compatibility: + + rows => ['C', + type => '=1', # nothing read + data => 'S', + ] + + rows => ['C', + type => 'C', + data => 'S', + ] + =back =head1 AUTHOR