------------------------------------------------------------------------------
-- |
-- Module:      Blaze.ByteString.Builder.Compat.Write
-- Copyright:   (c) 2013 Leon P Smith
-- License:     BSD3
-- Maintainer:  Leon P Smith <leon@melding-monads.com>
-- Stability:   experimental
--
-- Conversions from the new Prims to the old Writes.
--
------------------------------------------------------------------------------

module Blaze.ByteString.Builder.Compat.Write
    ( Write
    , writePrimFixed
    , writePrimBounded
    ) where

import Data.ByteString.Builder.Prim.Internal (BoundedPrim, FixedPrim
                                             , runB, runF, size, sizeBound)
import Blaze.ByteString.Builder.Internal.Write (Poke(..), Write
                                               , boundedWrite, exactWrite)

writePrimFixed :: FixedPrim a -> a -> Write
writePrimFixed :: FixedPrim a -> a -> Write
writePrimFixed fe :: FixedPrim a
fe a :: a
a = Int -> (Ptr Word8 -> IO ()) -> Write
exactWrite (FixedPrim a -> Int
forall a. FixedPrim a -> Int
size FixedPrim a
fe) (FixedPrim a -> a -> Ptr Word8 -> IO ()
forall a. FixedPrim a -> a -> Ptr Word8 -> IO ()
runF FixedPrim a
fe a
a)
{-# INLINE writePrimFixed #-}

writePrimBounded :: BoundedPrim a -> a -> Write
writePrimBounded :: BoundedPrim a -> a -> Write
writePrimBounded be :: BoundedPrim a
be a :: a
a = Int -> Poke -> Write
boundedWrite (BoundedPrim a -> Int
forall a. BoundedPrim a -> Int
sizeBound BoundedPrim a
be) ((Ptr Word8 -> IO (Ptr Word8)) -> Poke
Poke (BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim a
be a
a))
{-# INLINE writePrimBounded #-}