Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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