-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Simple bidirectional serialization
--   
--   See the README
@package codec
@version 0.2.1

module Control.Monad.Codec

-- | A serializer/deserializer pair reading <tt>a</tt> in context
--   <tt>r</tt> and writing <tt>c</tt> in context <tt>w</tt>.
data CodecFor r w c a
Codec :: r a -> c -> w a -> CodecFor r w c a
[codecIn] :: CodecFor r w c a -> r a
[codecOut] :: CodecFor r w c a -> c -> w a
type Codec r w a = CodecFor r w a a

-- | Compose a function into the serializer of a <a>Codec</a>. Useful to
--   modify a <a>Codec</a> so that it writes a particular record field.
(=.) :: (c' -> c) -> CodecFor r w c a -> CodecFor r w c' a

-- | Modify a serializer function so that it also returns the serialized
--   value, Useful for implementing codecs.
fmapArg :: Functor f => (a -> f ()) -> a -> f a
instance (GHC.Base.Functor r, GHC.Base.Functor w) => GHC.Base.Functor (Control.Monad.Codec.CodecFor r w c)
instance (GHC.Base.Applicative r, GHC.Base.Applicative w) => GHC.Base.Applicative (Control.Monad.Codec.CodecFor r w c)
instance (GHC.Base.Monad r, GHC.Base.Monad w) => GHC.Base.Monad (Control.Monad.Codec.CodecFor r w c)
instance (GHC.Base.Functor r, GHC.Base.Functor w) => Data.Profunctor.Unsafe.Profunctor (Control.Monad.Codec.CodecFor r w)

module Data.Aeson.Codec

-- | Describes the de/serialization of a type <tt>a</tt>. Equivalent to a
--   <a>ToJSON</a> and a <a>FromJSON</a> instance.
data JSONCodec a
JSONCodec :: Value -> Parser a -> a -> Value -> a -> Encoding -> JSONCodec a
[parseJSONCodec] :: JSONCodec a -> Value -> Parser a
[toJSONCodec] :: JSONCodec a -> a -> Value
[toEncodingCodec] :: JSONCodec a -> a -> Encoding

-- | Encode/decode a value with its <a>ToJSON</a> and <a>FromJSON</a>
--   instances.
defJSON :: (FromJSON a, ToJSON a) => JSONCodec a
type ObjectParser = ReaderT Object Parser
type ObjectBuilder = Writer (Series, Endo [Pair])

-- | A codec that parses values out of a given <a>Object</a>, and produces
--   key-value pairs into a new one.
type ObjectCodec a = Codec ObjectParser ObjectBuilder a

-- | Store/retrieve a value in a given JSON field, with the default JSON
--   serialization.
field :: (FromJSON a, ToJSON a) => Text -> ObjectCodec a

-- | Store/retrieve a value in a given JSON field, with a given JSONCodec.
field' :: Text -> JSONCodec a -> ObjectCodec a

-- | Turn an <a>ObjectCodec</a> into a <a>JSONCodec</a> with an expected
--   name (see <a>withObject</a>).
asObject :: String -> ObjectCodec a -> JSONCodec a
type ArrayParser = StateT [Value] Parser
type ArrayBuilder = Writer (Series, [Value])

-- | A codec that serializes data to a sequence of JSON array elements.
type ArrayCodec a = Codec ArrayParser ArrayBuilder a

-- | Expect/append an array element, using the default serialization.
element :: (FromJSON a, ToJSON a) => ArrayCodec a

-- | Expect/append an array element, using a given <a>JSONCodec</a>.
element' :: JSONCodec a -> ArrayCodec a

-- | A codec that parses values out of a given <a>Array</a>, and produces
--   key-value pairs into a new one.
asArray :: String -> ArrayCodec a -> JSONCodec a

-- | Given a a way to turn <tt>a</tt> into <tt>[ b ]</tt> and back, create
--   a <a>JSONCodec</a> for <tt>a</tt>.
arrayOf :: (FromJSON b, ToJSON b) => (a -> [b]) -> ([b] -> a) -> JSONCodec a

-- | Given a <a>JSONCodec</a> for <tt>b</tt> and a way to turn <tt>a</tt>
--   into <tt>[ b ]</tt> and back, create a <a>JSONCodec</a> for
--   <tt>a</tt>.
arrayOf' :: (a -> [b]) -> ([b] -> a) -> JSONCodec b -> JSONCodec a

module Data.Binary.Codec
type BinaryCodec a = Codec Get PutM a

-- | Get/put an n-byte field.
byteString :: Int -> BinaryCodec ByteString
word8 :: BinaryCodec Word8
word16be :: BinaryCodec Word16
word16le :: BinaryCodec Word16
word16host :: BinaryCodec Word16
word32be :: BinaryCodec Word32
word32le :: BinaryCodec Word32
word32host :: BinaryCodec Word32
word64be :: BinaryCodec Word64
word64le :: BinaryCodec Word64
word64host :: BinaryCodec Word64
wordhost :: BinaryCodec Word
int8 :: BinaryCodec Int8
int16be :: BinaryCodec Int16
int16le :: BinaryCodec Int16
int16host :: BinaryCodec Int16
int32be :: BinaryCodec Int32
int32le :: BinaryCodec Int32
int32host :: BinaryCodec Int32
int64be :: BinaryCodec Int64
int64le :: BinaryCodec Int64
int64host :: BinaryCodec Int64
inthost :: BinaryCodec Int

module Data.Binary.Bits.Codec
type BitCodec a = Codec Block BitPut a
bool :: BitCodec Bool
word8 :: Int -> BitCodec Word8
word16be :: Int -> BitCodec Word16
word32be :: Int -> BitCodec Word32
word64be :: Int -> BitCodec Word64

-- | Convert a <a>BitCodec</a> into a <a>BinaryCodec</a>.
toBytes :: BitCodec a -> BinaryCodec a
