{-# LANGUAGE CPP #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances #-}

-- | Serialization monoid and serializable types.
module Data.Serializer
  (
  -- * Serialization monoid
    Serializer(..)
  , buildBytes
  , buildByteString
  , buildLazyByteString
  , BinarySerializer(..)
  , CerealSerializer(..)
  -- ** Binary words serialization
  , word16H
  , word32H
  , word64H
  , word
  , wordL
  , wordB
  , wordH
  , int8
  , int16
  , int16L
  , int16B
  , int16H
  , int32
  , int32L
  , int32B
  , int32H
  , int64
  , int64L
  , int64B
  , int64H
  , int
  , intL
  , intB
  , intH
  -- ** Endian serializers
  , LittleEndianSerializer(..)
  , BigEndianSerializer(..)
  , serializeIn
  , serializeH
  -- * Serializable types
  , Serializable(..)
  , putIn
  , putL
  , putB
  , putH
  , toBytes
  , toByteString
  , toLazyByteString
  , SizedSerializable(..)
  , RestSerializable(..)
  ) where

import GHC.Generics (Generic)
import Data.Typeable (Typeable)
import Data.Data (Data)
import Data.Proxy (Proxy(..))
#if !MIN_VERSION_base(4,13,0)
import Data.Semigroup (Semigroup, (<>))
import Data.Monoid (Monoid)
#endif
import Data.Endian (Endian(..), swapEndian)
import Data.Word
import Data.Int
import Data.Bits (shiftR)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as SBS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Builder as BB
import qualified Data.Binary.Put as B
import qualified Data.Serialize.Put as S

-- | Serialization monoid.
class (Semigroup s, Monoid s)  Serializer s where
  {-# MINIMAL word8 #-}
  -- | Default byte order of the serializer.
  endian  Proxy s  Endian
#ifdef WORDS_BIGENDIAN
  endian _ = BigEndian
#else
  endian Proxy s
_ = Endian
LittleEndian
#endif
  {-# INLINE endian #-}
  -- | Serialize a byte. 'word8' /x/ = 'byteString' ('BS.singleton' /x/)
  word8  Word8  s
  -- | Serialize an unsigned 16-bit integer in the default byte order.
  word16  Word16  s
  word16 = Endian -> Word16 -> s
forall s α. (Serializer s, Serializable α) => Endian -> α -> s
putIn (Proxy s -> Endian
forall s. Serializer s => Proxy s -> Endian
endian (Proxy s
forall k (t :: k). Proxy t
Proxy  Proxy s))
  {-# INLINE word16 #-}
  -- | Serialize an unsigned 32-bit integer in the default byte order.
  word32  Word32  s
  word32 = Endian -> Word32 -> s
forall s α. (Serializer s, Serializable α) => Endian -> α -> s
putIn (Proxy s -> Endian
forall s. Serializer s => Proxy s -> Endian
endian (Proxy s
forall k (t :: k). Proxy t
Proxy  Proxy s))
  {-# INLINE word32 #-}
  -- | Serialize an unsigned 64-bit integer in the default byte order.
  word64  Word64  s
  word64 = Endian -> Word64 -> s
forall s α. (Serializer s, Serializable α) => Endian -> α -> s
putIn (Proxy s -> Endian
forall s. Serializer s => Proxy s -> Endian
endian (Proxy s
forall k (t :: k). Proxy t
Proxy  Proxy s))
  {-# INLINE word64 #-}
  -- | Serialize an unsigned 16-bit integer in little endian.
  word16L  Word16  s
  word16L Word16
w =  Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word16
w)
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word16 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Int -> Word16
forall a. Bits a => a -> Int -> a
shiftR Word16
w Int
8))
  {-# INLINE word16L #-}
  -- | Serialize an unsigned 16-bit integer in big endian.
  word16B  Word16  s
  word16B = Word16 -> s
forall s. Serializer s => Word16 -> s
word16L (Word16 -> s) -> (Word16 -> Word16) -> Word16 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Word16
forall α. EndianSensitive α => α -> α
swapEndian
  {-# INLINE word16B #-}
  -- | Serialize an unsigned 32-bit integer in little endian.
  word32L  Word32  s
  word32L Word32
w =  Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
w)
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
shiftR Word32
w Int
8))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
shiftR Word32
w Int
16))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word32 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> Int -> Word32
forall a. Bits a => a -> Int -> a
shiftR Word32
w Int
24))
  {-# INLINE word32L #-}
  -- | Serialize an unsigned 32-bit integer in big endian.
  word32B  Word32  s
  word32B = Word32 -> s
forall s. Serializer s => Word32 -> s
word32L (Word32 -> s) -> (Word32 -> Word32) -> Word32 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Word32
forall α. EndianSensitive α => α -> α
swapEndian
  {-# INLINE word32B #-}
  -- | Serialize an unsigned 64-bit integer in little endian.
  word64L  Word64  s
  word64L Word64
w =  Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
w)
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
8))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
16))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
24))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
32))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
40))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
48))
            s -> s -> s
forall a. Semigroup a => a -> a -> a
<> Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word64 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Int -> Word64
forall a. Bits a => a -> Int -> a
shiftR Word64
w Int
56))
  {-# INLINE word64L #-}
  -- | Serialize an unsigned 64-bit integer in big endian.
  word64B  Word64  s
  word64B = Word64 -> s
forall s. Serializer s => Word64 -> s
word64L (Word64 -> s) -> (Word64 -> Word64) -> Word64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall α. EndianSensitive α => α -> α
swapEndian
  {-# INLINE word64B #-}
  -- | Serialize a 'BS.ByteString'. Must be a monoid homomorphism.
  byteString  BS.ByteString  s
  byteString = [s] -> s
forall a. Monoid a => [a] -> a
mconcat ([s] -> s) -> (ByteString -> [s]) -> ByteString -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8 -> s) -> [Word8] -> [s]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word8 -> s
forall s. Serializer s => Word8 -> s
word8 ([Word8] -> [s]) -> (ByteString -> [Word8]) -> ByteString -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [Word8]
BS.unpack
  {-# INLINE byteString #-}
  -- | Serialize a 'SBS.ShortByteString'. Must be a monoid homomorphism.
  shortByteString  SBS.ShortByteString  s
  shortByteString = [s] -> s
forall a. Monoid a => [a] -> a
mconcat ([s] -> s) -> (ShortByteString -> [s]) -> ShortByteString -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word8 -> s) -> [Word8] -> [s]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Word8 -> s
forall s. Serializer s => Word8 -> s
word8 ([Word8] -> [s])
-> (ShortByteString -> [Word8]) -> ShortByteString -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
SBS.unpack
  {-# INLINE shortByteString #-}
  -- | Serialize a lazy 'LBS.ByteString'. Must be a monoid homomorphism.
  lazyByteString  LBS.ByteString  s
  lazyByteString = [s] -> s
forall a. Monoid a => [a] -> a
mconcat ([s] -> s) -> (ByteString -> [s]) -> ByteString -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> s) -> [ByteString] -> [s]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> s
forall s. Serializer s => ByteString -> s
byteString ([ByteString] -> [s])
-> (ByteString -> [ByteString]) -> ByteString -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [ByteString]
LBS.toChunks
  {-# INLINE lazyByteString #-}
  -- | Serialize a 'BB.Builder'. Must be a monoid homomorphism.
  builder  BB.Builder  s
  builder = ByteString -> s
forall s. Serializer s => ByteString -> s
lazyByteString (ByteString -> s) -> (Builder -> ByteString) -> Builder -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BB.toLazyByteString
  {-# INLINE builder #-}

instance Serializer [Word8] where
  word8 :: Word8 -> [Word8]
word8 = Word8 -> [Word8]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
  {-# INLINE word8 #-}

instance Serializer BB.Builder where
  word8 :: Word8 -> Builder
word8 = Word8 -> Builder
BB.word8
  {-# INLINE word8 #-}
  word16L :: Word16 -> Builder
word16L = Word16 -> Builder
BB.word16LE
  {-# INLINE word16L #-}
  word16B :: Word16 -> Builder
word16B = Word16 -> Builder
BB.word16BE
  {-# INLINE word16B #-}
  word32L :: Word32 -> Builder
word32L = Word32 -> Builder
BB.word32LE
  {-# INLINE word32L #-}
  word32B :: Word32 -> Builder
word32B = Word32 -> Builder
BB.word32BE
  {-# INLINE word32B #-}
  word64L :: Word64 -> Builder
word64L = Word64 -> Builder
BB.word64LE
  {-# INLINE word64L #-}
  word64B :: Word64 -> Builder
word64B = Word64 -> Builder
BB.word64BE
  {-# INLINE word64B #-}
  byteString :: ByteString -> Builder
byteString = ByteString -> Builder
BB.byteString
  {-# INLINE byteString #-}
  shortByteString :: ShortByteString -> Builder
shortByteString = ShortByteString -> Builder
BB.shortByteString
  {-# INLINE shortByteString #-}
  lazyByteString :: ByteString -> Builder
lazyByteString = ByteString -> Builder
BB.lazyByteString
  {-# INLINE lazyByteString #-}
  builder :: Builder -> Builder
builder = Builder -> Builder
forall a. a -> a
id
  {-# INLINE builder #-}

-- | A shorthand for @"LBS.unpack' . 'BB.toLazyByteString'@.
buildBytes  BB.Builder  [Word8]
buildBytes :: Builder -> [Word8]
buildBytes = ByteString -> [Word8]
LBS.unpack (ByteString -> [Word8])
-> (Builder -> ByteString) -> Builder -> [Word8]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BB.toLazyByteString

-- | A shorthand for @'LBS.toStrict' . 'BB.toLazyByteString'@.
buildByteString  BB.Builder  BS.ByteString
buildByteString :: Builder -> ByteString
buildByteString = ByteString -> ByteString
LBS.toStrict (ByteString -> ByteString)
-> (Builder -> ByteString) -> Builder -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BB.toLazyByteString
{-# INLINE buildByteString #-}

-- | An alias for @'BB.toLazyByteString'@.
buildLazyByteString  BB.Builder  LBS.ByteString
buildLazyByteString :: Builder -> ByteString
buildLazyByteString = Builder -> ByteString
BB.toLazyByteString
{-# INLINE buildLazyByteString #-}

#if MIN_VERSION_base(4,9,0) && MIN_VERSION_binary(0,8,3)
instance Serializer B.Put where
  word8 :: Word8 -> Put
word8 = Word8 -> Put
B.putWord8
  {-# INLINE word8 #-}
  word16L :: Word16 -> Put
word16L = Word16 -> Put
B.putWord16le
  {-# INLINE word16L #-}
  word16B :: Word16 -> Put
word16B = Word16 -> Put
B.putWord16be
  {-# INLINE word16B #-}
  word32L :: Word32 -> Put
word32L = Word32 -> Put
B.putWord32le
  {-# INLINE word32L #-}
  word32B :: Word32 -> Put
word32B = Word32 -> Put
B.putWord32be
  {-# INLINE word32B #-}
  word64L :: Word64 -> Put
word64L = Word64 -> Put
B.putWord64le
  {-# INLINE word64L #-}
  word64B :: Word64 -> Put
word64B = Word64 -> Put
B.putWord64be
  {-# INLINE word64B #-}
  byteString :: ByteString -> Put
byteString = ByteString -> Put
B.putByteString
  {-# INLINE byteString #-}
  shortByteString :: ShortByteString -> Put
shortByteString = ShortByteString -> Put
B.putShortByteString
  {-# INLINE shortByteString #-}
  lazyByteString :: ByteString -> Put
lazyByteString = ByteString -> Put
B.putLazyByteString
  {-# INLINE lazyByteString #-}
  builder :: Builder -> Put
builder = Builder -> Put
B.putBuilder
  {-# INLINE builder #-}
#endif

-- | A wrapper around the 'B.Put' monoid (to avoid orphan instances).
newtype BinarySerializer = BinarySerializer { BinarySerializer -> Put
binarySerializer  B.Put }
                           deriving ( Typeable, (forall x. BinarySerializer -> Rep BinarySerializer x)
-> (forall x. Rep BinarySerializer x -> BinarySerializer)
-> Generic BinarySerializer
forall x. Rep BinarySerializer x -> BinarySerializer
forall x. BinarySerializer -> Rep BinarySerializer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BinarySerializer x -> BinarySerializer
$cfrom :: forall x. BinarySerializer -> Rep BinarySerializer x
Generic
#if MIN_VERSION_binary(0,8,3)
# if MIN_VERSION_base(4,9,0)
                                    , b -> BinarySerializer -> BinarySerializer
NonEmpty BinarySerializer -> BinarySerializer
BinarySerializer -> BinarySerializer -> BinarySerializer
(BinarySerializer -> BinarySerializer -> BinarySerializer)
-> (NonEmpty BinarySerializer -> BinarySerializer)
-> (forall b.
    Integral b =>
    b -> BinarySerializer -> BinarySerializer)
-> Semigroup BinarySerializer
forall b. Integral b => b -> BinarySerializer -> BinarySerializer
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> BinarySerializer -> BinarySerializer
$cstimes :: forall b. Integral b => b -> BinarySerializer -> BinarySerializer
sconcat :: NonEmpty BinarySerializer -> BinarySerializer
$csconcat :: NonEmpty BinarySerializer -> BinarySerializer
<> :: BinarySerializer -> BinarySerializer -> BinarySerializer
$c<> :: BinarySerializer -> BinarySerializer -> BinarySerializer
Semigroup
# endif
                                    , Semigroup BinarySerializer
BinarySerializer
Semigroup BinarySerializer
-> BinarySerializer
-> (BinarySerializer -> BinarySerializer -> BinarySerializer)
-> ([BinarySerializer] -> BinarySerializer)
-> Monoid BinarySerializer
[BinarySerializer] -> BinarySerializer
BinarySerializer -> BinarySerializer -> BinarySerializer
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [BinarySerializer] -> BinarySerializer
$cmconcat :: [BinarySerializer] -> BinarySerializer
mappend :: BinarySerializer -> BinarySerializer -> BinarySerializer
$cmappend :: BinarySerializer -> BinarySerializer -> BinarySerializer
mempty :: BinarySerializer
$cmempty :: BinarySerializer
$cp1Monoid :: Semigroup BinarySerializer
Monoid
#endif
                                    )

#if !MIN_VERSION_base(4,9,0) || !MIN_VERSION_binary(0,8,3)
instance Semigroup BinarySerializer where
  s₁ <> s₂ = BinarySerializer $ binarySerializer s₁ >> binarySerializer s₂
  {-# INLINE (<>) #-}
#endif

#if !MIN_VERSION_binary(0,8,3)
instance Monoid BinarySerializer where
  mempty = BinarySerializer $ return ()
  {-# INLINE mempty #-}
  mappend = (<>)
  {-# INLINE mappend #-}
#endif

instance Serializer BinarySerializer where
  word8 :: Word8 -> BinarySerializer
word8 = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word8 -> Put) -> Word8 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Put
B.putWord8
  {-# INLINE word8 #-}
  word16L :: Word16 -> BinarySerializer
word16L = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word16 -> Put) -> Word16 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Put
B.putWord16le
  {-# INLINE word16L #-}
  word16B :: Word16 -> BinarySerializer
word16B = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word16 -> Put) -> Word16 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Put
B.putWord16be
  {-# INLINE word16B #-}
  word32L :: Word32 -> BinarySerializer
word32L = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word32 -> Put) -> Word32 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Put
B.putWord32le
  {-# INLINE word32L #-}
  word32B :: Word32 -> BinarySerializer
word32B = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word32 -> Put) -> Word32 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Put
B.putWord32be
  {-# INLINE word32B #-}
  word64L :: Word64 -> BinarySerializer
word64L = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word64 -> Put) -> Word64 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Put
B.putWord64le
  {-# INLINE word64L #-}
  word64B :: Word64 -> BinarySerializer
word64B = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Word64 -> Put) -> Word64 -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Put
B.putWord64be
  {-# INLINE word64B #-}
  byteString :: ByteString -> BinarySerializer
byteString = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (ByteString -> Put) -> ByteString -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Put
B.putByteString
  {-# INLINE byteString #-}
#if MIN_VERSION_binary(0,8,1)
  shortByteString :: ShortByteString -> BinarySerializer
shortByteString = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (ShortByteString -> Put) -> ShortByteString -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Put
B.putShortByteString
  {-# INLINE shortByteString #-}
#endif
  lazyByteString :: ByteString -> BinarySerializer
lazyByteString = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (ByteString -> Put) -> ByteString -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Put
B.putLazyByteString
  {-# INLINE lazyByteString #-}
#if MIN_VERSION_binary(0,8,3)
  builder :: Builder -> BinarySerializer
builder = Put -> BinarySerializer
BinarySerializer (Put -> BinarySerializer)
-> (Builder -> Put) -> Builder -> BinarySerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Put
B.putBuilder
  {-# INLINE builder #-}
#endif

-- | A wrapper around the 'S.Put' monoid (to avoid orphan instances).
newtype CerealSerializer = CerealSerializer { CerealSerializer -> Put
cerealSerializer  S.Put }
                           deriving ( Typeable, (forall x. CerealSerializer -> Rep CerealSerializer x)
-> (forall x. Rep CerealSerializer x -> CerealSerializer)
-> Generic CerealSerializer
forall x. Rep CerealSerializer x -> CerealSerializer
forall x. CerealSerializer -> Rep CerealSerializer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CerealSerializer x -> CerealSerializer
$cfrom :: forall x. CerealSerializer -> Rep CerealSerializer x
Generic
#if MIN_VERSION_cereal(0,5,3)
                                    , Semigroup CerealSerializer
CerealSerializer
Semigroup CerealSerializer
-> CerealSerializer
-> (CerealSerializer -> CerealSerializer -> CerealSerializer)
-> ([CerealSerializer] -> CerealSerializer)
-> Monoid CerealSerializer
[CerealSerializer] -> CerealSerializer
CerealSerializer -> CerealSerializer -> CerealSerializer
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [CerealSerializer] -> CerealSerializer
$cmconcat :: [CerealSerializer] -> CerealSerializer
mappend :: CerealSerializer -> CerealSerializer -> CerealSerializer
$cmappend :: CerealSerializer -> CerealSerializer -> CerealSerializer
mempty :: CerealSerializer
$cmempty :: CerealSerializer
$cp1Monoid :: Semigroup CerealSerializer
Monoid
#endif
                                    )

instance Semigroup CerealSerializer where
  CerealSerializer
s₁ <> :: CerealSerializer -> CerealSerializer -> CerealSerializer
<> CerealSerializer
s₂ = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer) -> Put -> CerealSerializer
forall a b. (a -> b) -> a -> b
$ CerealSerializer -> Put
cerealSerializer CerealSerializer
s₁ Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CerealSerializer -> Put
cerealSerializer CerealSerializer
s₂
  {-# INLINE (<>) #-}

#if !MIN_VERSION_cereal(0,5,3)
instance Monoid CerealSerializer where
  mempty = CerealSerializer $ return ()
  {-# INLINE mempty #-}
  mappend = (<>)
  {-# INLINE mappend #-}
#endif

instance Serializer CerealSerializer where
  word8 :: Word8 -> CerealSerializer
word8 = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word8 -> Put) -> Word8 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Put
S.putWord8
  {-# INLINE word8 #-}
  word16L :: Word16 -> CerealSerializer
word16L = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word16 -> Put) -> Word16 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Put
S.putWord16le
  {-# INLINE word16L #-}
  word16B :: Word16 -> CerealSerializer
word16B = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word16 -> Put) -> Word16 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Put
S.putWord16be
  {-# INLINE word16B #-}
  word32L :: Word32 -> CerealSerializer
word32L = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word32 -> Put) -> Word32 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Put
S.putWord32le
  {-# INLINE word32L #-}
  word32B :: Word32 -> CerealSerializer
word32B = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word32 -> Put) -> Word32 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Put
S.putWord32be
  {-# INLINE word32B #-}
  word64L :: Word64 -> CerealSerializer
word64L = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word64 -> Put) -> Word64 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Put
S.putWord64le
  {-# INLINE word64L #-}
  word64B :: Word64 -> CerealSerializer
word64B = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Word64 -> Put) -> Word64 -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Put
S.putWord64be
  {-# INLINE word64B #-}
  byteString :: ByteString -> CerealSerializer
byteString = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (ByteString -> Put) -> ByteString -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Put
S.putByteString
  {-# INLINE byteString #-}
#if MIN_VERSION_cereal(0,5,0)
  shortByteString :: ShortByteString -> CerealSerializer
shortByteString = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (ShortByteString -> Put) -> ShortByteString -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Put
S.putShortByteString
  {-# INLINE shortByteString #-}
#endif
  lazyByteString :: ByteString -> CerealSerializer
lazyByteString = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (ByteString -> Put) -> ByteString -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Put
S.putLazyByteString
  {-# INLINE lazyByteString #-}
#if MIN_VERSION_cereal(0,5,0)
  builder :: Builder -> CerealSerializer
builder = Put -> CerealSerializer
CerealSerializer (Put -> CerealSerializer)
-> (Builder -> Put) -> Builder -> CerealSerializer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> Put
S.putBuilder
  {-# INLINE builder #-}
#endif

-- | Serialize an usigned 16-bit integer in host byte order.
word16H  Serializer s  Word16  s
#ifdef WORDS_BIGENDIAN
word16H = word16B
#else
word16H :: Word16 -> s
word16H = Word16 -> s
forall s. Serializer s => Word16 -> s
word16L
#endif
{-# INLINE word16H #-}

-- | Serialize an unsigned 32-bit integer in host byte order.
word32H  Serializer s  Word32  s
#ifdef WORDS_BIGENDIAN
word32H = word32B
#else
word32H :: Word32 -> s
word32H = Word32 -> s
forall s. Serializer s => Word32 -> s
word32L
#endif
{-# INLINE word32H #-}

-- | Serialize an unsigned 64-bit integer in host byte order.
word64H  Serializer s  Word64  s
#ifdef WORDS_BIGENDIAN
word64H = word64B
#else
word64H :: Word64 -> s
word64H = Word64 -> s
forall s. Serializer s => Word64 -> s
word64L
#endif
{-# INLINE word64H #-}

-- | Serialize an unsigned native-sized integer in serializer default
--   byte order.
word  Serializer s  Word  s
#ifdef WORDS_BIGENDIAN
word = wordB
#else
word :: Word -> s
word = Word -> s
forall s. Serializer s => Word -> s
wordL
#endif
{-# INLINE word #-}

-- | Serialize an unsigned native-sized integer in little endian.
wordL  Serializer s  Word  s
#if WORD_SIZE_IN_BITS == 32
wordL = word32L . fromIntegral
#else
wordL :: Word -> s
wordL = Word64 -> s
forall s. Serializer s => Word64 -> s
word64L (Word64 -> s) -> (Word -> Word64) -> Word -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE wordL #-}

-- | Serialize an unsigned native-sized integer in big endian.
wordB  Serializer s  Word  s
#if WORD_SIZE_IN_BITS == 32
wordB = word32B . fromIntegral
#else
wordB :: Word -> s
wordB = Word64 -> s
forall s. Serializer s => Word64 -> s
word64B (Word64 -> s) -> (Word -> Word64) -> Word -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE wordB #-}

-- | Serialize an unsigned native-sized integer in host byte order.
wordH  Serializer s  Word  s
#if WORD_SIZE_IN_BITS == 32
wordH = word32H . fromIntegral
#else
wordH :: Word -> s
wordH = Word64 -> s
forall s. Serializer s => Word64 -> s
word64H (Word64 -> s) -> (Word -> Word64) -> Word -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE wordH #-}

-- | Serialize a signed 8-bit integer.
int8  Serializer s  Int8  s
int8 :: Int8 -> s
int8 = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 (Word8 -> s) -> (Int8 -> Word8) -> Int8 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int8 #-}

-- | Serialize a signed 16-bit integer in serializer default byte order.
int16  Serializer s  Int16  s
int16 :: Int16 -> s
int16 = Word16 -> s
forall s. Serializer s => Word16 -> s
word16 (Word16 -> s) -> (Int16 -> Word16) -> Int16 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int16 #-}

-- | Serialize a signed 16-bit integer in little endian.
int16L  Serializer s  Int16  s
int16L :: Int16 -> s
int16L = Word16 -> s
forall s. Serializer s => Word16 -> s
word16L (Word16 -> s) -> (Int16 -> Word16) -> Int16 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int16L #-}

-- | Serialize a signed 16-bit integer in big endian.
int16B  Serializer s  Int16  s
int16B :: Int16 -> s
int16B = Word16 -> s
forall s. Serializer s => Word16 -> s
word16B (Word16 -> s) -> (Int16 -> Word16) -> Int16 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int16B #-}

-- | Serialize a signed 16-bit integer in host byte order.
int16H  Serializer s  Int16  s
#ifdef WORDS_BIGENDIAN
int16H = int16B
#else
int16H :: Int16 -> s
int16H = Int16 -> s
forall s. Serializer s => Int16 -> s
int16L
#endif
{-# INLINE int16H #-}

-- | Serialize a signed 32-bit integer in serializer default byte order.
int32  Serializer s  Int32  s
int32 :: Int32 -> s
int32 = Word32 -> s
forall s. Serializer s => Word32 -> s
word32 (Word32 -> s) -> (Int32 -> Word32) -> Int32 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int32 #-}

-- | Serialize a signed 32-bit integer in little endian.
int32L  Serializer s  Int32  s
int32L :: Int32 -> s
int32L = Word32 -> s
forall s. Serializer s => Word32 -> s
word32L (Word32 -> s) -> (Int32 -> Word32) -> Int32 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int32L #-}

-- | Serialize a signed 32-bit integer in big endian.
int32B  Serializer s  Int32  s
int32B :: Int32 -> s
int32B = Word32 -> s
forall s. Serializer s => Word32 -> s
word32B (Word32 -> s) -> (Int32 -> Word32) -> Int32 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int32B #-}

-- | Serialize a signed 32-bit integer in host byte order.
int32H  Serializer s  Int32  s
#ifdef WORDS_BIGENDIAN
int32H = int32B
#else
int32H :: Int32 -> s
int32H = Int32 -> s
forall s. Serializer s => Int32 -> s
int32L
#endif
{-# INLINE int32H #-}

-- | Serialize a signed 64-bit integer in serializer default byte order.
int64  Serializer s  Int64  s
int64 :: Int64 -> s
int64 = Word64 -> s
forall s. Serializer s => Word64 -> s
word64 (Word64 -> s) -> (Int64 -> Word64) -> Int64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int64 #-}

-- | Serialize a signed 64-bit integer in little endian.
int64L  Serializer s  Int64  s
int64L :: Int64 -> s
int64L = Word64 -> s
forall s. Serializer s => Word64 -> s
word64L (Word64 -> s) -> (Int64 -> Word64) -> Int64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int64L #-}

-- | Serialize a signed 64-bit integer in big endian.
int64B  Serializer s  Int64  s
int64B :: Int64 -> s
int64B = Word64 -> s
forall s. Serializer s => Word64 -> s
word64B (Word64 -> s) -> (Int64 -> Word64) -> Int64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
{-# INLINE int64B #-}

-- | Serialize a signed 64-bit integer in host byte order.
int64H  Serializer s  Int64  s
#ifdef WORDS_BIGENDIAN
int64H = int64B
#else
int64H :: Int64 -> s
int64H = Int64 -> s
forall s. Serializer s => Int64 -> s
int64L
#endif
{-# INLINE int64H #-}

-- | Serialize a signed native-sized integer in serializer default byte order.
int  Serializer s  Int  s
#ifdef WORDS_BIGENDIAN
int = intB
#else
int :: Int -> s
int = Int -> s
forall s. Serializer s => Int -> s
intL
#endif
{-# INLINE int #-}

-- | Serialize a signed native-sized integer in little endian.
intL  Serializer s  Int  s
#if WORD_SIZE_IN_BITS == 32
intL = word32L . fromIntegral
#else
intL :: Int -> s
intL = Word64 -> s
forall s. Serializer s => Word64 -> s
word64L (Word64 -> s) -> (Int -> Word64) -> Int -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE intL #-}

-- | Serialize a signed native-sized integer in big endian.
intB  Serializer s  Int64  s
#if WORD_SIZE_IN_BITS == 32
intB = word32B . fromIntegral
#else
intB :: Int64 -> s
intB = Word64 -> s
forall s. Serializer s => Word64 -> s
word64B (Word64 -> s) -> (Int64 -> Word64) -> Int64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE intB #-}

-- | Serialize a signed native-sized integer in host byte order.
intH  Serializer s  Int  s
#if WORD_SIZE_IN_BITS == 32
intH = word32H . fromIntegral
#else
intH :: Int -> s
intH = Word64 -> s
forall s. Serializer s => Word64 -> s
word64H (Word64 -> s) -> (Int -> Word64) -> Int -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
#endif
{-# INLINE intH #-}

-- | Serializer wrapper with little endian default byte order.
newtype LittleEndianSerializer s = LittleEndianSerializer { LittleEndianSerializer s -> s
serializeL  s }
                                   deriving (Typeable, Typeable (LittleEndianSerializer s)
DataType
Constr
Typeable (LittleEndianSerializer s)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> LittleEndianSerializer s
    -> c (LittleEndianSerializer s))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s))
-> (LittleEndianSerializer s -> Constr)
-> (LittleEndianSerializer s -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d))
    -> Maybe (c (LittleEndianSerializer s)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (LittleEndianSerializer s)))
-> ((forall b. Data b => b -> b)
    -> LittleEndianSerializer s -> LittleEndianSerializer s)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> LittleEndianSerializer s
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> LittleEndianSerializer s
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u])
-> (forall u.
    Int
    -> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> LittleEndianSerializer s -> m (LittleEndianSerializer s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> LittleEndianSerializer s -> m (LittleEndianSerializer s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> LittleEndianSerializer s -> m (LittleEndianSerializer s))
-> Data (LittleEndianSerializer s)
LittleEndianSerializer s -> DataType
LittleEndianSerializer s -> Constr
(forall d. Data d => c (t d))
-> Maybe (c (LittleEndianSerializer s))
(forall b. Data b => b -> b)
-> LittleEndianSerializer s -> LittleEndianSerializer s
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LittleEndianSerializer s
-> c (LittleEndianSerializer s)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s)
forall s. Data s => Typeable (LittleEndianSerializer s)
forall s. Data s => LittleEndianSerializer s -> DataType
forall s. Data s => LittleEndianSerializer s -> Constr
forall s.
Data s =>
(forall b. Data b => b -> b)
-> LittleEndianSerializer s -> LittleEndianSerializer s
forall s u.
Data s =>
Int
-> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u
forall s u.
Data s =>
(forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u]
forall s r r'.
Data s =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
forall s r r'.
Data s =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
forall s (m :: * -> *).
(Data s, Monad m) =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
forall s (c :: * -> *).
Data s =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s)
forall s (c :: * -> *).
Data s =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LittleEndianSerializer s
-> c (LittleEndianSerializer s)
forall s (t :: * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (LittleEndianSerializer s))
forall s (t :: * -> * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LittleEndianSerializer s))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u
forall u.
(forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LittleEndianSerializer s
-> c (LittleEndianSerializer s)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c (LittleEndianSerializer s))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LittleEndianSerializer s))
$cLittleEndianSerializer :: Constr
$tLittleEndianSerializer :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
$cgmapMo :: forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
gmapMp :: (forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
$cgmapMp :: forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
gmapM :: (forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
$cgmapM :: forall s (m :: * -> *).
(Data s, Monad m) =>
(forall d. Data d => d -> m d)
-> LittleEndianSerializer s -> m (LittleEndianSerializer s)
gmapQi :: Int
-> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u
$cgmapQi :: forall s u.
Data s =>
Int
-> (forall d. Data d => d -> u) -> LittleEndianSerializer s -> u
gmapQ :: (forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u]
$cgmapQ :: forall s u.
Data s =>
(forall d. Data d => d -> u) -> LittleEndianSerializer s -> [u]
gmapQr :: (r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
$cgmapQr :: forall s r r'.
Data s =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
gmapQl :: (r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
$cgmapQl :: forall s r r'.
Data s =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> LittleEndianSerializer s
-> r
gmapT :: (forall b. Data b => b -> b)
-> LittleEndianSerializer s -> LittleEndianSerializer s
$cgmapT :: forall s.
Data s =>
(forall b. Data b => b -> b)
-> LittleEndianSerializer s -> LittleEndianSerializer s
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LittleEndianSerializer s))
$cdataCast2 :: forall s (t :: * -> * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LittleEndianSerializer s))
dataCast1 :: (forall d. Data d => c (t d))
-> Maybe (c (LittleEndianSerializer s))
$cdataCast1 :: forall s (t :: * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (LittleEndianSerializer s))
dataTypeOf :: LittleEndianSerializer s -> DataType
$cdataTypeOf :: forall s. Data s => LittleEndianSerializer s -> DataType
toConstr :: LittleEndianSerializer s -> Constr
$ctoConstr :: forall s. Data s => LittleEndianSerializer s -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s)
$cgunfold :: forall s (c :: * -> *).
Data s =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LittleEndianSerializer s)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LittleEndianSerializer s
-> c (LittleEndianSerializer s)
$cgfoldl :: forall s (c :: * -> *).
Data s =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LittleEndianSerializer s
-> c (LittleEndianSerializer s)
$cp1Data :: forall s. Data s => Typeable (LittleEndianSerializer s)
Data, (forall x.
 LittleEndianSerializer s -> Rep (LittleEndianSerializer s) x)
-> (forall x.
    Rep (LittleEndianSerializer s) x -> LittleEndianSerializer s)
-> Generic (LittleEndianSerializer s)
forall x.
Rep (LittleEndianSerializer s) x -> LittleEndianSerializer s
forall x.
LittleEndianSerializer s -> Rep (LittleEndianSerializer s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s x.
Rep (LittleEndianSerializer s) x -> LittleEndianSerializer s
forall s x.
LittleEndianSerializer s -> Rep (LittleEndianSerializer s) x
$cto :: forall s x.
Rep (LittleEndianSerializer s) x -> LittleEndianSerializer s
$cfrom :: forall s x.
LittleEndianSerializer s -> Rep (LittleEndianSerializer s) x
Generic,
                                             b -> LittleEndianSerializer s -> LittleEndianSerializer s
NonEmpty (LittleEndianSerializer s) -> LittleEndianSerializer s
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
(LittleEndianSerializer s
 -> LittleEndianSerializer s -> LittleEndianSerializer s)
-> (NonEmpty (LittleEndianSerializer s)
    -> LittleEndianSerializer s)
-> (forall b.
    Integral b =>
    b -> LittleEndianSerializer s -> LittleEndianSerializer s)
-> Semigroup (LittleEndianSerializer s)
forall b.
Integral b =>
b -> LittleEndianSerializer s -> LittleEndianSerializer s
forall s.
Semigroup s =>
NonEmpty (LittleEndianSerializer s) -> LittleEndianSerializer s
forall s.
Semigroup s =>
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
forall s b.
(Semigroup s, Integral b) =>
b -> LittleEndianSerializer s -> LittleEndianSerializer s
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> LittleEndianSerializer s -> LittleEndianSerializer s
$cstimes :: forall s b.
(Semigroup s, Integral b) =>
b -> LittleEndianSerializer s -> LittleEndianSerializer s
sconcat :: NonEmpty (LittleEndianSerializer s) -> LittleEndianSerializer s
$csconcat :: forall s.
Semigroup s =>
NonEmpty (LittleEndianSerializer s) -> LittleEndianSerializer s
<> :: LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
$c<> :: forall s.
Semigroup s =>
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
Semigroup, Semigroup (LittleEndianSerializer s)
LittleEndianSerializer s
Semigroup (LittleEndianSerializer s)
-> LittleEndianSerializer s
-> (LittleEndianSerializer s
    -> LittleEndianSerializer s -> LittleEndianSerializer s)
-> ([LittleEndianSerializer s] -> LittleEndianSerializer s)
-> Monoid (LittleEndianSerializer s)
[LittleEndianSerializer s] -> LittleEndianSerializer s
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall s. Monoid s => Semigroup (LittleEndianSerializer s)
forall s. Monoid s => LittleEndianSerializer s
forall s.
Monoid s =>
[LittleEndianSerializer s] -> LittleEndianSerializer s
forall s.
Monoid s =>
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
mconcat :: [LittleEndianSerializer s] -> LittleEndianSerializer s
$cmconcat :: forall s.
Monoid s =>
[LittleEndianSerializer s] -> LittleEndianSerializer s
mappend :: LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
$cmappend :: forall s.
Monoid s =>
LittleEndianSerializer s
-> LittleEndianSerializer s -> LittleEndianSerializer s
mempty :: LittleEndianSerializer s
$cmempty :: forall s. Monoid s => LittleEndianSerializer s
$cp1Monoid :: forall s. Monoid s => Semigroup (LittleEndianSerializer s)
Monoid)

instance Serializer s  Serializer (LittleEndianSerializer s) where
  endian :: Proxy (LittleEndianSerializer s) -> Endian
endian Proxy (LittleEndianSerializer s)
_ = Endian
LittleEndian
  {-# INLINE endian #-}
  word8 :: Word8 -> LittleEndianSerializer s
word8 = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word8 -> s) -> Word8 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> s
forall s. Serializer s => Word8 -> s
word8
  {-# INLINE word8 #-}
  word16 :: Word16 -> LittleEndianSerializer s
word16 = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word16 -> s) -> Word16 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16L
  {-# INLINE word16 #-}
  word32 :: Word32 -> LittleEndianSerializer s
word32 = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word32 -> s) -> Word32 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32L
  {-# INLINE word32 #-}
  word64 :: Word64 -> LittleEndianSerializer s
word64 = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word64 -> s) -> Word64 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64L
  {-# INLINE word64 #-}
  word16L :: Word16 -> LittleEndianSerializer s
word16L = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word16 -> s) -> Word16 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16L
  {-# INLINE word16L #-}
  word16B :: Word16 -> LittleEndianSerializer s
word16B = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word16 -> s) -> Word16 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16B
  {-# INLINE word16B #-}
  word32L :: Word32 -> LittleEndianSerializer s
word32L = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word32 -> s) -> Word32 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32L
  {-# INLINE word32L #-}
  word32B :: Word32 -> LittleEndianSerializer s
word32B = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word32 -> s) -> Word32 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32B
  {-# INLINE word32B #-}
  word64L :: Word64 -> LittleEndianSerializer s
word64L = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word64 -> s) -> Word64 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64L
  {-# INLINE word64L #-}
  word64B :: Word64 -> LittleEndianSerializer s
word64B = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Word64 -> s) -> Word64 -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64B
  {-# INLINE word64B #-}
  byteString :: ByteString -> LittleEndianSerializer s
byteString = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (ByteString -> s) -> ByteString -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> s
forall s. Serializer s => ByteString -> s
byteString
  {-# INLINE byteString #-}
  shortByteString :: ShortByteString -> LittleEndianSerializer s
shortByteString = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (ShortByteString -> s)
-> ShortByteString
-> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> s
forall s. Serializer s => ShortByteString -> s
shortByteString
  {-# INLINE shortByteString #-}
  lazyByteString :: ByteString -> LittleEndianSerializer s
lazyByteString = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (ByteString -> s) -> ByteString -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> s
forall s. Serializer s => ByteString -> s
lazyByteString
  {-# INLINE lazyByteString #-}
  builder :: Builder -> LittleEndianSerializer s
builder = s -> LittleEndianSerializer s
forall s. s -> LittleEndianSerializer s
LittleEndianSerializer (s -> LittleEndianSerializer s)
-> (Builder -> s) -> Builder -> LittleEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> s
forall s. Serializer s => Builder -> s
builder
  {-# INLINE builder #-}

-- | Serializer wrapper with big endian default byte order.
newtype BigEndianSerializer s = BigEndianSerializer { BigEndianSerializer s -> s
serializeB  s }
                                deriving (Typeable, Typeable (BigEndianSerializer s)
DataType
Constr
Typeable (BigEndianSerializer s)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> BigEndianSerializer s
    -> c (BigEndianSerializer s))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s))
-> (BigEndianSerializer s -> Constr)
-> (BigEndianSerializer s -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (BigEndianSerializer s)))
-> ((forall b. Data b => b -> b)
    -> BigEndianSerializer s -> BigEndianSerializer s)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> BigEndianSerializer s
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> BigEndianSerializer s
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> BigEndianSerializer s -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> BigEndianSerializer s -> m (BigEndianSerializer s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BigEndianSerializer s -> m (BigEndianSerializer s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> BigEndianSerializer s -> m (BigEndianSerializer s))
-> Data (BigEndianSerializer s)
BigEndianSerializer s -> DataType
BigEndianSerializer s -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s))
(forall b. Data b => b -> b)
-> BigEndianSerializer s -> BigEndianSerializer s
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BigEndianSerializer s
-> c (BigEndianSerializer s)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s)
forall s. Data s => Typeable (BigEndianSerializer s)
forall s. Data s => BigEndianSerializer s -> DataType
forall s. Data s => BigEndianSerializer s -> Constr
forall s.
Data s =>
(forall b. Data b => b -> b)
-> BigEndianSerializer s -> BigEndianSerializer s
forall s u.
Data s =>
Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u
forall s u.
Data s =>
(forall d. Data d => d -> u) -> BigEndianSerializer s -> [u]
forall s r r'.
Data s =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
forall s r r'.
Data s =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
forall s (m :: * -> *).
(Data s, Monad m) =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
forall s (c :: * -> *).
Data s =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s)
forall s (c :: * -> *).
Data s =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BigEndianSerializer s
-> c (BigEndianSerializer s)
forall s (t :: * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s))
forall s (t :: * -> * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BigEndianSerializer s))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u
forall u.
(forall d. Data d => d -> u) -> BigEndianSerializer s -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BigEndianSerializer s
-> c (BigEndianSerializer s)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BigEndianSerializer s))
$cBigEndianSerializer :: Constr
$tBigEndianSerializer :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
$cgmapMo :: forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
gmapMp :: (forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
$cgmapMp :: forall s (m :: * -> *).
(Data s, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
gmapM :: (forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
$cgmapM :: forall s (m :: * -> *).
(Data s, Monad m) =>
(forall d. Data d => d -> m d)
-> BigEndianSerializer s -> m (BigEndianSerializer s)
gmapQi :: Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u
$cgmapQi :: forall s u.
Data s =>
Int -> (forall d. Data d => d -> u) -> BigEndianSerializer s -> u
gmapQ :: (forall d. Data d => d -> u) -> BigEndianSerializer s -> [u]
$cgmapQ :: forall s u.
Data s =>
(forall d. Data d => d -> u) -> BigEndianSerializer s -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
$cgmapQr :: forall s r r'.
Data s =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
$cgmapQl :: forall s r r'.
Data s =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BigEndianSerializer s -> r
gmapT :: (forall b. Data b => b -> b)
-> BigEndianSerializer s -> BigEndianSerializer s
$cgmapT :: forall s.
Data s =>
(forall b. Data b => b -> b)
-> BigEndianSerializer s -> BigEndianSerializer s
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BigEndianSerializer s))
$cdataCast2 :: forall s (t :: * -> * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (BigEndianSerializer s))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s))
$cdataCast1 :: forall s (t :: * -> *) (c :: * -> *).
(Data s, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (BigEndianSerializer s))
dataTypeOf :: BigEndianSerializer s -> DataType
$cdataTypeOf :: forall s. Data s => BigEndianSerializer s -> DataType
toConstr :: BigEndianSerializer s -> Constr
$ctoConstr :: forall s. Data s => BigEndianSerializer s -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s)
$cgunfold :: forall s (c :: * -> *).
Data s =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (BigEndianSerializer s)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BigEndianSerializer s
-> c (BigEndianSerializer s)
$cgfoldl :: forall s (c :: * -> *).
Data s =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> BigEndianSerializer s
-> c (BigEndianSerializer s)
$cp1Data :: forall s. Data s => Typeable (BigEndianSerializer s)
Data, (forall x. BigEndianSerializer s -> Rep (BigEndianSerializer s) x)
-> (forall x.
    Rep (BigEndianSerializer s) x -> BigEndianSerializer s)
-> Generic (BigEndianSerializer s)
forall x. Rep (BigEndianSerializer s) x -> BigEndianSerializer s
forall x. BigEndianSerializer s -> Rep (BigEndianSerializer s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s x. Rep (BigEndianSerializer s) x -> BigEndianSerializer s
forall s x. BigEndianSerializer s -> Rep (BigEndianSerializer s) x
$cto :: forall s x. Rep (BigEndianSerializer s) x -> BigEndianSerializer s
$cfrom :: forall s x. BigEndianSerializer s -> Rep (BigEndianSerializer s) x
Generic,
                                          b -> BigEndianSerializer s -> BigEndianSerializer s
NonEmpty (BigEndianSerializer s) -> BigEndianSerializer s
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
(BigEndianSerializer s
 -> BigEndianSerializer s -> BigEndianSerializer s)
-> (NonEmpty (BigEndianSerializer s) -> BigEndianSerializer s)
-> (forall b.
    Integral b =>
    b -> BigEndianSerializer s -> BigEndianSerializer s)
-> Semigroup (BigEndianSerializer s)
forall b.
Integral b =>
b -> BigEndianSerializer s -> BigEndianSerializer s
forall s.
Semigroup s =>
NonEmpty (BigEndianSerializer s) -> BigEndianSerializer s
forall s.
Semigroup s =>
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
forall s b.
(Semigroup s, Integral b) =>
b -> BigEndianSerializer s -> BigEndianSerializer s
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: b -> BigEndianSerializer s -> BigEndianSerializer s
$cstimes :: forall s b.
(Semigroup s, Integral b) =>
b -> BigEndianSerializer s -> BigEndianSerializer s
sconcat :: NonEmpty (BigEndianSerializer s) -> BigEndianSerializer s
$csconcat :: forall s.
Semigroup s =>
NonEmpty (BigEndianSerializer s) -> BigEndianSerializer s
<> :: BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
$c<> :: forall s.
Semigroup s =>
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
Semigroup, Semigroup (BigEndianSerializer s)
BigEndianSerializer s
Semigroup (BigEndianSerializer s)
-> BigEndianSerializer s
-> (BigEndianSerializer s
    -> BigEndianSerializer s -> BigEndianSerializer s)
-> ([BigEndianSerializer s] -> BigEndianSerializer s)
-> Monoid (BigEndianSerializer s)
[BigEndianSerializer s] -> BigEndianSerializer s
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall s. Monoid s => Semigroup (BigEndianSerializer s)
forall s. Monoid s => BigEndianSerializer s
forall s.
Monoid s =>
[BigEndianSerializer s] -> BigEndianSerializer s
forall s.
Monoid s =>
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
mconcat :: [BigEndianSerializer s] -> BigEndianSerializer s
$cmconcat :: forall s.
Monoid s =>
[BigEndianSerializer s] -> BigEndianSerializer s
mappend :: BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
$cmappend :: forall s.
Monoid s =>
BigEndianSerializer s
-> BigEndianSerializer s -> BigEndianSerializer s
mempty :: BigEndianSerializer s
$cmempty :: forall s. Monoid s => BigEndianSerializer s
$cp1Monoid :: forall s. Monoid s => Semigroup (BigEndianSerializer s)
Monoid)

instance Serializer s  Serializer (BigEndianSerializer s) where
  endian :: Proxy (BigEndianSerializer s) -> Endian
endian Proxy (BigEndianSerializer s)
_ = Endian
BigEndian
  {-# INLINE endian #-}
  word8 :: Word8 -> BigEndianSerializer s
word8 = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word8 -> s) -> Word8 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> s
forall s. Serializer s => Word8 -> s
word8
  {-# INLINE word8 #-}
  word16 :: Word16 -> BigEndianSerializer s
word16 = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word16 -> s) -> Word16 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16B
  {-# INLINE word16 #-}
  word32 :: Word32 -> BigEndianSerializer s
word32 = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word32 -> s) -> Word32 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32B
  {-# INLINE word32 #-}
  word64 :: Word64 -> BigEndianSerializer s
word64 = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word64 -> s) -> Word64 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64B
  {-# INLINE word64 #-}
  word16L :: Word16 -> BigEndianSerializer s
word16L = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word16 -> s) -> Word16 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16L
  {-# INLINE word16L #-}
  word16B :: Word16 -> BigEndianSerializer s
word16B = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word16 -> s) -> Word16 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> s
forall s. Serializer s => Word16 -> s
word16B
  {-# INLINE word16B #-}
  word32L :: Word32 -> BigEndianSerializer s
word32L = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word32 -> s) -> Word32 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32L
  {-# INLINE word32L #-}
  word32B :: Word32 -> BigEndianSerializer s
word32B = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word32 -> s) -> Word32 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> s
forall s. Serializer s => Word32 -> s
word32B
  {-# INLINE word32B #-}
  word64L :: Word64 -> BigEndianSerializer s
word64L = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word64 -> s) -> Word64 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64L
  {-# INLINE word64L #-}
  word64B :: Word64 -> BigEndianSerializer s
word64B = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Word64 -> s) -> Word64 -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> s
forall s. Serializer s => Word64 -> s
word64B
  {-# INLINE word64B #-}
  byteString :: ByteString -> BigEndianSerializer s
byteString = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (ByteString -> s) -> ByteString -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> s
forall s. Serializer s => ByteString -> s
byteString
  {-# INLINE byteString #-}
  shortByteString :: ShortByteString -> BigEndianSerializer s
shortByteString = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (ShortByteString -> s)
-> ShortByteString
-> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> s
forall s. Serializer s => ShortByteString -> s
shortByteString
  {-# INLINE shortByteString #-}
  lazyByteString :: ByteString -> BigEndianSerializer s
lazyByteString = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (ByteString -> s) -> ByteString -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> s
forall s. Serializer s => ByteString -> s
lazyByteString
  {-# INLINE lazyByteString #-}
  builder :: Builder -> BigEndianSerializer s
builder = s -> BigEndianSerializer s
forall s. s -> BigEndianSerializer s
BigEndianSerializer (s -> BigEndianSerializer s)
-> (Builder -> s) -> Builder -> BigEndianSerializer s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> s
forall s. Serializer s => Builder -> s
builder
  {-# INLINE builder #-}

-- | Force the default byte order.
serializeIn  Serializer s  Endian  ( s' . (Serializer s')  s')  s
serializeIn :: Endian -> (forall s'. Serializer s' => s') -> s
serializeIn Endian
LittleEndian forall s'. Serializer s' => s'
s = LittleEndianSerializer s -> s
forall s. LittleEndianSerializer s -> s
serializeL LittleEndianSerializer s
forall s'. Serializer s' => s'
s
serializeIn Endian
BigEndian    forall s'. Serializer s' => s'
s = BigEndianSerializer s -> s
forall s. BigEndianSerializer s -> s
serializeB BigEndianSerializer s
forall s'. Serializer s' => s'
s
{-# INLINE serializeIn #-}

-- | Force the default byte order to be the host byte order.
serializeH  Serializer s  ( s' . (Serializer s')  s')  s
#ifdef WORDS_BIGENDIAN
serializeH s = serializeB s
#else
serializeH :: (forall s'. Serializer s' => s') -> s
serializeH forall s'. Serializer s' => s'
s = LittleEndianSerializer s -> s
forall s. LittleEndianSerializer s -> s
serializeL LittleEndianSerializer s
forall s'. Serializer s' => s'
s
#endif
{-# INLINE serializeH #-}

-- | Serializable type. 'put' must work under assumption that it will be
--   followed by more output.
class Serializable α where
  put  Serializer s  α  s

instance Serializable Bool where
  put :: Bool -> s
put Bool
False = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
0
  put Bool
True  = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
1
  {-# INLINE put #-}

instance Serializable Word8 where
  put :: Word8 -> s
put = Word8 -> s
forall s. Serializer s => Word8 -> s
word8
  {-# INLINE put #-}

instance Serializable Word16 where
  put :: Word16 -> s
put = Word16 -> s
forall s. Serializer s => Word16 -> s
word16
  {-# INLINE put #-}

instance Serializable Word32 where
  put :: Word32 -> s
put = Word32 -> s
forall s. Serializer s => Word32 -> s
word32
  {-# INLINE put #-}

instance Serializable Word64 where
  put :: Word64 -> s
put = Word64 -> s
forall s. Serializer s => Word64 -> s
word64
  {-# INLINE put #-}

instance Serializable Word where
  put :: Word -> s
put = Word -> s
forall s. Serializer s => Word -> s
word
  {-# INLINE put #-}

instance Serializable Int8 where
  put :: Int8 -> s
put = Int8 -> s
forall s. Serializer s => Int8 -> s
int8
  {-# INLINE put #-}

instance Serializable Int16 where
  put :: Int16 -> s
put = Word16 -> s
forall s. Serializer s => Word16 -> s
word16 (Word16 -> s) -> (Int16 -> Word16) -> Int16 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  {-# INLINE put #-}

instance Serializable Int32 where
  put :: Int32 -> s
put = Word32 -> s
forall s. Serializer s => Word32 -> s
word32 (Word32 -> s) -> (Int32 -> Word32) -> Int32 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  {-# INLINE put #-}

instance Serializable Int64 where
  put :: Int64 -> s
put = Word64 -> s
forall s. Serializer s => Word64 -> s
word64 (Word64 -> s) -> (Int64 -> Word64) -> Int64 -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
  {-# INLINE put #-}

instance Serializable Int where
  put :: Int -> s
put = Int -> s
forall s. Serializer s => Int -> s
int
  {-# INLINE put #-}

instance (Serializable α, Serializable β)  Serializable (α, β) where
  put :: (α, β) -> s
put (α
a, β
b) = α -> s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a s -> s -> s
forall a. Semigroup a => a -> a -> a
<> β -> s
forall α s. (Serializable α, Serializer s) => α -> s
put β
b
  {-# INLINE put #-}

instance Serializable α  Serializable (Maybe α) where
  put :: Maybe α -> s
put Maybe α
Nothing  = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
0
  put (Just α
a) = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
1 s -> s -> s
forall a. Semigroup a => a -> a -> a
<> α -> s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a

instance (Serializable α, Serializable β)  Serializable (Either α β) where
  put :: Either α β -> s
put (Left α
a)  = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
0 s -> s -> s
forall a. Semigroup a => a -> a -> a
<> α -> s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a
  put (Right β
b) = Word8 -> s
forall s. Serializer s => Word8 -> s
word8 Word8
1 s -> s -> s
forall a. Semigroup a => a -> a -> a
<> β -> s
forall α s. (Serializable α, Serializer s) => α -> s
put β
b

instance Serializable BS.ByteString where
  put :: ByteString -> s
put ByteString
bs = Int -> s
forall s. Serializer s => Int -> s
int (ByteString -> Int
BS.length ByteString
bs) s -> s -> s
forall a. Semigroup a => a -> a -> a
<> ByteString -> s
forall s. Serializer s => ByteString -> s
byteString ByteString
bs

instance Serializable SBS.ShortByteString where
  put :: ShortByteString -> s
put ShortByteString
bs = Int -> s
forall s. Serializer s => Int -> s
int (ShortByteString -> Int
SBS.length ShortByteString
bs) s -> s -> s
forall a. Semigroup a => a -> a -> a
<> ShortByteString -> s
forall s. Serializer s => ShortByteString -> s
shortByteString ShortByteString
bs

-- | Serialize a value using the provided default byte order.
putIn  (Serializer s, Serializable α)  Endian  α  s
putIn :: Endian -> α -> s
putIn Endian
e α
a = Endian -> (forall s'. Serializer s' => s') -> s
forall s.
Serializer s =>
Endian -> (forall s'. Serializer s' => s') -> s
serializeIn Endian
e (α -> s'
forall α s. (Serializable α, Serializer s) => α -> s
put α
a)
{-# INLINE putIn #-}

-- | Serialize a value using little endian as the default byte order.
putL  (Serializer s, Serializable α)  α  s
putL :: α -> s
putL α
a = LittleEndianSerializer s -> s
forall s. LittleEndianSerializer s -> s
serializeL (α -> LittleEndianSerializer s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a)
{-# INLINE putL #-}

-- | Serialize a value using big endian as the default byte order.
putB  (Serializer s, Serializable α)  α  s
putB :: α -> s
putB α
a = BigEndianSerializer s -> s
forall s. BigEndianSerializer s -> s
serializeB (α -> BigEndianSerializer s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a)
{-# INLINE putB #-}

-- | Serialize a value using host byte order as the default byte order.
putH  (Serializer s, Serializable α)  α  s
putH :: α -> s
putH α
a = (forall s'. Serializer s' => s') -> s
forall s. Serializer s => (forall s'. Serializer s' => s') -> s
serializeH (α -> s'
forall α s. (Serializable α, Serializer s) => α -> s
put α
a)
{-# INLINE putH #-}

-- | A shorthand for @'buildBytes' . 'put'@.
toBytes  Serializable α  α  [Word8]
toBytes :: α -> [Word8]
toBytes = Builder -> [Word8]
buildBytes (Builder -> [Word8]) -> (α -> Builder) -> α -> [Word8]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Builder
forall α s. (Serializable α, Serializer s) => α -> s
put
{-# INLINE toBytes #-}

-- | A shorthand for @'buildByteString' . 'put'@.
toByteString  Serializable α  α  BS.ByteString
toByteString :: α -> ByteString
toByteString = Builder -> ByteString
buildByteString (Builder -> ByteString) -> (α -> Builder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Builder
forall α s. (Serializable α, Serializer s) => α -> s
put
{-# INLINE toByteString #-}

-- | A shorthand for @'buildLazyByteString' . 'put'@.
toLazyByteString  Serializable α  α  LBS.ByteString
toLazyByteString :: α -> ByteString
toLazyByteString = Builder -> ByteString
BB.toLazyByteString (Builder -> ByteString) -> (α -> Builder) -> α -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. α -> Builder
forall α s. (Serializable α, Serializer s) => α -> s
put
{-# INLINE toLazyByteString #-}

-- | Types with fixed serialized size.
class Serializable α  SizedSerializable α where
  -- | Serialized size in bytes.
  size  Proxy α  Int

instance SizedSerializable Bool where
  size :: Proxy Bool -> Int
size Proxy Bool
_ = Int
1
  {-# INLINE size #-}

instance SizedSerializable Word8 where
  size :: Proxy Word8 -> Int
size Proxy Word8
_ = Int
1
  {-# INLINE size #-}

instance SizedSerializable Word16 where
  size :: Proxy Word16 -> Int
size Proxy Word16
_ = Int
2
  {-# INLINE size #-}

instance SizedSerializable Word32 where
  size :: Proxy Word32 -> Int
size Proxy Word32
_ = Int
4
  {-# INLINE size #-}

instance SizedSerializable Word64 where
  size :: Proxy Word64 -> Int
size Proxy Word64
_ = Int
8
  {-# INLINE size #-}

instance SizedSerializable Word where
#if WORD_SIZE_IN_BITS == 32
  size _ = 4
#else
  size :: Proxy Word -> Int
size Proxy Word
_ = Int
8
#endif
  {-# INLINE size #-}

instance SizedSerializable Int8 where
  size :: Proxy Int8 -> Int
size Proxy Int8
_ = Int
1
  {-# INLINE size #-}

instance SizedSerializable Int16 where
  size :: Proxy Int16 -> Int
size Proxy Int16
_ = Int
2
  {-# INLINE size #-}

instance SizedSerializable Int32 where
  size :: Proxy Int32 -> Int
size Proxy Int32
_ = Int
4
  {-# INLINE size #-}

instance SizedSerializable Int64 where
  size :: Proxy Int64 -> Int
size Proxy Int64
_ = Int
8
  {-# INLINE size #-}

instance SizedSerializable Int where
#if WORD_SIZE_IN_BITS == 32
  size _ = 4
#else
  size :: Proxy Int -> Int
size Proxy Int
_ = Int
8
#endif
  {-# INLINE size #-}

instance (SizedSerializable α, SizedSerializable β)
          SizedSerializable (α, β) where
  size :: Proxy (α, β) -> Int
size Proxy (α, β)
_ = Proxy α -> Int
forall α. SizedSerializable α => Proxy α -> Int
size (Proxy α
forall k (t :: k). Proxy t
Proxy  Proxy α) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Proxy β -> Int
forall α. SizedSerializable α => Proxy α -> Int
size (Proxy β
forall k (t :: k). Proxy t
Proxy  Proxy β)
  {-# INLINE size #-}

-- | Serializable type. 'putRest' must work under assumption that it will not
--   be followed by any more output.
class RestSerializable α where
  putRest  Serializer s  α  s

instance RestSerializable BS.ByteString where
  putRest :: ByteString -> s
putRest = ByteString -> s
forall s. Serializer s => ByteString -> s
byteString
  {-# INLINE putRest #-}

instance RestSerializable SBS.ShortByteString where
  putRest :: ShortByteString -> s
putRest = ShortByteString -> s
forall s. Serializer s => ShortByteString -> s
shortByteString
  {-# INLINE putRest #-}

instance RestSerializable LBS.ByteString where
  putRest :: ByteString -> s
putRest = ByteString -> s
forall s. Serializer s => ByteString -> s
lazyByteString
  {-# INLINE putRest #-}

instance RestSerializable BB.Builder where
  putRest :: Builder -> s
putRest = Builder -> s
forall s. Serializer s => Builder -> s
builder
  {-# INLINE putRest #-}

instance Serializable α  RestSerializable [α] where
  putRest :: [α] -> s
putRest = [s] -> s
forall a. Monoid a => [a] -> a
mconcat ([s] -> s) -> ([α] -> [s]) -> [α] -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (α -> s) -> [α] -> [s]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap α -> s
forall α s. (Serializable α, Serializer s) => α -> s
put
  {-# INLINE putRest #-}

instance (Serializable α, RestSerializable β)  RestSerializable (α, β) where
  putRest :: (α, β) -> s
putRest (α
a, β
b) = α -> s
forall α s. (Serializable α, Serializer s) => α -> s
put α
a s -> s -> s
forall a. Semigroup a => a -> a -> a
<> β -> s
forall α s. (RestSerializable α, Serializer s) => α -> s
putRest β
b
  {-# INLINE putRest #-}