Skip to content
Permalink
Browse files

Add initial implementation of write-int128

Which I didn't have time yet to do.
  • Loading branch information...
lizmat committed Dec 15, 2018
1 parent 79dd1c8 commit ceaf7218fc96543420729cb86dc6ba7b02c5c48a
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/core/Buf.pm6
@@ -671,6 +671,18 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
nqp::writeint(self,$offset,$value,
nqp::bitor_i(BINARY_SIZE_64_BIT,$endian))
}
method write-int128(::?ROLE:D:
int $offset, Int $value, Endian $endian = NativeEndian --> Nil
) is raw {
# These uints are intentional to keep the value within 64 bits
my uint $first = ($value +> 64) +& (1 +< 64 - 1);
my uint $second = $value +& (1 +< 64 - 1);
my $be = $endian == BigEndian
|| ($endian == NativeEndian && Kernel.endian == BigEndian);

self.write-int64($offset, $be ?? $first !! $second, $endian);
self.write-int64($offset + 8, $be ?? $second !! $first, $endian);
}
method write-uint8(::?ROLE:D:
int $offset, uint8 $value, Endian $endian = NativeEndian --> Nil
) is raw {

0 comments on commit ceaf721

Please sign in to comment.
You can’t perform that action at this time.