sub run_callbacks($$$) {
my ($coder, $cbs, $msg) = @_;
- return if (0 ne index $msg, $MESSAGE_START);
- $msg = substr($msg, length $MESSAGE_START);
+ my $regex = "^$MESSAGE_START(["
+ . (join ("",@{$$coder{'code_chars'}}))
+ ."]+)$MESSAGE_END(.*)\$";
+
+ my $rest;
+ # Note how this regex works: it will greedily consume into
+ # what we think is the message, and may have to backtrack out
+ # to find MESSAGE_END. It will never prematurely terminate
+ # the encoded message if it sees MESSAGE_END inside the message.
+ if ( $msg =~ /$regex/ ) {
+ $msg = $1;
+ $rest = $2;
+ } else {
+ return (0, $msg);
+ }
while( $msg ne "" )
{
}
}
- return $msg eq "";
+ return ($msg eq "", $rest);
}
sub dump_message($$) {
print "ENCODED '", $ts, "' into hc ", $enc, " and tlv ", $tlv, "\n";
}
-my $mesg = tlvs_to_message(\@tlvs);
+my $mesg_suffix = "This is some normal text.";
+my $mesg = tlvs_to_message(\@tlvs) . $mesg_suffix;
dump_message($mc, $mesg);
die "Unanticipated message of type $t: $v";
}
-run_callbacks($mc,
+my ($res, $rest) = run_callbacks($mc,
{ 'default' => \&def_cb,
$known_types{'InstanceLabelHuffman1'} => \&ilf_cb,
},
$mesg );
+
+die unless $res eq 1;
+die unless $rest eq $mesg_suffix;