{-# LANGUAGE BangPatterns #-} module FlatBuffers.Internal.Build where import Data.ByteString.Builder ( Builder ) import qualified Data.ByteString.Builder as B import Data.Int import Data.Word {-# INLINE buildWord8 #-} buildWord8 :: Word8 -> Builder buildWord8 :: Word8 -> Builder buildWord8 = Word8 -> Builder B.word8 {-# INLINE buildWord16 #-} buildWord16 :: Word16 -> Builder buildWord16 :: Word16 -> Builder buildWord16 = Word16 -> Builder B.word16LE {-# INLINE buildWord32 #-} buildWord32 :: Word32 -> Builder buildWord32 :: Word32 -> Builder buildWord32 = Word32 -> Builder B.word32LE {-# INLINE buildWord64 #-} buildWord64 :: Word64 -> Builder buildWord64 :: Word64 -> Builder buildWord64 = Word64 -> Builder B.word64LE {-# INLINE buildInt8 #-} buildInt8 :: Int8 -> Builder buildInt8 :: Int8 -> Builder buildInt8 = Int8 -> Builder B.int8 {-# INLINE buildInt16 #-} buildInt16 :: Int16 -> Builder buildInt16 :: Int16 -> Builder buildInt16 = Int16 -> Builder B.int16LE {-# INLINE buildInt32 #-} buildInt32 :: Int32 -> Builder buildInt32 :: Int32 -> Builder buildInt32 = Int32 -> Builder B.int32LE {-# INLINE buildInt64 #-} buildInt64 :: Int64 -> Builder buildInt64 :: Int64 -> Builder buildInt64 = Int64 -> Builder B.int64LE {-# INLINE buildFloat #-} buildFloat :: Float -> Builder buildFloat :: Float -> Builder buildFloat = Float -> Builder B.floatLE {-# INLINE buildDouble #-} buildDouble :: Double -> Builder buildDouble :: Double -> Builder buildDouble = Double -> Builder B.doubleLE {-# INLINE buildBool #-} buildBool :: Bool -> Builder buildBool :: Bool -> Builder buildBool = Word8 -> Builder buildWord8 (Word8 -> Builder) -> (Bool -> Word8) -> Bool -> Builder forall b c a. (b -> c) -> (a -> b) -> a -> c . Bool -> Word8 boolToWord8 {-# INLINE buildPadding #-} buildPadding :: Int32 -> Builder buildPadding :: Int32 -> Builder buildPadding !Int32 n = (Int32 -> Builder) -> [Int32] -> Builder forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap (\Int32 _ -> Word8 -> Builder B.word8 Word8 0) [Int32 0..Int32 nInt32 -> Int32 -> Int32 forall a. Num a => a -> a -> a -Int32 1] {-# INLINE boolToWord8 #-} boolToWord8 :: Bool -> Word8 boolToWord8 :: Bool -> Word8 boolToWord8 Bool False = Word8 0 boolToWord8 Bool True = Word8 1