{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Haskus.Binary.Serialize.Put
( PutMonad (..)
, putFloat32
, putFloat32LE
, putFloat32BE
, putFloat64
, putFloat64LE
, putFloat64BE
, putWord16BE
, putWord32BE
, putWord64BE
, putWord16LE
, putWord32LE
, putWord64LE
, putWord16BEs
, putWord32BEs
, putWord64BEs
, putWord16LEs
, putWord32LEs
, putWord64LEs
)
where
import Haskus.Memory.Buffer
import Haskus.Number.Word
import Haskus.Binary.Endianness
import Haskus.Number.Float
import Haskus.Utils.Flow
class Monad m => PutMonad m where
putWord8 :: Word8 -> m ()
putWord16 :: Word16 -> m ()
putWord32 :: Word32 -> m ()
putWord64 :: Word64 -> m ()
putWord8s :: [Word8] -> m ()
putWord8s xs = forM_ xs putWord8
putWord16s :: [Word16] -> m ()
putWord16s xs = forM_ xs putWord16
putWord32s :: [Word32] -> m ()
putWord32s xs = forM_ xs putWord32
putWord64s :: [Word64] -> m ()
putWord64s xs = forM_ xs putWord64
putBuffer :: BufferSize (Buffer Immutable pin gc heap) => Buffer Immutable pin gc heap -> m ()
preAllocateAtLeast :: Word -> m ()
preAllocateAtLeast _ = return ()
putFloat64 :: PutMonad m => Float64 -> m ()
putFloat64 d = putWord64 (float64ToWord64 d)
putFloat64LE :: PutMonad m => Float64 -> m ()
putFloat64LE d = putWord64LE (float64ToWord64 d)
putFloat64BE :: PutMonad m => Float64 -> m ()
putFloat64BE d = putWord64BE (float64ToWord64 d)
putFloat32 :: PutMonad m => Float32 -> m ()
putFloat32 d = putWord32 (float32ToWord32 d)
putFloat32LE :: PutMonad m => Float32 -> m ()
putFloat32LE d = putWord32LE (float32ToWord32 d)
putFloat32BE :: PutMonad m => Float32 -> m ()
putFloat32BE d = putWord32BE (float32ToWord32 d)
putWord16LE :: PutMonad m => Word16 -> m ()
putWord16LE x = putWord16 (hostToLittleEndian x)
putWord32LE :: PutMonad m => Word32 -> m ()
putWord32LE x = putWord32 (hostToLittleEndian x)
putWord64LE :: PutMonad m => Word64 -> m ()
putWord64LE x = putWord64 (hostToLittleEndian x)
putWord16BE :: PutMonad m => Word16 -> m ()
putWord16BE x = putWord16 (hostToBigEndian x)
putWord32BE :: PutMonad m => Word32 -> m ()
putWord32BE x = putWord32 (hostToBigEndian x)
putWord64BE :: PutMonad m => Word64 -> m ()
putWord64BE x = putWord64 (hostToBigEndian x)
putWord16LEs :: PutMonad m => [Word16] -> m ()
putWord16LEs xs = putWord16s (fmap hostToLittleEndian xs)
putWord32LEs :: PutMonad m => [Word32] -> m ()
putWord32LEs xs = putWord32s (fmap hostToLittleEndian xs)
putWord64LEs :: PutMonad m => [Word64] -> m ()
putWord64LEs xs = putWord64s (fmap hostToLittleEndian xs)
putWord16BEs :: PutMonad m => [Word16] -> m ()
putWord16BEs xs = putWord16s (fmap hostToBigEndian xs)
putWord32BEs :: PutMonad m => [Word32] -> m ()
putWord32BEs xs = putWord32s (fmap hostToBigEndian xs)
putWord64BEs :: PutMonad m => [Word64] -> m ()
putWord64BEs xs = putWord64s (fmap hostToBigEndian xs)