{-# language BangPatterns #-}
{-# language BinaryLiterals #-}
{-# language DataKinds #-}
{-# language KindSignatures #-}
{-# language LambdaCase #-}
{-# language MagicHash #-}
{-# language RankNTypes #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeOperators #-}
{-# language UnboxedTuples #-}
{-# language UnliftedFFITypes #-}
module Data.Bytes.Builder.Bounded
(
Builder
, run
, runByteString
, pasteGrowST
, empty
, append
, weaken
, substitute
, word64Dec
, word32Dec
, word16Dec
, word8Dec
, wordDec
, int64Dec
, int32Dec
, int16Dec
, int8Dec
, intDec
, word128PaddedLowerHex
, word128PaddedUpperHex
, word256PaddedLowerHex
, word256PaddedUpperHex
, word64PaddedLowerHex
, word64PaddedUpperHex
, word48PaddedLowerHex
, word32PaddedLowerHex
, word32PaddedUpperHex
, word16PaddedLowerHex
, word16PaddedUpperHex
, word16LowerHex
, word16UpperHex
, word8PaddedLowerHex
, word8PaddedUpperHex
, word8LowerHex
, ascii
, ascii2
, ascii3
, ascii4
, ascii5
, ascii6
, ascii7
, ascii8
, char
, wordPaddedDec2
, wordPaddedDec4
, wordPaddedDec9
, word8
, word256BE
, word128BE
, word64BE
, word32BE
, word16BE
, int64BE
, int32BE
, int16BE
, word256LE
, word128LE
, word64LE
, word32LE
, word16LE
, int64LE
, int32LE
, int16LE
, wordLEB128
, word32LEB128
, word64LEB128
, doubleDec
) where
import Arithmetic.Types (type (<=), type (:=:))
import Control.Monad.Primitive (primitive_)
import Control.Monad.ST (ST)
import Control.Monad.ST.Run (runByteArrayST,runIntByteArrayST)
import Data.Bits
import Data.Bytes.Builder.Bounded.Unsafe (Builder(..))
import Data.ByteString (ByteString)
import Data.Char (ord)
import Data.Primitive (MutableByteArray(..),ByteArray,writeByteArray)
import Data.Primitive (readByteArray,newByteArray,unsafeFreezeByteArray)
import Data.Primitive.ByteArray.Offset (MutableByteArrayOffset(..))
import Data.WideWord (Word128(Word128),Word256(Word256))
import GHC.Exts
import GHC.Int (Int64(I64#),Int32(I32#),Int16(I16#),Int8(I8#))
import GHC.IO (unsafeIOToST)
import GHC.ST (ST(ST))
import GHC.TypeLits (type (+))
import GHC.Word (Word8(W8#),Word16(W16#),Word32(W32#),Word64(W64#))
import Data.Bytes.Types (Bytes(Bytes))
import qualified Compat as C
import qualified Arithmetic.Lte as Lte
import qualified Arithmetic.Nat as Nat
import qualified Arithmetic.Types as Arithmetic
import qualified Data.Bytes as Bytes
import qualified Data.Bytes.Builder.Bounded.Unsafe as Unsafe
import qualified Data.Primitive as PM
run ::
Arithmetic.Nat n
-> Builder n
-> ByteArray
{-# inline run #-}
run :: Nat n -> Builder n -> ByteArray
run Nat n
n Builder n
b = (forall s. ST s ByteArray) -> ByteArray
runByteArrayST ((forall s. ST s ByteArray) -> ByteArray)
-> (forall s. ST s ByteArray) -> ByteArray
forall a b. (a -> b) -> a -> b
$ do
MutableByteArray s
arr <- Int -> ST s (MutableByteArray (PrimState (ST s)))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
newByteArray (Nat n -> Int
forall (n :: Nat). Nat n -> Int
Nat.demote Nat n
n)
Int
len <- Builder n -> MutableByteArray s -> Int -> ST s Int
forall (n :: Nat) s.
Builder n -> MutableByteArray s -> Int -> ST s Int
Unsafe.pasteST Builder n
b MutableByteArray s
arr Int
0
MutableByteArray s -> Int -> ST s ()
forall s. MutableByteArray s -> Int -> ST s ()
shrinkMutableByteArray MutableByteArray s
arr Int
len
MutableByteArray (PrimState (ST s)) -> ST s ByteArray
forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> m ByteArray
unsafeFreezeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr
runByteString ::
Arithmetic.Nat n
-> Builder n
-> ByteString
{-# inline runByteString #-}
runByteString :: Nat n -> Builder n -> ByteString
runByteString Nat n
n Builder n
b =
let (Int
finalLen,ByteArray
r) = (forall s. ST s (Int, ByteArray)) -> (Int, ByteArray)
runIntByteArrayST ((forall s. ST s (Int, ByteArray)) -> (Int, ByteArray))
-> (forall s. ST s (Int, ByteArray)) -> (Int, ByteArray)
forall a b. (a -> b) -> a -> b
$ do
MutableByteArray s
arr <- Int -> ST s (MutableByteArray (PrimState (ST s)))
forall (m :: * -> *).
PrimMonad m =>
Int -> m (MutableByteArray (PrimState m))
PM.newPinnedByteArray (Nat n -> Int
forall (n :: Nat). Nat n -> Int
Nat.demote Nat n
n)
Int
len <- Builder n -> MutableByteArray s -> Int -> ST s Int
forall (n :: Nat) s.
Builder n -> MutableByteArray s -> Int -> ST s Int
Unsafe.pasteST Builder n
b MutableByteArray s
arr Int
0
MutableByteArray s -> Int -> ST s ()
forall s. MutableByteArray s -> Int -> ST s ()
shrinkMutableByteArray MutableByteArray s
arr Int
len
ByteArray
arr' <- MutableByteArray (PrimState (ST s)) -> ST s ByteArray
forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> m ByteArray
unsafeFreezeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr
(Int, ByteArray) -> ST s (Int, ByteArray)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
len,ByteArray
arr')
in Bytes -> ByteString
Bytes.pinnedToByteString (ByteArray -> Int -> Int -> Bytes
Bytes ByteArray
r Int
0 Int
finalLen)
pasteGrowST ::
Arithmetic.Nat n
-> Builder n
-> MutableByteArrayOffset s
-> ST s (MutableByteArrayOffset s)
{-# inline pasteGrowST #-}
pasteGrowST :: Nat n
-> Builder n
-> MutableByteArrayOffset s
-> ST s (MutableByteArrayOffset s)
pasteGrowST Nat n
n Builder n
b !(MutableByteArrayOffset{$sel:array:MutableByteArrayOffset :: forall s. MutableByteArrayOffset s -> MutableByteArray s
array=MutableByteArray s
arr0,$sel:offset:MutableByteArrayOffset :: forall s. MutableByteArrayOffset s -> Int
offset=Int
off0}) = do
Int
sz0 <- MutableByteArray (PrimState (ST s)) -> ST s Int
forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m) -> m Int
PM.getSizeofMutableByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr0
let req :: Int
req = Nat n -> Int
forall (n :: Nat). Nat n -> Int
Nat.demote Nat n
n
let sz1 :: Int
sz1 = Int
off0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
req
if Int
sz1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
sz0
then do
Int
off1 <- Builder n -> MutableByteArray s -> Int -> ST s Int
forall (n :: Nat) s.
Builder n -> MutableByteArray s -> Int -> ST s Int
Unsafe.pasteST Builder n
b MutableByteArray s
arr0 Int
off0
MutableByteArrayOffset s -> ST s (MutableByteArrayOffset s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MutableByteArray s -> Int -> MutableByteArrayOffset s
forall s. MutableByteArray s -> Int -> MutableByteArrayOffset s
MutableByteArrayOffset MutableByteArray s
arr0 Int
off1)
else do
MutableByteArray s
arr1 <- MutableByteArray (PrimState (ST s))
-> Int -> ST s (MutableByteArray (PrimState (ST s)))
forall (m :: * -> *).
PrimMonad m =>
MutableByteArray (PrimState m)
-> Int -> m (MutableByteArray (PrimState m))
PM.resizeMutableByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr0 Int
sz1
Int
off1 <- Builder n -> MutableByteArray s -> Int -> ST s Int
forall (n :: Nat) s.
Builder n -> MutableByteArray s -> Int -> ST s Int
Unsafe.pasteST Builder n
b MutableByteArray s
arr1 Int
off0
MutableByteArrayOffset s -> ST s (MutableByteArrayOffset s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MutableByteArray s -> Int -> MutableByteArrayOffset s
forall s. MutableByteArray s -> Int -> MutableByteArrayOffset s
MutableByteArrayOffset MutableByteArray s
arr1 Int
off1)
empty :: Builder 0
empty :: Builder 0
empty = (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder 0
forall (n :: Nat).
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
Builder ((forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder 0)
-> (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder 0
forall a b. (a -> b) -> a -> b
$ \MutableByteArray# s
_ Int#
off0 State# s
s0 -> (# State# s
s0, Int#
off0 #)
infixr 9 `append`
append :: Builder m -> Builder n -> Builder (m + n)
append :: Builder m -> Builder n -> Builder (m + n)
append = Builder m -> Builder n -> Builder (m + n)
forall (m :: Nat) (n :: Nat) (p :: Nat).
Builder m -> Builder n -> Builder p
unsafeAppend
unsafeAppend :: Builder m -> Builder n -> Builder p
unsafeAppend :: Builder m -> Builder n -> Builder p
unsafeAppend (Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f) (Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
g) =
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder p
forall (n :: Nat).
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
Builder ((forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder p)
-> (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder p
forall a b. (a -> b) -> a -> b
$ \MutableByteArray# s
arr Int#
off0 State# s
s0 -> case MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f MutableByteArray# s
arr Int#
off0 State# s
s0 of
(# State# s
s1, Int#
r #) -> MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
g MutableByteArray# s
arr Int#
r State# s
s1
weaken :: forall m n. (m <= n) -> Builder m -> Builder n
weaken :: (m <= n) -> Builder m -> Builder n
weaken !m <= n
_ (Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f) = (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
forall (n :: Nat).
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f
substitute :: forall m n. (m :=: n) -> Builder m -> Builder n
substitute :: (m :=: n) -> Builder m -> Builder n
substitute !m :=: n
_ (Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f) = (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
forall (n :: Nat).
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
Builder forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
f
doubleDec :: Double -> Builder 32
doubleDec :: Double -> Builder 32
doubleDec (D# Double#
d) = (forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder 32
forall (n :: Nat).
(forall s.
MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #))
-> Builder n
Builder (\MutableByteArray# s
arr Int#
off0 State# s
s0 -> Double#
-> MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
forall s.
Double#
-> MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
doubleDec# Double#
d MutableByteArray# s
arr Int#
off0 State# s
s0)
word64Dec :: Word64 -> Builder 19
word64Dec :: Word64 -> Builder 19
word64Dec (W64# Word#
w) = Word# -> Builder 19
forall (n :: Nat). Word# -> Builder n
wordCommonDec# Word#
w
word32Dec :: Word32 -> Builder 10
word32Dec :: Word32 -> Builder 10
word32Dec (W32# Word#
w) = Word# -> Builder 10
forall (n :: Nat). Word# -> Builder n
wordCommonDec# (Word# -> Word#
C.word32ToWord# Word#
w)
word16Dec :: Word16 -> Builder 5
word16Dec :: Word16 -> Builder 5
word16Dec (W16# Word#
w) = Word# -> Builder 5
forall (n :: Nat). Word# -> Builder n
wordCommonDec# (Word# -> Word#
C.word16ToWord# Word#
w)
word8Dec :: Word8 -> Builder 3
word8Dec :: Word8 -> Builder 3
word8Dec (W8# Word#
w) =
Word# -> Builder 3
word8Dec# (Word# -> Word#
C.word8ToWord# Word#
w)
wordDec :: Word -> Builder 19
wordDec :: Word -> Builder 19
wordDec (W# Word#
w) = Word# -> Builder 19
forall (n :: Nat). Word# -> Builder n
wordCommonDec# Word#
w
int64Dec :: Int64 -> Builder 20
int64Dec :: Int64 -> Builder 20
int64Dec (I64# Int#
w) = Int# -> Builder 20
forall (n :: Nat). Int# -> Builder n
intCommonDec# Int#
w
int32Dec :: Int32 -> Builder 11
int32Dec :: Int32 -> Builder 11
int32Dec (I32# Int#
w) = Int# -> Builder 11
forall (n :: Nat). Int# -> Builder n
intCommonDec# (Int# -> Int#
C.int32ToInt# Int#
w)
int16Dec :: Int16 -> Builder 6
int16Dec :: Int16 -> Builder 6
int16Dec (I16# Int#
w) = Int# -> Builder 6
forall (n :: Nat). Int# -> Builder n
intCommonDec# (Int# -> Int#
C.int16ToInt# Int#
w)
int8Dec :: Int8 -> Builder 4
int8Dec :: Int8 -> Builder 4
int8Dec (I8# Int#
w) = Int# -> Builder 4
forall (n :: Nat). Int# -> Builder n
intCommonDec# (Int# -> Int#
C.int8ToInt# Int#
w)
intDec :: Int -> Builder 20
intDec :: Int -> Builder 20
intDec (I# Int#
w) = Int# -> Builder 20
forall (n :: Nat). Int# -> Builder n
intCommonDec# Int#
w
word8Dec# :: Word# -> Builder 3
{-# noinline word8Dec# #-}
word8Dec# :: Word# -> Builder 3
word8Dec# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off0 -> do
let !(I# Int#
off0# ) = Int
off0
!(!Word
x,!Word
ones) = Word -> Word -> (Word, Word)
forall a. Integral a => a -> a -> (a, a)
quotRem Word
w Word
10
!(hundreds :: Word
hundreds@(W# Word#
hundreds# ),tens :: Word
tens@(W# Word#
tens# )) = Word -> Word -> (Word, Word)
forall a. Integral a => a -> a -> (a, a)
quotRem Word
x Word
10
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off0 (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word
hundreds Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
0x30) :: Word8)
let !hasHundreds :: Int#
hasHundreds = Word# -> Word# -> Int#
gtWord# Word#
hundreds# Word#
0##
!off1 :: Int
off1@(I# Int#
off1# ) = Int# -> Int
I# (Int#
off0# Int# -> Int# -> Int#
+# Int#
hasHundreds)
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off1 (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word
tens Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
0x30) :: Word8)
let !off2 :: Int
off2 = Int# -> Int
I# (Int#
off1# Int# -> Int# -> Int#
+# (Int# -> Int# -> Int#
orI# Int#
hasHundreds (Word# -> Word# -> Int#
gtWord# Word#
tens# Word#
0## )))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off2 (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word
ones Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
0x30) :: Word8)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
w :: Word
w = Word# -> Word
W# Word#
w#
wordCommonDec# :: Word# -> Builder n
{-# noinline wordCommonDec# #-}
wordCommonDec# :: Word# -> Builder n
wordCommonDec# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off0 -> if Word64
w Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0
then MutableByteArray s -> Int -> Word -> ST s Int
forall s. MutableByteArray s -> Int -> Word -> ST s Int
internalWordLoop MutableByteArray s
arr Int
off0 (Word# -> Word
W# Word#
w#)
else do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off0 (Char -> Word8
c2w Char
'0')
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
w :: Word64
w = Word# -> Word64
W64# Word#
w#
internalWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int
{-# inline internalWordLoop #-}
internalWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int
internalWordLoop MutableByteArray s
arr Int
off0 Word
x0 = do
Int
off1 <- MutableByteArray s -> Int -> Word -> ST s Int
forall s. MutableByteArray s -> Int -> Word -> ST s Int
backwardsWordLoop MutableByteArray s
arr Int
off0 Word
x0
MutableByteArray s -> Int -> Int -> ST s ()
forall s. MutableByteArray s -> Int -> Int -> ST s ()
reverseBytes MutableByteArray s
arr Int
off0 (Int
off1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
off1
backwardsWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int
{-# inline backwardsWordLoop #-}
backwardsWordLoop :: MutableByteArray s -> Int -> Word -> ST s Int
backwardsWordLoop MutableByteArray s
arr Int
off0 Word
x0 = Int -> Word -> ST s Int
go Int
off0 Word
x0 where
go :: Int -> Word -> ST s Int
go !Int
off !(Word
x :: Word) = if Word
x Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
> Word
0
then do
let (Word
y,Word
z) = Word -> Word -> (Word, Word)
forall a. Integral a => a -> a -> (a, a)
quotRem Word
x Word
10
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word
z Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
0x30) :: Word8)
Int -> Word -> ST s Int
go (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Word
y
else Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
off
intCommonDec# :: Int# -> Builder n
{-# noinline intCommonDec# #-}
intCommonDec# :: Int# -> Builder n
intCommonDec# Int#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off0 -> case Int64 -> Int64 -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int64
w Int64
0 of
Ordering
GT -> MutableByteArray s -> Int -> Word -> ST s Int
forall s. MutableByteArray s -> Int -> Word -> ST s Int
internalWordLoop MutableByteArray s
arr Int
off0 (Int64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
w)
Ordering
EQ -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off0 (Char -> Word8
c2w Char
'0')
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Ordering
LT -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off0 (Char -> Word8
c2w Char
'-')
MutableByteArray s -> Int -> Word -> ST s Int
forall s. MutableByteArray s -> Int -> Word -> ST s Int
internalWordLoop MutableByteArray s
arr (Int
off0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int64 -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Int64
forall a. Num a => a -> a
negate Int64
w))
where
w :: Int64
w = Int# -> Int64
I64# Int#
w#
toHexUpper :: Word -> Word8
toHexUpper :: Word -> Word8
toHexUpper Word
w' = Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Word -> Word8) -> Word -> Word8
forall a b. (a -> b) -> a -> b
$ (Word -> Word
forall a. Bits a => a -> a
complement Word
theMask Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
loSolved)
Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. (Word
theMask Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
hiSolved)
where
w :: Word
w = Word
w' Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
0xF
theMask :: Word
theMask = (Word
1 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR (Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
10) Int
63) Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1
loSolved :: Word
loSolved = Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
48
hiSolved :: Word
hiSolved = Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
55
toHexLower :: Word -> Word8
toHexLower :: Word -> Word8
toHexLower Word
w' = Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral
(Word -> Word8) -> Word -> Word8
forall a b. (a -> b) -> a -> b
$ (Word -> Word
forall a. Bits a => a -> a
complement Word
theMask Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
loSolved)
Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. (Word
theMask Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
hiSolved)
where
w :: Word
w = Word
w' Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
0xF
theMask :: Word
theMask = (Word
1 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR (Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
10) Int
63) Word -> Word -> Word
forall a. Num a => a -> a -> a
- Word
1
loSolved :: Word
loSolved = Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
48
hiSolved :: Word
hiSolved = Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
87
word256PaddedLowerHex :: Word256 -> Builder 64
word256PaddedLowerHex :: Word256 -> Builder 64
word256PaddedLowerHex (Word256 Word64
w192 Word64
w128 Word64
w64 Word64
w0) =
Word64 -> Builder 16
word64PaddedLowerHex Word64
w192
Builder 16 -> Builder 48 -> Builder (16 + 48)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedLowerHex Word64
w128
Builder 16 -> Builder 32 -> Builder (16 + 32)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedLowerHex Word64
w64
Builder 16 -> Builder 16 -> Builder (16 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedLowerHex Word64
w0
word256PaddedUpperHex :: Word256 -> Builder 64
word256PaddedUpperHex :: Word256 -> Builder 64
word256PaddedUpperHex (Word256 Word64
w192 Word64
w128 Word64
w64 Word64
w0) =
Word64 -> Builder 16
word64PaddedUpperHex Word64
w192
Builder 16 -> Builder 48 -> Builder (16 + 48)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedUpperHex Word64
w128
Builder 16 -> Builder 32 -> Builder (16 + 32)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedUpperHex Word64
w64
Builder 16 -> Builder 16 -> Builder (16 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedUpperHex Word64
w0
word128PaddedLowerHex :: Word128 -> Builder 32
word128PaddedLowerHex :: Word128 -> Builder 32
word128PaddedLowerHex (Word128 Word64
w64 Word64
w0) =
Word64 -> Builder 16
word64PaddedLowerHex Word64
w64
Builder 16 -> Builder 16 -> Builder (16 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedLowerHex Word64
w0
word128PaddedUpperHex :: Word128 -> Builder 32
word128PaddedUpperHex :: Word128 -> Builder 32
word128PaddedUpperHex (Word128 Word64
w64 Word64
w0) =
Word64 -> Builder 16
word64PaddedUpperHex Word64
w64
Builder 16 -> Builder 16 -> Builder (16 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 16
word64PaddedUpperHex Word64
w0
word64PaddedUpperHex :: Word64 -> Builder 16
word64PaddedUpperHex :: Word64 -> Builder 16
word64PaddedUpperHex (W64# Word#
w) = Word# -> Builder 16
word64PaddedUpperHex# Word#
w
word64PaddedLowerHex :: Word64 -> Builder 16
word64PaddedLowerHex :: Word64 -> Builder 16
word64PaddedLowerHex (W64# Word#
w) = Word# -> Builder 16
word64PaddedLowerHex# Word#
w
word48PaddedLowerHex :: Word64 -> Builder 12
word48PaddedLowerHex :: Word64 -> Builder 12
word48PaddedLowerHex (W64# Word#
w) = Word# -> Builder 12
word48PaddedLowerHex# Word#
w
word32PaddedUpperHex :: Word32 -> Builder 8
word32PaddedUpperHex :: Word32 -> Builder 8
word32PaddedUpperHex (W32# Word#
w) = Word# -> Builder 8
word32PaddedUpperHex# (Word# -> Word#
C.word32ToWord# Word#
w)
word32PaddedLowerHex :: Word32 -> Builder 8
word32PaddedLowerHex :: Word32 -> Builder 8
word32PaddedLowerHex (W32# Word#
w) = Word# -> Builder 8
word32PaddedLowerHex# (Word# -> Word#
C.word32ToWord# Word#
w)
word16PaddedUpperHex :: Word16 -> Builder 4
word16PaddedUpperHex :: Word16 -> Builder 4
word16PaddedUpperHex (W16# Word#
w) = Word# -> Builder 4
word16PaddedUpperHex# (Word# -> Word#
C.word16ToWord# Word#
w)
word16PaddedLowerHex :: Word16 -> Builder 4
word16PaddedLowerHex :: Word16 -> Builder 4
word16PaddedLowerHex (W16# Word#
w) = Word# -> Builder 4
word16PaddedLowerHex# (Word# -> Word#
C.word16ToWord# Word#
w)
word16LowerHex :: Word16 -> Builder 4
word16LowerHex :: Word16 -> Builder 4
word16LowerHex (W16# Word#
w) = Word# -> Builder 4
word16LowerHex# (Word# -> Word#
C.word16ToWord# Word#
w)
word16UpperHex :: Word16 -> Builder 4
word16UpperHex :: Word16 -> Builder 4
word16UpperHex (W16# Word#
w) = Word# -> Builder 4
word16UpperHex# (Word# -> Word#
C.word16ToWord# Word#
w)
word8LowerHex :: Word8 -> Builder 2
word8LowerHex :: Word8 -> Builder 2
word8LowerHex (W8# Word#
w) = Word# -> Builder 2
word8LowerHex# (Word# -> Word#
C.word8ToWord# Word#
w)
word8PaddedUpperHex :: Word8 -> Builder 2
word8PaddedUpperHex :: Word8 -> Builder 2
word8PaddedUpperHex (W8# Word#
w) = Word# -> Builder 2
word8PaddedUpperHex# (Word# -> Word#
C.word8ToWord# Word#
w)
word8PaddedLowerHex :: Word8 -> Builder 2
word8PaddedLowerHex :: Word8 -> Builder 2
word8PaddedLowerHex (W8# Word#
w) = Word# -> Builder 2
word8PaddedLowerHex# (Word# -> Word#
C.word8ToWord# Word#
w)
word64PaddedUpperHex# :: Word# -> Builder 16
{-# noinline word64PaddedUpperHex# #-}
word64PaddedUpperHex# :: Word# -> Builder 16
word64PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
60))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
56))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
52))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
48))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
44))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
40))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
36))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
32))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
28))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
9) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
20))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
11) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
12) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
13) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
14) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
15) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
16)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word48PaddedLowerHex# :: Word# -> Builder 12
{-# noinline word48PaddedLowerHex# #-}
word48PaddedLowerHex# :: Word# -> Builder 12
word48PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 12
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 12)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 12
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
44))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
40))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
36))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
32))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
28))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
20))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
9) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
11) (Word -> Word8
toHexLower Word
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
12)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word64PaddedLowerHex# :: Word# -> Builder 16
{-# noinline word64PaddedLowerHex# #-}
word64PaddedLowerHex# :: Word# -> Builder 16
word64PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 16
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
60))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
56))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
52))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
48))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
44))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
40))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
36))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
32))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
28))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
9) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
10) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
20))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
11) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
12) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
13) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
14) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
15) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
16)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word32PaddedUpperHex# :: Word# -> Builder 8
{-# noinline word32PaddedUpperHex# #-}
word32PaddedUpperHex# :: Word# -> Builder 8
word32PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
28))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
20))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word32PaddedLowerHex# :: Word# -> Builder 8
{-# noinline word32PaddedLowerHex# #-}
word32PaddedLowerHex# :: Word# -> Builder 8
word32PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
28))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
20))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word16PaddedUpperHex# :: Word# -> Builder 4
word16PaddedUpperHex# :: Word# -> Builder 4
word16PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word16PaddedLowerHex# :: Word# -> Builder 4
word16PaddedLowerHex# :: Word# -> Builder 4
word16PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word12PaddedLowerHex# :: Word# -> Builder 3
word12PaddedLowerHex# :: Word# -> Builder 3
word12PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word12PaddedUpperHex# :: Word# -> Builder 3
word12PaddedUpperHex# :: Word# -> Builder 3
word12PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word8PaddedUpperHex# :: Word# -> Builder 2
{-# inline word8PaddedUpperHex# #-}
word8PaddedUpperHex# :: Word# -> Builder 2
word8PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexUpper (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word8PaddedLowerHex# :: Word# -> Builder 2
{-# inline word8PaddedLowerHex# #-}
word8PaddedLowerHex# :: Word# -> Builder 2
word8PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
4))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
toHexLower (Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
0))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word4PaddedLowerHex# :: Word# -> Builder 1
{-# inline word4PaddedLowerHex# #-}
word4PaddedLowerHex# :: Word# -> Builder 1
word4PaddedLowerHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexLower Word
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word4PaddedUpperHex# :: Word# -> Builder 1
{-# inline word4PaddedUpperHex# #-}
word4PaddedUpperHex# :: Word# -> Builder 1
word4PaddedUpperHex# Word#
w# = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
toHexUpper Word
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
where
w :: Word
w = Word# -> Word
W# Word#
w#
word16UpperHex# :: Word# -> Builder 4
word16UpperHex# :: Word# -> Builder 4
word16UpperHex# Word#
w#
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xF = (1 <= 4) -> Builder 1 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 1 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 1
word4PaddedUpperHex# Word#
w#)
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xFF = (2 <= 4) -> Builder 2 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 2 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 2
word8PaddedUpperHex# Word#
w#)
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xFFF = (3 <= 4) -> Builder 3 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 3 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 3
word12PaddedUpperHex# Word#
w#)
| Bool
otherwise = Word# -> Builder 4
word16PaddedUpperHex# Word#
w#
where
w :: Word
w = Word# -> Word
W# Word#
w#
word16LowerHex# :: Word# -> Builder 4
word16LowerHex# :: Word# -> Builder 4
word16LowerHex# Word#
w#
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xF = (1 <= 4) -> Builder 1 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 1 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 1
word4PaddedLowerHex# Word#
w#)
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xFF = (2 <= 4) -> Builder 2 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 2 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 2
word8PaddedLowerHex# Word#
w#)
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xFFF = (3 <= 4) -> Builder 3 -> Builder 4
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 3 <= 4
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 3
word12PaddedLowerHex# Word#
w#)
| Bool
otherwise = Word# -> Builder 4
word16PaddedLowerHex# Word#
w#
where
w :: Word
w = Word# -> Word
W# Word#
w#
word8LowerHex# :: Word# -> Builder 2
word8LowerHex# :: Word# -> Builder 2
word8LowerHex# Word#
w#
| Word
w Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
<= Word
0xF = (1 <= 2) -> Builder 1 -> Builder 2
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 1 <= 2
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 1
word4PaddedLowerHex# Word#
w#)
| Bool
otherwise = (2 <= 2) -> Builder 2 -> Builder 2
forall (m :: Nat) (n :: Nat). (m <= n) -> Builder m -> Builder n
weaken 2 <= 2
forall (a :: Nat) (b :: Nat).
(IsLte (CmpNat a b) ~ 'True) =>
a <= b
Lte.constant (Word# -> Builder 2
word8PaddedLowerHex# Word#
w#)
where
w :: Word
w = Word# -> Word
W# Word#
w#
wordPaddedDec2 :: Word -> Builder 2
wordPaddedDec2 :: Word -> Builder 2
wordPaddedDec2 !Word
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
let d1 :: Word
d1 = Word -> Word
approxDiv10 Word
w
d2 :: Word
d2 = Word
w Word -> Word -> Word
forall a. Num a => a -> a -> a
- (Word
10 Word -> Word -> Word
forall a. Num a => a -> a -> a
* Word
d1)
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 (Word
d1 Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
48))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
unsafeWordToWord8 (Word
d2 Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
48))
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
wordPaddedDec4 :: Word -> Builder 4
wordPaddedDec4 :: Word -> Builder 4
wordPaddedDec4 !Word
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
(MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10
((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10
(\MutableByteArray s
_ Int
_ Word
_ -> () -> ST s ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
) MutableByteArray s
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) Word
w
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
wordPaddedDec9 :: Word -> Builder 9
wordPaddedDec9 :: Word -> Builder 9
wordPaddedDec9 !Word
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 9
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 9)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 9
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
(MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10
((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$
(MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 ((MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ())
-> (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s
-> Int
-> Word
-> ST s ()
forall a b. (a -> b) -> a -> b
$ (MutableByteArray s -> Int -> Word -> ST s ())
-> MutableByteArray s -> Int -> Word -> ST s ()
forall s a.
(MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10
(\MutableByteArray s
_ Int
_ Word
_ -> () -> ST s ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
) MutableByteArray s
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8) Word
w
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
9)
putRem10 :: (MutableByteArray s -> Int -> Word -> ST s a) -> MutableByteArray s -> Int -> Word -> ST s a
{-# inline putRem10 #-}
putRem10 :: (MutableByteArray s -> Int -> Word -> ST s a)
-> MutableByteArray s -> Int -> Word -> ST s a
putRem10 MutableByteArray s -> Int -> Word -> ST s a
andThen MutableByteArray s
arr Int
off Word
dividend = do
let quotient :: Word
quotient = Word -> Word
approxDiv10 Word
dividend
remainder :: Word
remainder = Word
dividend Word -> Word -> Word
forall a. Num a => a -> a -> a
- (Word
10 Word -> Word -> Word
forall a. Num a => a -> a -> a
* Word
quotient)
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 (Word
remainder Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
48))
MutableByteArray s -> Int -> Word -> ST s a
andThen MutableByteArray s
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Word
quotient
ascii :: Char -> Builder 1
ascii :: Char -> Builder 1
ascii (C# Char#
c) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
1# ))
ascii2 :: Char -> Char -> Builder 2
ascii2 :: Char -> Char -> Builder 2
ascii2 (C# Char#
c0) (C# Char#
c1) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
2# ))
ascii3 :: Char -> Char -> Char -> Builder 3
ascii3 :: Char -> Char -> Char -> Builder 3
ascii3 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 3
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
3# ))
ascii4 :: Char -> Char -> Char -> Char -> Builder 4
ascii4 :: Char -> Char -> Char -> Char -> Builder 4
ascii4 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) (C# Char#
c3) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
3# ) Char#
c3)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
4# ))
ascii5 :: Char -> Char -> Char -> Char -> Char -> Builder 5
ascii5 :: Char -> Char -> Char -> Char -> Char -> Builder 5
ascii5 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) (C# Char#
c3) (C# Char#
c4) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 5
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 5)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 5
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
3# ) Char#
c3)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
4# ) Char#
c4)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
5# ))
ascii6 :: Char -> Char -> Char -> Char -> Char -> Char -> Builder 6
ascii6 :: Char -> Char -> Char -> Char -> Char -> Char -> Builder 6
ascii6 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) (C# Char#
c3) (C# Char#
c4) (C# Char#
c5) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 6
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 6)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 6
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
3# ) Char#
c3)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
4# ) Char#
c4)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
5# ) Char#
c5)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
6# ))
ascii7 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Builder 7
ascii7 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Builder 7
ascii7 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) (C# Char#
c3) (C# Char#
c4) (C# Char#
c5) (C# Char#
c6) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 7
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 7)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 7
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
3# ) Char#
c3)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
4# ) Char#
c4)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
5# ) Char#
c5)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
6# ) Char#
c6)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
7# ))
ascii8 :: Char -> Char -> Char -> Char -> Char -> Char -> Char -> Char -> Builder 8
ascii8 :: Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Char
-> Builder 8
ascii8 (C# Char#
c0) (C# Char#
c1) (C# Char#
c2) (C# Char#
c3) (C# Char#
c4) (C# Char#
c5) (C# Char#
c6) (C# Char#
c7) = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall a b. (a -> b) -> a -> b
$ \(MutableByteArray MutableByteArray# s
arr) (I# Int#
off) -> do
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr Int#
off Char#
c0)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
1# ) Char#
c1)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
2# ) Char#
c2)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
3# ) Char#
c3)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
4# ) Char#
c4)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
5# ) Char#
c5)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
6# ) Char#
c6)
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
forall d.
MutableByteArray# d -> Int# -> Char# -> State# d -> State# d
writeCharArray# MutableByteArray# s
arr (Int#
off Int# -> Int# -> Int#
+# Int#
7# ) Char#
c7)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int# -> Int
I# (Int#
off Int# -> Int# -> Int#
+# Int#
8# ))
wordLEB128 :: Word -> Builder 10
{-# inline wordLEB128 #-}
wordLEB128 :: Word -> Builder 10
wordLEB128 (W# Word#
w) = Word -> Builder 10
forall (n :: Nat). Word -> Builder n
lebCommon (Word# -> Word
W# Word#
w)
word32LEB128 :: Word32 -> Builder 5
{-# inline word32LEB128 #-}
word32LEB128 :: Word32 -> Builder 5
word32LEB128 (W32# Word#
w) = Word -> Builder 5
forall (n :: Nat). Word -> Builder n
lebCommon (Word# -> Word
W# (Word# -> Word#
C.word32ToWord# Word#
w))
word64LEB128 :: Word64 -> Builder 10
{-# inline word64LEB128 #-}
word64LEB128 :: Word64 -> Builder 10
word64LEB128 (W64# Word#
w) = Word -> Builder 10
forall (n :: Nat). Word -> Builder n
lebCommon (Word# -> Word
W# Word#
w)
lebCommon :: Word -> Builder n
lebCommon :: Word -> Builder n
lebCommon !Word
w = case Word -> Word -> (Word, Word)
forall a. Integral a => a -> a -> (a, a)
quotRem Word
w Word
128 of
(Word
q,Word
r) -> case Word
q of
Word
0 -> Word8 -> Builder n
forall (n :: Nat). Word8 -> Builder n
unsafeWord8 (Word -> Word8
unsafeWordToWord8 Word
r)
Word
_ -> Builder Any -> Builder Any -> Builder n
forall (m :: Nat) (n :: Nat) (p :: Nat).
Builder m -> Builder n -> Builder p
unsafeAppend
(Word8 -> Builder Any
forall (n :: Nat). Word8 -> Builder n
unsafeWord8 (Word -> Word8
unsafeWordToWord8 (Word
r Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0x80)))
(Word -> Builder Any
forall (n :: Nat). Word -> Builder n
lebCommon Word
q)
char :: Char -> Builder 4
char :: Char -> Builder 4
char Char
c
| Word
codepoint Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
0x80 = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 Word
codepoint)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Word
codepoint Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
0x800 = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteTwoOne Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteTwoTwo Word
codepoint))
Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Word
codepoint Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>= Word
0xD800 Bool -> Bool -> Bool
&& Word
codepoint Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
0xE000 = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word8
0xEF :: Word8)
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word8
0xBF :: Word8)
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word8
0xBD :: Word8)
Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3)
| Word
codepoint Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
0x10000 = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteThreeOne Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteThreeTwo Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteThreeThree Word
codepoint))
Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3)
| Bool
otherwise = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteFourOne Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteFourTwo Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteFourThree Word
codepoint))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word -> Word8
unsafeWordToWord8 (Word -> Word
byteFourFour Word
codepoint))
Int -> ST s Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
where
codepoint :: Word
codepoint :: Word
codepoint = Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
ord Char
c)
byteTwoOne :: Word -> Word
byteTwoOne :: Word -> Word
byteTwoOne Word
w = Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
6 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b11000000
byteTwoTwo :: Word -> Word
byteTwoTwo :: Word -> Word
byteTwoTwo Word
w = (Word
w Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
0b00111111) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
byteThreeOne :: Word -> Word
byteThreeOne :: Word -> Word
byteThreeOne Word
w = Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b11100000
byteThreeTwo :: Word -> Word
byteThreeTwo :: Word -> Word
byteThreeTwo Word
w = (Word
0b00111111 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
6) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
byteThreeThree :: Word -> Word
byteThreeThree :: Word -> Word
byteThreeThree Word
w = (Word
w Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
0b00111111) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
byteFourOne :: Word -> Word
byteFourOne :: Word -> Word
byteFourOne Word
w = Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
18 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b11110000
byteFourTwo :: Word -> Word
byteFourTwo :: Word -> Word
byteFourTwo Word
w = (Word
0b00111111 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
12) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
byteFourThree :: Word -> Word
byteFourThree :: Word -> Word
byteFourThree Word
w = (Word
0b00111111 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR Word
w Int
6) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
byteFourFour :: Word -> Word
byteFourFour :: Word -> Word
byteFourFour Word
w = (Word
0b00111111 Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. Word
w) Word -> Word -> Word
forall a. Bits a => a -> a -> a
.|. Word
0b10000000
int64BE :: Int64 -> Builder 8
int64BE :: Int64 -> Builder 8
int64BE (I64# Int#
i) = Word64 -> Builder 8
word64BE (Word# -> Word64
W64# (Int# -> Word#
int2Word# Int#
i))
int32BE :: Int32 -> Builder 4
int32BE :: Int32 -> Builder 4
int32BE (I32# Int#
i) = Word32 -> Builder 4
word32BE (Word# -> Word32
W32# (Word# -> Word#
C.wordToWord32# (Int# -> Word#
int2Word# (Int# -> Int#
C.int32ToInt# Int#
i))))
int16BE :: Int16 -> Builder 2
int16BE :: Int16 -> Builder 2
int16BE (I16# Int#
i) = Word16 -> Builder 2
word16BE (Word# -> Word16
W16# (Word# -> Word#
C.wordToWord16# (Int# -> Word#
int2Word# (Int# -> Int#
C.int16ToInt# Int#
i))))
int64LE :: Int64 -> Builder 8
int64LE :: Int64 -> Builder 8
int64LE (I64# Int#
i) = Word64 -> Builder 8
word64LE (Word# -> Word64
W64# (Int# -> Word#
int2Word# Int#
i))
int32LE :: Int32 -> Builder 4
int32LE :: Int32 -> Builder 4
int32LE (I32# Int#
i) = Word32 -> Builder 4
word32LE (Word# -> Word32
W32# (Word# -> Word#
C.wordToWord32# (Int# -> Word#
int2Word# (Int# -> Int#
C.int32ToInt# Int#
i))))
int16LE :: Int16 -> Builder 2
int16LE :: Int16 -> Builder 2
int16LE (I16# Int#
i) = Word16 -> Builder 2
word16LE (Word# -> Word16
W16# (Word# -> Word#
C.wordToWord16# (Int# -> Word#
int2Word# (Int# -> Int#
C.int16ToInt# Int#
i))))
word128LE :: Word128 -> Builder 16
word128LE :: Word128 -> Builder 16
word128LE (Word128 Word64
hi Word64
lo) = Builder 8 -> Builder 8 -> Builder (8 + 8)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
append (Word64 -> Builder 8
word64LE Word64
lo) (Word64 -> Builder 8
word64LE Word64
hi)
word128BE :: Word128 -> Builder 16
word128BE :: Word128 -> Builder 16
word128BE (Word128 Word64
hi Word64
lo) = Builder 8 -> Builder 8 -> Builder (8 + 8)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
append (Word64 -> Builder 8
word64BE Word64
hi) (Word64 -> Builder 8
word64BE Word64
lo)
word256LE :: Word256 -> Builder 32
word256LE :: Word256 -> Builder 32
word256LE (Word256 Word64
hi Word64
mhi Word64
mlo Word64
lo) = Word64 -> Builder 8
word64LE Word64
lo Builder 8 -> Builder 24 -> Builder (8 + 24)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64LE Word64
mlo Builder 8 -> Builder 16 -> Builder (8 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64LE Word64
mhi Builder 8 -> Builder 8 -> Builder (8 + 8)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64LE Word64
hi
word256BE :: Word256 -> Builder 32
word256BE :: Word256 -> Builder 32
word256BE (Word256 Word64
hi Word64
mhi Word64
mlo Word64
lo) = Word64 -> Builder 8
word64BE Word64
hi Builder 8 -> Builder 24 -> Builder (8 + 24)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64BE Word64
mhi Builder 8 -> Builder 16 -> Builder (8 + 16)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64BE Word64
mlo Builder 8 -> Builder 8 -> Builder (8 + 8)
forall (m :: Nat) (n :: Nat).
Builder m -> Builder n -> Builder (m + n)
`append` Word64 -> Builder 8
word64BE Word64
lo
word64LE :: Word64 -> Builder 8
word64LE :: Word64 -> Builder 8
word64LE Word64
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
56))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
48))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
40))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
32))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 Word64
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8)
word64BE :: Word64 -> Builder 8
word64BE :: Word64 -> Builder 8
word64BE Word64
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 8
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
56))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
48))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
40))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
32))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
5) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
6) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
unsafeShiftR Word64
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word64 @Word8 Word64
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
8)
word32LE :: Word32 -> Builder 4
word32LE :: Word32 -> Builder 4
word32LE Word32
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 Word32
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
word32BE :: Word32 -> Builder 4
word32BE :: Word32 -> Builder 4
word32BE Word32
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 4
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
24))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
16))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
unsafeShiftR Word32
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
3) (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word32 @Word8 Word32
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)
word16LE :: Word16 -> Builder 2
word16LE :: Word16 -> Builder 2
word16LE Word16
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word16 @Word8 (Word16 -> Int -> Word16
forall a. Bits a => a -> Int -> a
unsafeShiftR Word16
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word16 @Word8 Word16
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
word16BE :: Word16 -> Builder 2
word16BE :: Word16 -> Builder 2
word16BE Word16
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 2
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off ) (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word16 @Word8 (Word16 -> Int -> Word16
forall a. Bits a => a -> Int -> a
unsafeShiftR Word16
w Int
8))
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral @Word16 @Word8 Word16
w)
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
word8 :: Word8 -> Builder 1
word8 :: Word8 -> Builder 1
word8 Word8
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder 1
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off Word8
w
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
unsafeWord8 :: Word8 -> Builder n
unsafeWord8 :: Word8 -> Builder n
unsafeWord8 Word8
w = (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall (n :: Nat).
(forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
Unsafe.construct ((forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n)
-> (forall s. MutableByteArray s -> Int -> ST s Int) -> Builder n
forall a b. (a -> b) -> a -> b
$ \MutableByteArray s
arr Int
off -> do
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
off Word8
w
Int -> ST s Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
off Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
reverseBytes :: MutableByteArray s -> Int -> Int -> ST s ()
{-# inline reverseBytes #-}
reverseBytes :: MutableByteArray s -> Int -> Int -> ST s ()
reverseBytes MutableByteArray s
arr Int
begin Int
end = Int -> Int -> ST s ()
go Int
begin Int
end where
go :: Int -> Int -> ST s ()
go Int
ixA Int
ixB = if Int
ixA Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
ixB
then do
Word8
a :: Word8 <- MutableByteArray (PrimState (ST s)) -> Int -> ST s Word8
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> m a
readByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
ixA
Word8
b :: Word8 <- MutableByteArray (PrimState (ST s)) -> Int -> ST s Word8
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> m a
readByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
ixB
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
ixA Word8
b
MutableByteArray (PrimState (ST s)) -> Int -> Word8 -> ST s ()
forall a (m :: * -> *).
(Prim a, PrimMonad m) =>
MutableByteArray (PrimState m) -> Int -> a -> m ()
writeByteArray MutableByteArray s
MutableByteArray (PrimState (ST s))
arr Int
ixB Word8
a
Int -> Int -> ST s ()
go (Int
ixA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
ixB Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
else () -> ST s ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
c2w :: Char -> Word8
c2w :: Char -> Word8
c2w = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord
shrinkMutableByteArray :: MutableByteArray s -> Int -> ST s ()
shrinkMutableByteArray :: MutableByteArray s -> Int -> ST s ()
shrinkMutableByteArray (MutableByteArray MutableByteArray# s
arr) (I# Int#
sz) =
(State# (PrimState (ST s)) -> State# (PrimState (ST s))) -> ST s ()
forall (m :: * -> *).
PrimMonad m =>
(State# (PrimState m) -> State# (PrimState m)) -> m ()
primitive_ (MutableByteArray# s -> Int# -> State# s -> State# s
forall d. MutableByteArray# d -> Int# -> State# d -> State# d
shrinkMutableByteArray# MutableByteArray# s
arr Int#
sz)
doubleDec# :: forall s.
Double# -> MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
doubleDec# :: Double#
-> MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
doubleDec# Double#
d# MutableByteArray# s
marr# Int#
off# State# s
s0 =
case IO Int -> ST s Int
forall a s. IO a -> ST s a
unsafeIOToST (MutableByteArray# s -> Int# -> Double# -> IO Int
forall s. MutableByteArray# s -> Int# -> Double# -> IO Int
c_paste_double MutableByteArray# s
marr# Int#
off# Double#
d#) of
ST STRep s Int
f -> case STRep s Int
f State# s
s0 of
(# State# s
s1, I# Int#
r #) -> (# State# s
s1, Int#
r #)
approxDiv10 :: Word -> Word
approxDiv10 :: Word -> Word
approxDiv10 !Word
n = Word -> Int -> Word
forall a. Bits a => a -> Int -> a
unsafeShiftR (Word
0x1999999A Word -> Word -> Word
forall a. Num a => a -> a -> a
* Word
n) Int
32
unsafeWordToWord8 :: Word -> Word8
unsafeWordToWord8 :: Word -> Word8
unsafeWordToWord8 (W# Word#
w) = Word# -> Word8
W8# (Word# -> Word#
C.wordToWord8# Word#
w)
foreign import ccall unsafe "bytebuild_paste_double" c_paste_double ::
MutableByteArray# s -> Int# -> Double# -> IO Int