{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Haskus.Binary.BufferBuilder
( BufferBuilder
, emptyBufferBuilder
, toBufferList
, toBuffer
, fromBuffer
, fromWord8
)
where
import qualified Data.ByteString.Builder as B
import Haskus.Number.Word
import Haskus.Binary.Buffer
import qualified Haskus.Binary.BufferList as BL
newtype BufferBuilder
= BufferBuilder B.Builder
deriving (Semigroup,Monoid)
emptyBufferBuilder :: BufferBuilder
emptyBufferBuilder = BufferBuilder mempty
fromBuffer :: Buffer -> BufferBuilder
fromBuffer (Buffer bs) = BufferBuilder (B.byteString bs)
fromWord8 :: Word8 -> BufferBuilder
fromWord8 w = BufferBuilder (B.word8 w)
toBufferList :: BufferBuilder -> BL.BufferList
toBufferList (BufferBuilder b) = BL.BufferList (B.toLazyByteString b)
toBuffer :: BufferBuilder -> Buffer
toBuffer = BL.toBuffer . toBufferList