-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fast and extensible bytestring builder -- -- This package provides efficient implementation of bytestring builders. -- See README.md for details @package mason @version 0.2 module Mason.Builder.Internal -- | The Builder type. Requires RankNTypes extension type Builder = forall s. Buildable s => BuilderFor s -- | Builder specialised for a backend newtype BuilderFor s Builder :: (s -> Buffer -> IO Buffer) -> BuilderFor s [unBuilder] :: BuilderFor s -> s -> Buffer -> IO Buffer -- | This class is used to provide backend-specific operations for running -- a Builder. class Buildable s -- | Put a ByteString. byteString :: Buildable s => ByteString -> BuilderFor s -- | Flush the content of the internal buffer. flush :: Buildable s => BuilderFor s -- | Allocate a buffer with at least the given length. allocate :: Buildable s => Int -> BuilderFor s newtype GrowingBuffer GrowingBuffer :: IORef (ForeignPtr Word8) -> GrowingBuffer -- | Buffer pointers data Buffer Buffer :: {-# UNPACK #-} !Ptr Word8 -> {-# UNPACK #-} !Ptr Word8 -> Buffer -- | end of the buffer (next to the last byte) [bEnd] :: Buffer -> {-# UNPACK #-} !Ptr Word8 -- | current position [bCur] :: Buffer -> {-# UNPACK #-} !Ptr Word8 -- | Copy a ByteString to a buffer. byteStringCopy :: Buildable s => ByteString -> BuilderFor s -- | Copy a ShortByteString to a buffer. shortByteString :: ShortByteString -> Builder -- | Create a strict ByteString toStrictByteString :: BuilderFor GrowingBuffer -> ByteString data Channel Channel :: !MVar ByteString -> !IORef (ForeignPtr Word8) -> Channel [chResp] :: Channel -> !MVar ByteString [chBuffer] :: Channel -> !IORef (ForeignPtr Word8) -- | Create a lazy ByteString. Threaded runtime is required. toLazyByteString :: BuilderFor Channel -> ByteString -- | UTF-8 encode a String. stringUtf8 :: String -> Builder -- | Run a builder within a buffer and prefix it by the length. lengthPrefixedWithin :: Int -> BoundedPrim Int -> BuilderFor () -> Builder -- | Use BoundedPrim primBounded :: BoundedPrim a -> a -> Builder -- | Use FixedPrim primFixed :: FixedPrim a -> a -> Builder primMapListFixed :: FixedPrim a -> [a] -> Builder primMapListBounded :: BoundedPrim a -> [a] -> Builder primMapByteStringFixed :: FixedPrim Word8 -> ByteString -> Builder primMapLazyByteStringFixed :: FixedPrim Word8 -> ByteString -> Builder -- | Environment for handle output data PutEnv PutEnv :: !Int -> !Ptr Word8 -> Ptr Word8 -> IO () -> !IORef (ForeignPtr Word8) -> !IORef Int -> PutEnv [peThreshold] :: PutEnv -> !Int -- | takes a pointer range and returns the number of bytes written [pePut] :: PutEnv -> !Ptr Word8 -> Ptr Word8 -> IO () [peBuffer] :: PutEnv -> !IORef (ForeignPtr Word8) [peTotal] :: PutEnv -> !IORef Int -- | Write a Builder into a handle and obtain the number of bytes -- written. flush does not imply actual disk operations. Set -- NoBuffering if you want it to write the content immediately. hPutBuilderLen :: Handle -> BuilderFor PutEnv -> IO Int -- | Encode Text with a custom escaping function encodeUtf8BuilderEscaped :: BoundedPrim Word8 -> Text -> Builder -- | Write a Builder into a handle and obtain the number of bytes -- written. sendBuilder :: Socket -> BuilderFor PutEnv -> IO Int cstring :: Ptr Word8 -> Builder cstringUtf8 :: Ptr Word8 -> Builder -- | Construct a Builder from a "poke" function. withPtr :: Buildable s => Int -> (Ptr Word8 -> IO (Ptr Word8)) -> BuilderFor s -- | Turn a Storable value into a Builder storable :: Storable a => a -> Builder paddedBoundedPrim :: Word8 -> Int -> BoundedPrim a -> a -> Builder zeroPaddedBoundedPrim :: Int -> BoundedPrim a -> a -> Builder -- | Ensure that the given number of bytes is available in the buffer. -- Subject to semigroup fusion ensure :: Int -> (Buffer -> IO Buffer) -> Builder -- | Allocate a new buffer. allocateConstant :: (s -> IORef (ForeignPtr Word8)) -> Int -> BuilderFor s -- | Decimal encoding of a positive Double. withGrisu3 :: Double -> IO r -> (Ptr Word8 -> Int -> Int -> IO r) -> IO r withGrisu3Rounded :: Int -> Double -> (Ptr Word8 -> Int -> Int -> IO r) -> IO r -- | Round up to the supplied precision inplace. roundDigit :: Int -> Int -> Ptr Word8 -> IO Bool instance Mason.Builder.Internal.Buildable Mason.Builder.Internal.PutEnv instance Mason.Builder.Internal.Buildable Mason.Builder.Internal.Channel instance Mason.Builder.Internal.Buildable Mason.Builder.Internal.GrowingBuffer instance Mason.Builder.Internal.Buildable () instance Mason.Builder.Internal.Buildable s => Data.String.IsString (Mason.Builder.Internal.BuilderFor s) instance GHC.Base.Semigroup (Mason.Builder.Internal.BuilderFor s) instance GHC.Base.Monoid (Mason.Builder.Internal.BuilderFor a) module Mason.Builder -- | The Builder type. Requires RankNTypes extension type Builder = forall s. Buildable s => BuilderFor s -- | Builder specialised for a backend data BuilderFor s -- | This class is used to provide backend-specific operations for running -- a Builder. class Buildable s -- | Create a strict ByteString toStrictByteString :: BuilderFor GrowingBuffer -> ByteString -- | Create a lazy ByteString. Threaded runtime is required. toLazyByteString :: BuilderFor Channel -> ByteString -- | Write a Builder into a handle and obtain the number of bytes -- written. flush does not imply actual disk operations. Set -- NoBuffering if you want it to write the content immediately. hPutBuilderLen :: Handle -> BuilderFor PutEnv -> IO Int -- | Put the content of a Builder to a Handle. hPutBuilder :: Handle -> BuilderFor PutEnv -> IO () -- | Write a Builder into a handle and obtain the number of bytes -- written. sendBuilder :: Socket -> BuilderFor PutEnv -> IO Int -- | Flush the content of the internal buffer. flush :: Buildable s => BuilderFor s -- | Put a ByteString. byteString :: Buildable s => ByteString -> BuilderFor s -- | Combine chunks of a lazy ByteString lazyByteString :: ByteString -> Builder -- | Copy a ShortByteString to a buffer. shortByteString :: ShortByteString -> Builder -- | Encode Text as a UTF-8 byte stream. textUtf8 :: Text -> Builder -- | Encode Text as a UTF-8 byte stream. Synonym for -- textUtf8. encodeUtf8Builder :: Text -> Builder -- | Encode Text with a custom escaping function encodeUtf8BuilderEscaped :: BoundedPrim Word8 -> Text -> Builder -- | Char7 encode a Char. char7 :: Char -> Builder -- | Char7 encode a String. string7 :: String -> Builder -- | Char8 encode a Char. char8 :: Char -> Builder -- | Char8 encode a String. string8 :: String -> Builder -- | UTF-8 encode a Char. charUtf8 :: Char -> Builder -- | UTF-8 encode a String. stringUtf8 :: String -> Builder -- | Turn a Storable value into a Builder storable :: Storable a => a -> Builder -- | Encode a single signed byte as-is. int8 :: Int8 -> Builder -- | Encode a single unsigned byte as-is. word8 :: Word8 -> Builder -- | Encode an Int16 in little endian format. int16LE :: Int16 -> Builder -- | Encode an Int32 in little endian format. int32LE :: Int32 -> Builder -- | Encode an Int64 in little endian format. int64LE :: Int64 -> Builder -- | Encode a Word16 in little endian format. word16LE :: Word16 -> Builder -- | Encode a Word32 in little endian format. word32LE :: Word32 -> Builder -- | Encode a Word64 in little endian format. word64LE :: Word64 -> Builder -- | Encode a Float in little endian format. floatLE :: Float -> Builder -- | Encode a Double in little endian format. doubleLE :: Double -> Builder -- | Encode an Int16 in big endian format. int16BE :: Int16 -> Builder -- | Encode an Int32 in big endian format. int32BE :: Int32 -> Builder -- | Encode an Int64 in big endian format. int64BE :: Int64 -> Builder -- | Encode a Word16 in big endian format. word16BE :: Word16 -> Builder -- | Encode a Word32 in big endian format. word32BE :: Word32 -> Builder -- | Encode a Word64 in big endian format. word64BE :: Word64 -> Builder -- | Encode a Float in big endian format. floatBE :: Float -> Builder -- | Encode a Double in big endian format. doubleBE :: Double -> Builder -- | Currently slow. Decimal encoding of an IEEE Float. floatDec :: Float -> Builder -- | Decimal encoding of an IEEE Double. doubleDec :: Double -> Builder -- | Attach an SI prefix so that abs(mantissa) is within [1, 1000). Omits -- c, d, da and h. doubleSI :: Int -> Double -> Builder -- | Always use exponents doubleExp :: Int -> Double -> Builder -- | Fixed precision doubleFixed :: Int -> Double -> Builder -- | Decimal encoding of a Word8 using the ASCII digits. word8Dec :: Word8 -> Builder -- | Decimal encoding of a Word16 using the ASCII digits. word16Dec :: Word16 -> Builder -- | Decimal encoding of a Word32 using the ASCII digits. word32Dec :: Word32 -> Builder -- | Decimal encoding of a Word64 using the ASCII digits. word64Dec :: Word64 -> Builder -- | Decimal encoding of a Word using the ASCII digits. wordDec :: Word -> Builder -- | Decimal encoding of an Int8 using the ASCII digits. -- -- e.g. -- --
-- toLazyByteString (int8Dec 42) = "42" -- toLazyByteString (int8Dec (-1)) = "-1" --int8Dec :: Int8 -> Builder -- | Decimal encoding of an Int16 using the ASCII digits. int16Dec :: Int16 -> Builder -- | Decimal encoding of an Int32 using the ASCII digits. int32Dec :: Int32 -> Builder -- | Decimal encoding of an Int64 using the ASCII digits. int64Dec :: Int64 -> Builder -- | Decimal encoding of an Int using the ASCII digits. intDec :: Int -> Builder -- | Decimal encoding of an Integer using the ASCII digits. Simon -- Meier's improved implementation from -- https://github.com/haskell/bytestring/commit/92f19a5d94761042b44a433d7331107611e4d717 integerDec :: Integer -> Builder -- | Shortest hexadecimal encoding of a Word8 using lower-case -- characters. word8Hex :: Word8 -> Builder -- | Shortest hexadecimal encoding of a Word16 using lower-case -- characters. word16Hex :: Word16 -> Builder -- | Shortest hexadecimal encoding of a Word32 using lower-case -- characters. word32Hex :: Word32 -> Builder -- | Shortest hexadecimal encoding of a Word64 using lower-case -- characters. word64Hex :: Word64 -> Builder -- | Shortest hexadecimal encoding of a Word using lower-case -- characters. wordHex :: Word -> Builder -- | Encode a Int8 using 2 nibbles (hexadecimal digits). int8HexFixed :: Int8 -> Builder -- | Encode a Int16 using 4 nibbles. int16HexFixed :: Int16 -> Builder -- | Encode a Int32 using 8 nibbles. int32HexFixed :: Int32 -> Builder -- | Encode a Int64 using 16 nibbles. int64HexFixed :: Int64 -> Builder -- | Encode a Word8 using 2 nibbles (hexadecimal digits). word8HexFixed :: Word8 -> Builder -- | Encode a Word16 using 4 nibbles. word16HexFixed :: Word16 -> Builder -- | Encode a Word32 using 8 nibbles. word32HexFixed :: Word32 -> Builder -- | Encode a Word64 using 16 nibbles. word64HexFixed :: Word64 -> Builder -- | Encode an IEEE Float using 8 nibbles. floatHexFixed :: Float -> Builder -- | Encode an IEEE Double using 16 nibbles. doubleHexFixed :: Double -> Builder -- | Encode each byte of a ByteString using its fixed-width hex -- encoding. byteStringHex :: ByteString -> Builder -- | Encode each byte of a lazy ByteString using its fixed-width hex -- encoding. lazyByteStringHex :: ByteString -> Builder -- | Signed VLQ encoding (the first bit is a sign) intVLQ :: Int -> Builder intVLQBP :: BoundedPrim Int -- | Unsigned VLQ encoding wordVLQ :: Word -> Builder wordVLQBP :: BoundedPrim Word -- | Encode a Word in PrefixVarInt prefixVarInt :: Word -> Builder prefixVarIntBP :: BoundedPrim Word paddedBoundedPrim :: Word8 -> Int -> BoundedPrim a -> a -> Builder zeroPaddedBoundedPrim :: Int -> BoundedPrim a -> a -> Builder -- | Use FixedPrim primFixed :: FixedPrim a -> a -> Builder -- | Use BoundedPrim primBounded :: BoundedPrim a -> a -> Builder -- | Run a builder within a buffer and prefix it by the length. lengthPrefixedWithin :: Int -> BoundedPrim Int -> BuilderFor () -> Builder module Mason.Builder.Dynamic -- | Builder with a fixed set of backends. This helps reducing code size -- and unoptimised code especially on complex/recursive structures, at -- the cost of extensibility. type DynBuilder = BuilderFor DynamicBackend data DynamicBackend DynGrowingBuffer :: !GrowingBuffer -> DynamicBackend DynChannel :: !Channel -> DynamicBackend DynPutEnv :: !PutEnv -> DynamicBackend toStrictByteString :: DynBuilder -> ByteString toLazyByteString :: DynBuilder -> ByteString hPutBuilderLen :: Handle -> DynBuilder -> IO Int hPutBuilder :: Handle -> DynBuilder -> IO () sendBuilder :: Socket -> DynBuilder -> IO Int instance Mason.Builder.Internal.Buildable Mason.Builder.Dynamic.DynamicBackend