{-# OPTIONS_GHC -fno-cse #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Graphics.PDF.LowLevel.Serializer(
SerializeValue(..)
) where
import qualified Data.ByteString.Lazy as B
import qualified Data.Binary.Builder as BU
import qualified Data.ByteString.Lazy.Char8 as C
import Data.ByteString.Internal (c2w)
import Data.Word (Word8)
import Text.Printf (printf)
class (Monoid s) => SerializeValue s a where
serialize :: a -> s
cons :: a -> s -> s
cons a
a s
b = (a -> s
forall s a. SerializeValue s a => a -> s
serialize a
a) s -> s -> s
forall a. Monoid a => a -> a -> a
`mappend` s
b
instance SerializeValue B.ByteString Word8 where
serialize :: Word8 -> ByteString
serialize = Word8 -> ByteString
B.singleton
cons :: Word8 -> ByteString -> ByteString
cons = Word8 -> ByteString -> ByteString
B.cons
instance SerializeValue B.ByteString Char where
serialize :: Char -> ByteString
serialize = Char -> ByteString
C.singleton
cons :: Char -> ByteString -> ByteString
cons = Char -> ByteString -> ByteString
C.cons
instance SerializeValue B.ByteString [Char] where
serialize :: [Char] -> ByteString
serialize = [Char] -> ByteString
C.pack
instance SerializeValue B.ByteString B.ByteString where
serialize :: ByteString -> ByteString
serialize = ByteString -> ByteString
forall a. a -> a
id
instance SerializeValue B.ByteString Int where
serialize :: Int -> ByteString
serialize = [Char] -> ByteString
C.pack ([Char] -> ByteString) -> (Int -> [Char]) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Char]
forall a. Show a => a -> [Char]
show
instance SerializeValue B.ByteString Double where
serialize :: Double -> ByteString
serialize = [Char] -> ByteString
C.pack ([Char] -> ByteString)
-> (Double -> [Char]) -> Double -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Double -> [Char]
forall r. PrintfType r => [Char] -> r
printf [Char]
"%.5f"
instance SerializeValue BU.Builder Word8 where
serialize :: Word8 -> Builder
serialize = Word8 -> Builder
BU.singleton
instance SerializeValue BU.Builder Char where
serialize :: Char -> Builder
serialize = Word8 -> Builder
BU.singleton (Word8 -> Builder) -> (Char -> Word8) -> Char -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Word8
c2w
instance SerializeValue BU.Builder [Char] where
serialize :: [Char] -> Builder
serialize = ByteString -> Builder
BU.fromLazyByteString (ByteString -> Builder)
-> ([Char] -> ByteString) -> [Char] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> ByteString
forall s a. SerializeValue s a => a -> s
serialize
instance SerializeValue BU.Builder B.ByteString where
serialize :: ByteString -> Builder
serialize = ByteString -> Builder
BU.fromLazyByteString
instance SerializeValue BU.Builder Int where
serialize :: Int -> Builder
serialize = ByteString -> Builder
BU.fromLazyByteString (ByteString -> Builder) -> (Int -> ByteString) -> Int -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ByteString
forall s a. SerializeValue s a => a -> s
serialize
instance SerializeValue BU.Builder Double where
serialize :: Double -> Builder
serialize = ByteString -> Builder
BU.fromLazyByteString (ByteString -> Builder)
-> (Double -> ByteString) -> Double -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ByteString
forall s a. SerializeValue s a => a -> s
serialize