Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Created May 27, 2016 09:17
Show Gist options
  • Select an option

  • Save ab5tract/1835272892d9ee58cdfb0a1bcd34e5c7 to your computer and use it in GitHub Desktop.

Select an option

Save ab5tract/1835272892d9ee58cdfb0a1bcd34e5c7 to your computer and use it in GitHub Desktop.
a generic buf eater
my class Reader {
my $.pos is rw = 0;
my $.buf;
method read(Buf $buf) {
...
}
method read-type(Any:U: $type) {
my $width = nativesizeof($type);
my $value = $!buf.subbuf($!pos, %type-widths{$type.perl});
$!pos += $width;
return $value; # cast, but how?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment