winery-0: Sustainable serialisation library

Safe HaskellNone
LanguageHaskell2010

Data.Winery

Contents

Synopsis

Documentation

data Schema Source #

Constructors

SSchema !Word8 
SUnit 
SBool 
SChar 
SWord8 
SWord16 
SWord32 
SWord64 
SInt8 
SInt16 
SInt32 
SInt64 
SInteger 
SFloat 
SDouble 
SBytes 
SText 
SList !Schema 
SArray !(VarInt Int) !Schema 
SProduct [Schema] 
SProductFixed [(VarInt Int, Schema)] 
SRecord [(Text, Schema)] 
SVariant [(Text, [Schema])] 
SFix Schema

binds a fixpoint

SSelf !Word8

SSelf n refers to the n-th innermost fixpoint

Instances

Eq Schema Source # 

Methods

(==) :: Schema -> Schema -> Bool #

(/=) :: Schema -> Schema -> Bool #

Read Schema Source # 
Show Schema Source # 
Generic Schema Source # 

Associated Types

type Rep Schema :: * -> * #

Methods

from :: Schema -> Rep Schema x #

to :: Rep Schema x -> Schema #

Pretty Schema Source # 

Methods

pretty :: Schema -> Doc ann #

prettyList :: [Schema] -> Doc ann #

Serialise Schema Source # 
type Rep Schema Source # 
type Rep Schema = D1 * (MetaData "Schema" "Data.Winery" "winery-0-Kkn6wkyQhIYGqNxihLgi59" False) ((:+:) * ((:+:) * ((:+:) * ((:+:) * (C1 * (MetaCons "SSchema" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * Word8))) ((:+:) * (C1 * (MetaCons "SUnit" PrefixI False) (U1 *)) (C1 * (MetaCons "SBool" PrefixI False) (U1 *)))) ((:+:) * (C1 * (MetaCons "SChar" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "SWord8" PrefixI False) (U1 *)) (C1 * (MetaCons "SWord16" PrefixI False) (U1 *))))) ((:+:) * ((:+:) * (C1 * (MetaCons "SWord32" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "SWord64" PrefixI False) (U1 *)) (C1 * (MetaCons "SInt8" PrefixI False) (U1 *)))) ((:+:) * (C1 * (MetaCons "SInt16" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "SInt32" PrefixI False) (U1 *)) (C1 * (MetaCons "SInt64" PrefixI False) (U1 *)))))) ((:+:) * ((:+:) * ((:+:) * (C1 * (MetaCons "SInteger" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "SFloat" PrefixI False) (U1 *)) (C1 * (MetaCons "SDouble" PrefixI False) (U1 *)))) ((:+:) * (C1 * (MetaCons "SBytes" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "SText" PrefixI False) (U1 *)) (C1 * (MetaCons "SList" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * Schema)))))) ((:+:) * ((:+:) * (C1 * (MetaCons "SArray" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * (VarInt Int))) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * Schema)))) ((:+:) * (C1 * (MetaCons "SProduct" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * [Schema]))) (C1 * (MetaCons "SProductFixed" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * [(VarInt Int, Schema)]))))) ((:+:) * ((:+:) * (C1 * (MetaCons "SRecord" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * [(Text, Schema)]))) (C1 * (MetaCons "SVariant" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * [(Text, [Schema])])))) ((:+:) * (C1 * (MetaCons "SFix" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * Schema))) (C1 * (MetaCons "SSelf" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * Word8))))))))

class Typeable a => Serialise a where Source #

Serialisable datatype

Methods

schemaVia :: Proxy a -> [TypeRep] -> Schema Source #

Obtain the schema of the datatype. [TypeRep] is for handling recursion.

toEncoding :: a -> Encoding Source #

Serialise a value.

deserialiser :: Deserialiser a Source #

constantSize :: Proxy a -> Maybe Int Source #

If this is Just x, the size of toEncoding must be x. deserialiser must not depend on this value.

schemaVia :: (Generic a, GSerialiseVariant (Rep a)) => Proxy a -> [TypeRep] -> Schema Source #

Obtain the schema of the datatype. [TypeRep] is for handling recursion.

toEncoding :: (Generic a, GSerialiseVariant (Rep a)) => a -> Encoding Source #

Serialise a value.

deserialiser :: (Generic a, GSerialiseVariant (Rep a)) => Deserialiser a Source #

Instances

Serialise Bool Source # 
Serialise Char Source # 
Serialise Double Source # 
Serialise Float Source # 
Serialise Int Source # 
Serialise Int8 Source # 
Serialise Int16 Source # 
Serialise Int32 Source # 
Serialise Int64 Source # 
Serialise Integer Source # 
Serialise Word Source # 
Serialise Word8 Source # 
Serialise Word16 Source # 
Serialise Word32 Source # 
Serialise Word64 Source # 
Serialise () Source # 
Serialise ByteString Source # 
Serialise IntSet Source # 
Serialise Text Source # 
Serialise Schema Source # 
Serialise a => Serialise [a] Source # 
Serialise a => Serialise (Maybe a) Source # 
Serialise a => Serialise (Identity a) Source # 
Serialise v => Serialise (IntMap v) Source # 
Serialise a => Serialise (Seq a) Source # 
(Ord a, Serialise a) => Serialise (Set a) Source # 
(Unbox a, Serialise a) => Serialise (Vector a) Source # 
(Storable a, Serialise a) => Serialise (Vector a) Source # 
Serialise a => Serialise (Vector a) Source # 
(Typeable * a, Integral a, Bits a) => Serialise (VarInt a) Source # 
(Serialise a, Serialise b) => Serialise (Either a b) Source # 
(Serialise a, Serialise b) => Serialise (a, b) Source # 
(Ord k, Serialise k, Serialise v) => Serialise (Map k v) Source # 
(Eq k, Hashable k, Serialise k, Serialise v) => Serialise (HashMap k v) Source # 
(Serialise a, Serialise b, Serialise c) => Serialise (a, b, c) Source # 

Methods

schemaVia :: Proxy * (a, b, c) -> [TypeRep] -> Schema Source #

toEncoding :: (a, b, c) -> Encoding Source #

deserialiser :: Deserialiser (a, b, c) Source #

constantSize :: Proxy * (a, b, c) -> Maybe Int Source #

(Serialise a, Serialise b, Serialise c, Serialise d) => Serialise (a, b, c, d) Source # 

Methods

schemaVia :: Proxy * (a, b, c, d) -> [TypeRep] -> Schema Source #

toEncoding :: (a, b, c, d) -> Encoding Source #

deserialiser :: Deserialiser (a, b, c, d) Source #

constantSize :: Proxy * (a, b, c, d) -> Maybe Int Source #

schema :: forall proxy a. Serialise a => proxy a -> Schema Source #

Obtain the schema of the datatype.

Standalone serialisation

serialise :: Serialise a => a -> ByteString Source #

Serialise a value along with its schema.

Separate serialisation

newtype Deserialiser a Source #

Deserialiser is a Plan that creates a Decoder.

Constructors

Deserialiser 

serialiseOnly :: Serialise a => a -> ByteString Source #

Serialise a value without its schema.

getDecoder :: Serialise a => Schema -> Either StrategyError (Decoder a) Source #

Obtain a decoder from a schema.

getDecoderBy :: Deserialiser a -> Schema -> Either StrategyError (Decoder a) Source #

Get a decoder from a Deserialiser and a schema.

Encoding combinators

Decoding combinators

newtype Plan a Source #

Constructors

Plan 

Fields

Instances

Monad Plan Source # 

Methods

(>>=) :: Plan a -> (a -> Plan b) -> Plan b #

(>>) :: Plan a -> Plan b -> Plan b #

return :: a -> Plan a #

fail :: String -> Plan a #

Functor Plan Source # 

Methods

fmap :: (a -> b) -> Plan a -> Plan b #

(<$) :: a -> Plan b -> Plan a #

Applicative Plan Source # 

Methods

pure :: a -> Plan a #

(<*>) :: Plan (a -> b) -> Plan a -> Plan b #

liftA2 :: (a -> b -> c) -> Plan a -> Plan b -> Plan c #

(*>) :: Plan a -> Plan b -> Plan b #

(<*) :: Plan a -> Plan b -> Plan a #

Alternative Plan Source # 

Methods

empty :: Plan a #

(<|>) :: Plan a -> Plan a -> Plan a #

some :: Plan a -> Plan [a] #

many :: Plan a -> Plan [a] #

extractListWith :: Deserialiser a -> Deserialiser [a] Source #

Extract a list or an array of values.

extractField :: Serialise a => Text -> Deserialiser a Source #

Extract a field of a record.

extractFieldWith :: Typeable a => Deserialiser a -> Text -> Deserialiser a Source #

Extract a field using the supplied Deserialiser.

extractConstructorWith :: Typeable a => Deserialiser a -> Text -> Deserialiser (Maybe a) Source #

Tries to extract a specific constructor of a variant. Useful for implementing backward-compatible deserialisers.

Variable-length quantity

newtype VarInt a Source #

Encoded in variable-length quantity.

Constructors

VarInt 

Fields

Instances

Bounded a => Bounded (VarInt a) Source # 

Methods

minBound :: VarInt a #

maxBound :: VarInt a #

Enum a => Enum (VarInt a) Source # 

Methods

succ :: VarInt a -> VarInt a #

pred :: VarInt a -> VarInt a #

toEnum :: Int -> VarInt a #

fromEnum :: VarInt a -> Int #

enumFrom :: VarInt a -> [VarInt a] #

enumFromThen :: VarInt a -> VarInt a -> [VarInt a] #

enumFromTo :: VarInt a -> VarInt a -> [VarInt a] #

enumFromThenTo :: VarInt a -> VarInt a -> VarInt a -> [VarInt a] #

Eq a => Eq (VarInt a) Source # 

Methods

(==) :: VarInt a -> VarInt a -> Bool #

(/=) :: VarInt a -> VarInt a -> Bool #

Integral a => Integral (VarInt a) Source # 

Methods

quot :: VarInt a -> VarInt a -> VarInt a #

rem :: VarInt a -> VarInt a -> VarInt a #

div :: VarInt a -> VarInt a -> VarInt a #

mod :: VarInt a -> VarInt a -> VarInt a #

quotRem :: VarInt a -> VarInt a -> (VarInt a, VarInt a) #

divMod :: VarInt a -> VarInt a -> (VarInt a, VarInt a) #

toInteger :: VarInt a -> Integer #

Num a => Num (VarInt a) Source # 

Methods

(+) :: VarInt a -> VarInt a -> VarInt a #

(-) :: VarInt a -> VarInt a -> VarInt a #

(*) :: VarInt a -> VarInt a -> VarInt a #

negate :: VarInt a -> VarInt a #

abs :: VarInt a -> VarInt a #

signum :: VarInt a -> VarInt a #

fromInteger :: Integer -> VarInt a #

Ord a => Ord (VarInt a) Source # 

Methods

compare :: VarInt a -> VarInt a -> Ordering #

(<) :: VarInt a -> VarInt a -> Bool #

(<=) :: VarInt a -> VarInt a -> Bool #

(>) :: VarInt a -> VarInt a -> Bool #

(>=) :: VarInt a -> VarInt a -> Bool #

max :: VarInt a -> VarInt a -> VarInt a #

min :: VarInt a -> VarInt a -> VarInt a #

Read a => Read (VarInt a) Source # 
Real a => Real (VarInt a) Source # 

Methods

toRational :: VarInt a -> Rational #

Show a => Show (VarInt a) Source # 

Methods

showsPrec :: Int -> VarInt a -> ShowS #

show :: VarInt a -> String #

showList :: [VarInt a] -> ShowS #

Bits a => Bits (VarInt a) Source # 

Methods

(.&.) :: VarInt a -> VarInt a -> VarInt a #

(.|.) :: VarInt a -> VarInt a -> VarInt a #

xor :: VarInt a -> VarInt a -> VarInt a #

complement :: VarInt a -> VarInt a #

shift :: VarInt a -> Int -> VarInt a #

rotate :: VarInt a -> Int -> VarInt a #

zeroBits :: VarInt a #

bit :: Int -> VarInt a #

setBit :: VarInt a -> Int -> VarInt a #

clearBit :: VarInt a -> Int -> VarInt a #

complementBit :: VarInt a -> Int -> VarInt a #

testBit :: VarInt a -> Int -> Bool #

bitSizeMaybe :: VarInt a -> Maybe Int #

bitSize :: VarInt a -> Int #

isSigned :: VarInt a -> Bool #

shiftL :: VarInt a -> Int -> VarInt a #

unsafeShiftL :: VarInt a -> Int -> VarInt a #

shiftR :: VarInt a -> Int -> VarInt a #

unsafeShiftR :: VarInt a -> Int -> VarInt a #

rotateL :: VarInt a -> Int -> VarInt a #

rotateR :: VarInt a -> Int -> VarInt a #

popCount :: VarInt a -> Int #

(Typeable * a, Integral a, Bits a) => Serialise (VarInt a) Source # 

Internal

data Strategy a Source #

Instances

Monad Strategy Source # 

Methods

(>>=) :: Strategy a -> (a -> Strategy b) -> Strategy b #

(>>) :: Strategy a -> Strategy b -> Strategy b #

return :: a -> Strategy a #

fail :: String -> Strategy a #

Functor Strategy Source # 

Methods

fmap :: (a -> b) -> Strategy a -> Strategy b #

(<$) :: a -> Strategy b -> Strategy a #

MonadFix Strategy Source # 

Methods

mfix :: (a -> Strategy a) -> Strategy a #

Applicative Strategy Source # 

Methods

pure :: a -> Strategy a #

(<*>) :: Strategy (a -> b) -> Strategy a -> Strategy b #

liftA2 :: (a -> b -> c) -> Strategy a -> Strategy b -> Strategy c #

(*>) :: Strategy a -> Strategy b -> Strategy b #

(<*) :: Strategy a -> Strategy b -> Strategy a #

Alternative Strategy Source # 

Methods

empty :: Strategy a #

(<|>) :: Strategy a -> Strategy a -> Strategy a #

some :: Strategy a -> Strategy [a] #

many :: Strategy a -> Strategy [a] #

Generics

class GSerialiseRecord f Source #

Minimal complete definition

recordSchema, recordEncoder, recordDecoder

Instances

GSerialiseRecord k f => GSerialiseRecord k (D1 k c f) Source # 

Methods

recordSchema :: proxy f -> [TypeRep] -> [(Text, Schema)]

recordEncoder :: f x -> [Encoding]

recordDecoder :: Maybe (f x) -> RecordDecoder Text (Decoder (f x))

GSerialiseRecord k f => GSerialiseRecord k (C1 k c f) Source # 

Methods

recordSchema :: proxy f -> [TypeRep] -> [(Text, Schema)]

recordEncoder :: f x -> [Encoding]

recordDecoder :: Maybe (f x) -> RecordDecoder Text (Decoder (f x))

(GSerialiseRecord k f, GSerialiseRecord k g) => GSerialiseRecord k ((:*:) k f g) Source # 

Methods

recordSchema :: proxy f -> [TypeRep] -> [(Text, Schema)]

recordEncoder :: f x -> [Encoding]

recordDecoder :: Maybe (f x) -> RecordDecoder Text (Decoder (f x))

(Serialise a, Selector Meta c) => GSerialiseRecord k (S1 k c (K1 k i a)) Source # 

Methods

recordSchema :: proxy f -> [TypeRep] -> [(Text, Schema)]

recordEncoder :: f x -> [Encoding]

recordDecoder :: Maybe (f x) -> RecordDecoder Text (Decoder (f x))

gschemaViaRecord :: forall proxy a. (GSerialiseRecord (Rep a), Generic a, Typeable a) => proxy a -> [TypeRep] -> Schema Source #

Generic implementation of schemaVia for a record.

gtoEncodingRecord :: (GSerialiseRecord (Rep a), Generic a) => a -> Encoding Source #

Generic implementation of toEncoding for a record.

gdeserialiserRecord Source #

Arguments

:: (GSerialiseRecord (Rep a), Generic a, Typeable a) 
=> Maybe a

default value (optional)

-> Deserialiser a 

Generic implementation of deserialiser for a record.

class GSerialiseVariant f Source #

Minimal complete definition

variantCount, variantSchema, variantEncoder, variantDecoder

Instances

GSerialiseVariant k f => GSerialiseVariant k (D1 k c f) Source # 

Methods

variantCount :: proxy f -> Int

variantSchema :: proxy f -> [TypeRep] -> [(Text, [Schema])]

variantEncoder :: Int -> f x -> Encoding

variantDecoder :: [(Text, [Schema] -> Strategy (Decoder (f x)))]

GSerialiseVariant k f => GSerialiseVariant k (S1 k c f) Source # 

Methods

variantCount :: proxy f -> Int

variantSchema :: proxy f -> [TypeRep] -> [(Text, [Schema])]

variantEncoder :: Int -> f x -> Encoding

variantDecoder :: [(Text, [Schema] -> Strategy (Decoder (f x)))]

(GSerialiseProduct k f, Constructor Meta c) => GSerialiseVariant k (C1 k c f) Source # 

Methods

variantCount :: proxy f -> Int

variantSchema :: proxy f -> [TypeRep] -> [(Text, [Schema])]

variantEncoder :: Int -> f x -> Encoding

variantDecoder :: [(Text, [Schema] -> Strategy (Decoder (f x)))]

(GSerialiseVariant k f, GSerialiseVariant k g) => GSerialiseVariant k ((:+:) k f g) Source # 

Methods

variantCount :: proxy f -> Int

variantSchema :: proxy f -> [TypeRep] -> [(Text, [Schema])]

variantEncoder :: Int -> f x -> Encoding

variantDecoder :: [(Text, [Schema] -> Strategy (Decoder (f x)))]

gschemaViaVariant :: forall proxy a. (GSerialiseVariant (Rep a), Typeable a, Generic a) => proxy a -> [TypeRep] -> Schema Source #

Generic implementation of schemaVia for an ADT.

gtoEncodingVariant :: (GSerialiseVariant (Rep a), Generic a) => a -> Encoding Source #

Generic implementation of toEncoding for an ADT.

gdeserialiserVariant :: forall a. (GSerialiseVariant (Rep a), Generic a, Typeable a) => Deserialiser a Source #

Generic implementation of deserialiser for an ADT.

Preset schema