-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bytestring builder with zero intermediate allocation -- -- Please see README.md. @package bytezap @version 1.0.0 module Bytezap -- | Missing byteSwap functions for signed integers. -- -- We have them for unsigned integers, but not for signed. They should -- probably be provided, so I'm considering this a compatibility module -- for the future when we have them. module Raehik.Compat.Data.Int.ByteSwap byteSwapI16 :: Int16 -> Int16 byteSwapI32 :: Int32 -> Int32 byteSwapI64 :: Int64 -> Int64 byteSwapI :: Int -> Int -- | Missing byteSwap functions for unsigned integers. -- -- Don't know why this one is missing. module Raehik.Compat.Data.Word.ByteSwap byteSwap :: Word -> Word module Raehik.Compat.GHC.Exts.GHC908MemcpyPrimops copyAddrToAddrNonOverlapping# :: Addr# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld setAddrRange# :: Addr# -> Int# -> Int# -> State# RealWorld -> State# RealWorld module Raehik.Compat.GHC.Exts.GHC910UnalignedAddrPrimops indexWord8OffAddrAsWord16# :: Addr# -> Int# -> Word16# readWord8OffAddrAsWord16# :: Addr# -> Int# -> State# d -> (# State# d, Word16# #) writeWord8OffAddrAsWord16# :: Addr# -> Int# -> Word16# -> State# d -> State# d indexWord8OffAddrAsWord32# :: Addr# -> Int# -> Word32# readWord8OffAddrAsWord32# :: Addr# -> Int# -> State# d -> (# State# d, Word32# #) writeWord8OffAddrAsWord32# :: Addr# -> Int# -> Word32# -> State# d -> State# d indexWord8OffAddrAsWord64# :: Addr# -> Int# -> Word64# readWord8OffAddrAsWord64# :: Addr# -> Int# -> State# d -> (# State# d, Word64# #) writeWord8OffAddrAsWord64# :: Addr# -> Int# -> Word64# -> State# d -> State# d indexWord8OffAddrAsWord# :: Addr# -> Int# -> Word# readWord8OffAddrAsWord# :: Addr# -> Int# -> State# d -> (# State# d, Word# #) writeWord8OffAddrAsWord# :: Addr# -> Int# -> Word# -> State# d -> State# d indexWord8OffAddrAsInt16# :: Addr# -> Int# -> Int16# readWord8OffAddrAsInt16# :: Addr# -> Int# -> State# d -> (# State# d, Int16# #) writeWord8OffAddrAsInt16# :: Addr# -> Int# -> Int16# -> State# d -> State# d indexWord8OffAddrAsInt32# :: Addr# -> Int# -> Int32# readWord8OffAddrAsInt32# :: Addr# -> Int# -> State# d -> (# State# d, Int32# #) writeWord8OffAddrAsInt32# :: Addr# -> Int# -> Int32# -> State# d -> State# d indexWord8OffAddrAsInt64# :: Addr# -> Int# -> Int64# readWord8OffAddrAsInt64# :: Addr# -> Int# -> State# d -> (# State# d, Int64# #) writeWord8OffAddrAsInt64# :: Addr# -> Int# -> Int64# -> State# d -> State# d indexWord8OffAddrAsInt# :: Addr# -> Int# -> Int# readWord8OffAddrAsInt# :: Addr# -> Int# -> State# d -> (# State# d, Int# #) writeWord8OffAddrAsInt# :: Addr# -> Int# -> Int# -> State# d -> State# d module Raehik.Compat.Data.Primitive.Types -- | Prim extension class providing unaligned accesses -- -- hoping to get this merged in -- https://github.com/haskell/primitive/issues/409 -- -- (also includes Addr# primops which that issue/PR may not) -- -- Also includes an associated type for size in bytes. Another thing that -- maybe primitive could provide. (Wouldn't be hard!) class Prim a => Prim' a where { type SizeOf a :: Natural; } -- | Read a value from the array. The offset is in bytes. indexWord8ByteArrayAs# :: Prim' a => ByteArray# -> Int# -> a readWord8ByteArrayAs# :: Prim' a => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) writeWord8ByteArrayAs# :: Prim' a => MutableByteArray# s -> Int# -> a -> State# s -> State# s indexWord8OffAddrAs# :: Prim' a => Addr# -> Int# -> a readWord8OffAddrAs# :: Prim' a => Addr# -> Int# -> State# s -> (# State# s, a #) writeWord8OffAddrAs# :: Prim' a => Addr# -> Int# -> a -> State# s -> State# s -- | Class of types supporting primitive array operations. This includes -- interfacing with GC-managed memory (functions suffixed with -- ByteArray#) and interfacing with unmanaged memory (functions -- suffixed with Addr#). Endianness is platform-dependent. class () => Prim a -- | Size of values of type a. The argument is not used. sizeOf# :: Prim a => a -> Int# -- | Alignment of values of type a. The argument is not used. alignment# :: Prim a => a -> Int# -- | Read a value from the array. The offset is in elements of type -- a rather than in bytes. indexByteArray# :: Prim a => ByteArray# -> Int# -> a -- | Read a value from the mutable array. The offset is in elements of type -- a rather than in bytes. readByteArray# :: Prim a => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) -- | Write a value to the mutable array. The offset is in elements of type -- a rather than in bytes. writeByteArray# :: Prim a => MutableByteArray# s -> Int# -> a -> State# s -> State# s -- | Fill a slice of the mutable array with a value. The offset and length -- of the chunk are in elements of type a rather than in bytes. setByteArray# :: Prim a => MutableByteArray# s -> Int# -> Int# -> a -> State# s -> State# s -- | Read a value from a memory position given by an address and an offset. -- The memory block the address refers to must be immutable. The offset -- is in elements of type a rather than in bytes. indexOffAddr# :: Prim a => Addr# -> Int# -> a -- | Read a value from a memory position given by an address and an offset. -- The offset is in elements of type a rather than in bytes. readOffAddr# :: Prim a => Addr# -> Int# -> State# s -> (# State# s, a #) -- | Write a value to a memory position given by an address and an offset. -- The offset is in elements of type a rather than in bytes. writeOffAddr# :: Prim a => Addr# -> Int# -> a -> State# s -> State# s -- | Fill a memory block given by an address, an offset and a length. The -- offset and length are in elements of type a rather than in -- bytes. setOffAddr# :: Prim a => Addr# -> Int# -> Int# -> a -> State# s -> State# s -- | Size of values of type a. The argument is not used. -- -- This function has existed since 0.1, but was moved from -- Primitive to Types in version 0.6.3.0. sizeOf :: Prim a => a -> Int instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Word.Word8 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Word.Word16 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Word.Word32 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Word.Word64 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Int.Int8 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Int.Int16 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Int.Int32 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Int.Int64 instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Types.Word instance Raehik.Compat.Data.Primitive.Types.Prim' GHC.Types.Int -- | I think this should be in primitive. module Raehik.Compat.Data.Primitive.Types.Endian -- | Boxed types which permit reversing byte order ("byte swapping"). class ByteSwap a byteSwap :: ByteSwap a => a -> a newtype ByteOrdered (end :: ByteOrder) a ByteOrdered :: a -> ByteOrdered (end :: ByteOrder) a [unByteOrdered] :: ByteOrdered (end :: ByteOrder) a -> a -- | Newtype for easier instance derivation. newtype PrimByteSwapped a PrimByteSwapped :: a -> PrimByteSwapped a [unPrimByteSwapped] :: PrimByteSwapped a -> a instance GHC.Num.Num a => GHC.Num.Num (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered end a) instance GHC.Show.Show a => GHC.Show.Show (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered end a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered end a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered end a) instance Data.Primitive.Types.Prim a => Data.Primitive.Types.Prim (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered 'GHC.ByteOrder.LittleEndian a) instance Raehik.Compat.Data.Primitive.Types.Prim' a => Raehik.Compat.Data.Primitive.Types.Prim' (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered 'GHC.ByteOrder.LittleEndian a) instance (Data.Primitive.Types.Prim a, Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap a) => Data.Primitive.Types.Prim (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered 'GHC.ByteOrder.BigEndian a) instance (Raehik.Compat.Data.Primitive.Types.Prim' a, Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap a) => Raehik.Compat.Data.Primitive.Types.Prim' (Raehik.Compat.Data.Primitive.Types.Endian.ByteOrdered 'GHC.ByteOrder.BigEndian a) instance (Data.Primitive.Types.Prim a, Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap a) => Data.Primitive.Types.Prim (Raehik.Compat.Data.Primitive.Types.Endian.PrimByteSwapped a) instance (Raehik.Compat.Data.Primitive.Types.Prim' a, Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap a) => Raehik.Compat.Data.Primitive.Types.Prim' (Raehik.Compat.Data.Primitive.Types.Endian.PrimByteSwapped a) instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Word.Word16 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Word.Word32 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Word.Word64 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Types.Word instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Int.Int16 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Int.Int32 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Int.Int64 instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Types.Int instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Types.Float instance Raehik.Compat.Data.Primitive.Types.Endian.ByteSwap GHC.Types.Double module Bytezap.Poke type Poke# s = Addr# -> Int# -> State# s -> (# State# s, Int# #) -- | Poke newtype wrapper. newtype Poke s Poke :: Poke# s -> Poke s [unPoke] :: Poke s -> Poke# s -- | Execute a Poke at a fresh ByteString of the given -- length. unsafeRunPokeBS :: Int -> Poke RealWorld -> ByteString wrapIO :: Poke RealWorld -> Ptr Word8 -> IO () wrapIOUptoN :: Poke RealWorld -> Ptr Word8 -> IO Int -- | Execute a Poke at a fresh ByteString of the given -- maximum length. Does not reallocate if final size is less than -- estimated. unsafeRunPokeBSUptoN :: Int -> Poke RealWorld -> ByteString -- | Poke a type via its Prim' instance. prim :: forall a s. Prim' a => a -> Poke s byteString :: ByteString -> Poke RealWorld byteArray# :: ByteArray# -> Int# -> Int# -> Poke s -- | essentially memset replicateByte :: Int -> Word8 -> Poke RealWorld instance GHC.Base.Semigroup (Bytezap.Poke.Poke s) instance GHC.Base.Monoid (Bytezap.Poke.Poke s) module Bytezap.Write.Internal -- | A Poke with the associated size it pokes. data Write s Write :: Int -> Poke s -> Write s [size] :: Write s -> Int [poke] :: Write s -> Poke s instance GHC.Base.Semigroup (Bytezap.Write.Internal.Write s) instance GHC.Base.Monoid (Bytezap.Write.Internal.Write s) module Bytezap.Write -- | A Poke with the associated size it pokes. data Write s runWriteBS :: Write RealWorld -> ByteString runWriteBSUptoN :: Write RealWorld -> ByteString prim :: forall a s. Prim' a => a -> Write s byteString :: ByteString -> Write RealWorld byteArray# :: ByteArray# -> Int# -> Int# -> Write s -- | essentially memset replicateByte :: Int -> Word8 -> Write RealWorld module Bytezap.Poke.Derived.Endian w16le :: Word16 -> Poke s w16be :: Word16 -> Poke s w32le :: Word32 -> Poke s w32be :: Word32 -> Poke s w64le :: Word64 -> Poke s w64be :: Word64 -> Poke s i16le :: Int16 -> Poke s i16be :: Int16 -> Poke s i32le :: Int32 -> Poke s i32be :: Int32 -> Poke s i64le :: Int64 -> Poke s i64be :: Int64 -> Poke s module Bytezap.Poke.Derived -- | Poke a ShortByteString. shortByteString :: ShortByteString -> Poke s -- | Poke a Text. text :: Text -> Poke s -- | Poke a Char. -- -- Adapted from utf8-string. char :: Char -> Poke s -- | unsafePokeIndexed pokeAt off n performs n indexed -- pokes starting from off. -- -- Does not check bounds. Largely intended for bytewise pokes where some -- work needs to be performed for each byte (e.g. escaping text and -- poking inline). unsafePokeIndexed :: (Int -> Poke s) -> Int -> Int -> Poke s module Bytezap.Write.Derived -- | Write a ShortByteString. shortByteString :: ShortByteString -> Write s -- | Write a Text. text :: Text -> Write s -- | Write a Char. -- -- Adapted from utf8-string. char :: Char -> Write s module Bytezap.Poke.Json escapedLength8 :: Text -> Int escapeW8 :: Word8 -> Int pokeEscapedTextUnquoted :: Text -> Poke s pokeEscapeW8 :: Word8 -> Poke s w8AsciiHex :: Word8 -> Poke s c_lower_hex_table :: Ptr CChar -- | Handy typenat utils. module Util.TypeNats natVal'' :: forall n. KnownNat n => Natural natValInt :: forall n. KnownNat n => Int -- | Pokes with type-level poke length. module Bytezap.Poke.KnownLen newtype PokeKnownLen (len :: Natural) s PokeKnownLen :: Poke s -> PokeKnownLen (len :: Natural) s [unPokeKnownLen] :: PokeKnownLen (len :: Natural) s -> Poke s mappend' :: PokeKnownLen n s -> PokeKnownLen m s -> PokeKnownLen (n + m) s mempty' :: PokeKnownLen 0 s runPokeKnownLenBS :: forall n. KnownNat n => PokeKnownLen n RealWorld -> ByteString prim :: Prim' a => a -> PokeKnownLen (SizeOf a) s