{-# LANGUAGE CPP, BangPatterns #-}
{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-orphans #-}
#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Builder
(
Builder
, toLazyByteString
, hPutBuilder
, byteString
, lazyByteString
, shortByteString
, int8
, word8
, int16BE
, int32BE
, int64BE
, word16BE
, word32BE
, word64BE
, floatBE
, doubleBE
, int16LE
, int32LE
, int64LE
, word16LE
, word32LE
, word64LE
, floatLE
, doubleLE
, char7
, string7
, char8
, string8
, charUtf8
, stringUtf8
, module Data.ByteString.Builder.ASCII
) where
import Data.ByteString.Builder.Internal
import qualified Data.ByteString.Builder.Prim as P
import qualified Data.ByteString.Lazy.Internal as L
import Data.ByteString.Builder.ASCII
import Data.String (IsString(..))
import System.IO (Handle)
import Foreign
import qualified Data.ByteString as S (concat)
import Data.Monoid
import Data.Foldable (foldMap)
import Data.List (intersperse)
{-# NOINLINE toLazyByteString #-}
toLazyByteString :: Builder -> L.ByteString
toLazyByteString = toLazyByteStringWith
(safeStrategy L.smallChunkSize L.defaultChunkSize) L.Empty
hPutBuilder :: Handle -> Builder -> IO ()
hPutBuilder h = hPut h . putBuilder
{-# INLINE int8 #-}
int8 :: Int8 -> Builder
int8 = P.primFixed P.int8
{-# INLINE word8 #-}
word8 :: Word8 -> Builder
word8 = P.primFixed P.word8
{-# INLINE int16LE #-}
int16LE :: Int16 -> Builder
int16LE = P.primFixed P.int16LE
{-# INLINE int32LE #-}
int32LE :: Int32 -> Builder
int32LE = P.primFixed P.int32LE
{-# INLINE int64LE #-}
int64LE :: Int64 -> Builder
int64LE = P.primFixed P.int64LE
{-# INLINE word16LE #-}
word16LE :: Word16 -> Builder
word16LE = P.primFixed P.word16LE
{-# INLINE word32LE #-}
word32LE :: Word32 -> Builder
word32LE = P.primFixed P.word32LE
{-# INLINE word64LE #-}
word64LE :: Word64 -> Builder
word64LE = P.primFixed P.word64LE
{-# INLINE floatLE #-}
floatLE :: Float -> Builder
floatLE = P.primFixed P.floatLE
{-# INLINE doubleLE #-}
doubleLE :: Double -> Builder
doubleLE = P.primFixed P.doubleLE
{-# INLINE int16BE #-}
int16BE :: Int16 -> Builder
int16BE = P.primFixed P.int16BE
{-# INLINE int32BE #-}
int32BE :: Int32 -> Builder
int32BE = P.primFixed P.int32BE
{-# INLINE int64BE #-}
int64BE :: Int64 -> Builder
int64BE = P.primFixed P.int64BE
{-# INLINE word16BE #-}
word16BE :: Word16 -> Builder
word16BE = P.primFixed P.word16BE
{-# INLINE word32BE #-}
word32BE :: Word32 -> Builder
word32BE = P.primFixed P.word32BE
{-# INLINE word64BE #-}
word64BE :: Word64 -> Builder
word64BE = P.primFixed P.word64BE
{-# INLINE floatBE #-}
floatBE :: Float -> Builder
floatBE = P.primFixed P.floatBE
{-# INLINE doubleBE #-}
doubleBE :: Double -> Builder
doubleBE = P.primFixed P.doubleBE
{-# INLINE char7 #-}
char7 :: Char -> Builder
char7 = P.primFixed P.char7
{-# INLINE string7 #-}
string7 :: String -> Builder
string7 = P.primMapListFixed P.char7
{-# INLINE char8 #-}
char8 :: Char -> Builder
char8 = P.primFixed P.char8
{-# INLINE string8 #-}
string8 :: String -> Builder
string8 = P.primMapListFixed P.char8
{-# INLINE charUtf8 #-}
charUtf8 :: Char -> Builder
charUtf8 = P.primBounded P.charUtf8
{-# INLINE stringUtf8 #-}
stringUtf8 :: String -> Builder
stringUtf8 = P.primMapListBounded P.charUtf8
instance IsString Builder where
fromString = stringUtf8