Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Data::Dumper;
  5. use Data::Hexdumper qw(hexdump);
  6. use bytes;
  7.  
  8.  
  9. sub _encode {
  10. my $arry = shift;
  11. my $bigblob = "";
  12. foreach my $i (0..$#{$arry}) {
  13. next unless defined $arry->[$i];
  14. my $elen = @{$arry->[$i]};
  15. next unless $elen;
  16. my $blob = pack ("C C/l", $i, @{$arry->[$i]});
  17. $bigblob .= $blob;
  18. }
  19. return $bigblob;
  20. }
  21.  
  22.  
  23. sub _decode {
  24. my $blob = shift;
  25. print hexdump($blob) . "\n";
  26. my @ret;
  27.  
  28.  
  29. my (@blobs) = unpack("C C/l a*", $blob);
  30. print hexdump($_) . "\n\n" foreach @blobs;
  31. while ($blob = pop @blobs) {
  32. print "----------------------\n";
  33. print hexdump($blob);
  34. my ($id,@values) = unpack("C C/l", $blob);
  35. $ret[$id] = \@values;
  36. print "ID: $id";
  37. print " Values:" , join(",", @values);
  38. print "\n";
  39. }
  40. return \@ret;
  41. }
  42.  
  43. my $DATA = [
  44. #1:
  45. [1,2,3],
  46. [10,9,8],
  47. [42]
  48. ];
  49.  
  50. print Dumper($DATA);
  51. print Dumper _decode(_encode($DATA));
Add Comment
Please, Sign In to add comment