Created
May 27, 2016 09:17
-
-
Save ab5tract/1835272892d9ee58cdfb0a1bcd34e5c7 to your computer and use it in GitHub Desktop.
a generic buf eater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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