------------------------------------------------------------------------------
-- |
-- Module:      Blaze.ByteString.Builder.Compat.Write
-- Copyright:   (c) 2013 Leon P Smith
-- License:     BSD3
-- Maintainer:  https://github.com/blaze-builder
-- Stability:   stable
--
-- 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 :: forall a. FixedPrim a -> a -> Write
writePrimFixed FixedPrim a
fe a
a = Int -> (Ptr Word8 -> IO ()) -> Write
exactWrite (forall a. FixedPrim a -> Int
size FixedPrim a
fe) (forall a. FixedPrim a -> a -> Ptr Word8 -> IO ()
runF FixedPrim a
fe a
a)
{-# INLINE writePrimFixed #-}

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