winery-1.1: A compact, well-typed seralisation format for Haskell values

Copyright(c) Fumiaki Kinoshita 2019
LicenseBSD3
StabilityProvisional
Safe HaskellNone
LanguageHaskell2010

Codec.Winery

Contents

Description

Maintainer : Fumiaki Kinoshita fumiexcel@gmail.com

Synopsis

Documentation

type Schema = SchemaP Int Source #

A schema preserves structure of a datatype, allowing users to inspect the data regardless of the current implementation.

"Yeah, it’s just a memento. Just, you know, from the first time we met."

data SchemaP a Source #

The basic schema datatype

Constructors

SFix !(SchemaP a)

binds a fixpoint

SVar !a

SVar n refers to the n-th innermost fixpoint

SVector !(SchemaP a) 
SProduct !(Vector (SchemaP a)) 
SRecord !(Vector (Text, SchemaP a)) 
SVariant !(Vector (Text, SchemaP a)) 
SBool 
SChar 
SWord8 
SWord16 
SWord32 
SWord64 
SInt8 
SInt16 
SInt32 
SInt64 
SInteger 
SFloat 
SDouble 
SBytes 
SText 
SUTCTime

nanoseconds from POSIX epoch

STag !Tag !(SchemaP a) 
SLet !(SchemaP a) !(SchemaP a) 
Instances
Functor SchemaP Source # 
Instance details

Defined in Codec.Winery.Base

Methods

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

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

Foldable SchemaP Source # 
Instance details

Defined in Codec.Winery.Base

Methods

fold :: Monoid m => SchemaP m -> m #

foldMap :: Monoid m => (a -> m) -> SchemaP a -> m #

foldr :: (a -> b -> b) -> b -> SchemaP a -> b #

foldr' :: (a -> b -> b) -> b -> SchemaP a -> b #

foldl :: (b -> a -> b) -> b -> SchemaP a -> b #

foldl' :: (b -> a -> b) -> b -> SchemaP a -> b #

foldr1 :: (a -> a -> a) -> SchemaP a -> a #

foldl1 :: (a -> a -> a) -> SchemaP a -> a #

toList :: SchemaP a -> [a] #

null :: SchemaP a -> Bool #

length :: SchemaP a -> Int #

elem :: Eq a => a -> SchemaP a -> Bool #

maximum :: Ord a => SchemaP a -> a #

minimum :: Ord a => SchemaP a -> a #

sum :: Num a => SchemaP a -> a #

product :: Num a => SchemaP a -> a #

Traversable SchemaP Source # 
Instance details

Defined in Codec.Winery.Base

Methods

traverse :: Applicative f => (a -> f b) -> SchemaP a -> f (SchemaP b) #

sequenceA :: Applicative f => SchemaP (f a) -> f (SchemaP a) #

mapM :: Monad m => (a -> m b) -> SchemaP a -> m (SchemaP b) #

sequence :: Monad m => SchemaP (m a) -> m (SchemaP a) #

Serialise Schema Source # 
Instance details

Defined in Codec.Winery

Eq a => Eq (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

Methods

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

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

Read a => Read (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

Show a => Show (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

Methods

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

show :: SchemaP a -> String #

showList :: [SchemaP a] -> ShowS #

Generic (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

Associated Types

type Rep (SchemaP a) :: Type -> Type #

Methods

from :: SchemaP a -> Rep (SchemaP a) x #

to :: Rep (SchemaP a) x -> SchemaP a #

Pretty a => Pretty (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

Methods

pretty :: SchemaP a -> Doc ann #

prettyList :: [SchemaP a] -> Doc ann #

type Rep (SchemaP a) Source # 
Instance details

Defined in Codec.Winery.Base

type Rep (SchemaP a) = D1 (MetaData "SchemaP" "Codec.Winery.Base" "winery-1.1-GelciUm5a16BnHByjHLJjC" False) ((((C1 (MetaCons "SFix" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (SchemaP a))) :+: (C1 (MetaCons "SVar" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 a)) :+: C1 (MetaCons "SVector" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (SchemaP a))))) :+: (C1 (MetaCons "SProduct" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector (SchemaP a)))) :+: (C1 (MetaCons "SRecord" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector (Text, SchemaP a)))) :+: C1 (MetaCons "SVariant" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (Vector (Text, SchemaP a))))))) :+: ((C1 (MetaCons "SBool" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SChar" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SWord8" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "SWord16" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SWord32" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SWord64" PrefixI False) (U1 :: Type -> Type))))) :+: (((C1 (MetaCons "SInt8" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SInt16" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SInt32" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "SInt64" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SInteger" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SFloat" PrefixI False) (U1 :: Type -> Type)))) :+: ((C1 (MetaCons "SDouble" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "SBytes" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "SText" PrefixI False) (U1 :: Type -> Type))) :+: (C1 (MetaCons "SUTCTime" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "STag" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Tag) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (SchemaP a))) :+: C1 (MetaCons "SLet" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (SchemaP a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (SchemaP a))))))))

data Tag Source #

Tag is an extra value that can be attached to a schema.

Constructors

TagInt !Int 
TagStr !Text 
TagList ![Tag] 
Instances
IsList Tag Source # 
Instance details

Defined in Codec.Winery.Base

Associated Types

type Item Tag :: Type #

Methods

fromList :: [Item Tag] -> Tag #

fromListN :: Int -> [Item Tag] -> Tag #

toList :: Tag -> [Item Tag] #

Eq Tag Source # 
Instance details

Defined in Codec.Winery.Base

Methods

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

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

Read Tag Source # 
Instance details

Defined in Codec.Winery.Base

Show Tag Source # 
Instance details

Defined in Codec.Winery.Base

Methods

showsPrec :: Int -> Tag -> ShowS #

show :: Tag -> String #

showList :: [Tag] -> ShowS #

IsString Tag Source # 
Instance details

Defined in Codec.Winery.Base

Methods

fromString :: String -> Tag #

Generic Tag Source # 
Instance details

Defined in Codec.Winery.Base

Associated Types

type Rep Tag :: Type -> Type #

Methods

from :: Tag -> Rep Tag x #

to :: Rep Tag x -> Tag #

Pretty Tag Source # 
Instance details

Defined in Codec.Winery.Base

Methods

pretty :: Tag -> Doc ann #

prettyList :: [Tag] -> Doc ann #

Serialise Tag Source # 
Instance details

Defined in Codec.Winery

type Rep Tag Source # 
Instance details

Defined in Codec.Winery.Base

type Item Tag Source # 
Instance details

Defined in Codec.Winery.Base

type Item Tag = Tag

class Typeable a => Serialise a where Source #

Serialisable datatype

Methods

schemaGen :: Proxy a -> SchemaGen Schema Source #

Obtain the schema of the datatype.

toBuilder :: a -> Builder Source #

Serialise a value.

extractor :: Extractor a Source #

A value of 'Extractor a' interprets a schema and builds a function from Term to a. This must be equivalent to decodeCurrent when the schema is the current one.

If extractor s returns a function, the function must return a non-bottom for any Term decodeTerm s returns.

It must not return a function if an unsupported schema is supplied.

getDecoderBy extractor (schema (Proxy a)) must be Right d where d@ is equivalent to decodeCurrent.

decodeCurrent :: Decoder a Source #

Decode a value with the current schema.

decodeCurrent evalDecoder toBuilder x ≡ x

bundleSerialise :: BundleSerialise a Source #

Instead of the four methods above, you can supply a bundle.

Instances
Serialise Bool Source # 
Instance details

Defined in Codec.Winery

Serialise Char Source # 
Instance details

Defined in Codec.Winery

Serialise Double Source # 
Instance details

Defined in Codec.Winery

Serialise Float Source # 
Instance details

Defined in Codec.Winery

Serialise Int Source # 
Instance details

Defined in Codec.Winery

Serialise Int8 Source # 
Instance details

Defined in Codec.Winery

Serialise Int16 Source # 
Instance details

Defined in Codec.Winery

Serialise Int32 Source # 
Instance details

Defined in Codec.Winery

Serialise Int64 Source # 
Instance details

Defined in Codec.Winery

Serialise Integer Source # 
Instance details

Defined in Codec.Winery

Serialise Natural Source # 
Instance details

Defined in Codec.Winery

Serialise Ordering Source # 
Instance details

Defined in Codec.Winery

Serialise Word Source # 
Instance details

Defined in Codec.Winery

Serialise Word8 Source # 
Instance details

Defined in Codec.Winery

Serialise Word16 Source # 
Instance details

Defined in Codec.Winery

Serialise Word32 Source # 
Instance details

Defined in Codec.Winery

Serialise Word64 Source # 
Instance details

Defined in Codec.Winery

Serialise () Source # 
Instance details

Defined in Codec.Winery

Serialise ByteString Source # 
Instance details

Defined in Codec.Winery

Serialise ByteString Source # 
Instance details

Defined in Codec.Winery

Serialise Scientific Source # 
Instance details

Defined in Codec.Winery

Serialise Text Source # 
Instance details

Defined in Codec.Winery

Serialise UTCTime Source # 
Instance details

Defined in Codec.Winery

Serialise Void Source # 
Instance details

Defined in Codec.Winery

Serialise All Source # 
Instance details

Defined in Codec.Winery

Serialise Any Source # 
Instance details

Defined in Codec.Winery

Serialise IntSet Source # 
Instance details

Defined in Codec.Winery

Serialise NominalDiffTime Source # 
Instance details

Defined in Codec.Winery

Serialise Schema Source # 
Instance details

Defined in Codec.Winery

Serialise Tag Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise [a] Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Maybe a) Source # 
Instance details

Defined in Codec.Winery

(Integral a, Serialise a) => Serialise (Ratio a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Complex a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Min a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Max a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (First a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Last a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Option a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (ZipList a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Identity a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (First a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Last a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Dual a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Sum a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Product a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Down a) Source # 
Instance details

Defined in Codec.Winery

Serialise v => Serialise (IntMap v) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Seq a) Source # 
Instance details

Defined in Codec.Winery

(Ord a, Serialise a) => Serialise (Set a) Source # 
Instance details

Defined in Codec.Winery

(Unbox a, Serialise a) => Serialise (Vector a) Source # 
Instance details

Defined in Codec.Winery

(Storable a, Serialise a) => Serialise (Vector a) Source # 
Instance details

Defined in Codec.Winery

Serialise a => Serialise (Vector a) Source # 
Instance details

Defined in Codec.Winery

(GSerialiseVariant (Rep a), Generic a, Typeable a) => Serialise (WineryVariant a) Source # 
Instance details

Defined in Codec.Winery

(GEncodeProduct (Rep a), GSerialiseProduct (Rep a), GDecodeProduct (Rep a), Generic a, Typeable a) => Serialise (WineryProduct a) Source # 
Instance details

Defined in Codec.Winery

(GEncodeProduct (Rep a), GSerialiseRecord (Rep a), GDecodeProduct (Rep a), Generic a, Typeable a) => Serialise (WineryRecord a) Source # 
Instance details

Defined in Codec.Winery

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

Defined in Codec.Winery

(Serialise a, Serialise b) => Serialise (Either a b) Source # 
Instance details

Defined in Codec.Winery

(Serialise a, Serialise b) => Serialise (a, b) Source # 
Instance details

Defined in Codec.Winery

(Eq k, Hashable k, Serialise k, Serialise v) => Serialise (HashMap k v) Source # 
Instance details

Defined in Codec.Winery

(Ord k, Serialise k, Serialise v) => Serialise (Map k v) Source # 
Instance details

Defined in Codec.Winery

(Serialise a, Serialise b) => Serialise (Arg a b) Source # 
Instance details

Defined in Codec.Winery

(Serialise a, Serialise b, Serialise c) => Serialise (a, b, c) Source # 
Instance details

Defined in Codec.Winery

(Serialise a, Typeable b, Typeable k) => Serialise (Const a b) Source # 
Instance details

Defined in Codec.Winery

(Typeable k, Typeable f, Typeable a, Serialise (f a)) => Serialise (Ap f a) Source # 
Instance details

Defined in Codec.Winery

(Typeable k, Typeable f, Typeable a, Serialise (f a)) => Serialise (Alt f a) Source # 
Instance details

Defined in Codec.Winery

(Typeable k, Typeable a, Typeable b, a ~ b) => Serialise (a :~: b) Source # 
Instance details

Defined in Codec.Winery

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

Defined in Codec.Winery

Methods

schemaGen :: Proxy (a, b, c, d) -> SchemaGen Schema Source #

toBuilder :: (a, b, c, d) -> Builder Source #

extractor :: Extractor (a, b, c, d) Source #

decodeCurrent :: Decoder (a, b, c, d) Source #

bundleSerialise :: BundleSerialise (a, b, c, d) Source #

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

Defined in Codec.Winery

Methods

schemaGen :: Proxy (a, b, c, d, e) -> SchemaGen Schema Source #

toBuilder :: (a, b, c, d, e) -> Builder Source #

extractor :: Extractor (a, b, c, d, e) Source #

decodeCurrent :: Decoder (a, b, c, d, e) Source #

bundleSerialise :: BundleSerialise (a, b, c, d, e) Source #

(Typeable j, Typeable k, Typeable f, Typeable g, Typeable a, Serialise (f (g a))) => Serialise (Compose f g a) Source # 
Instance details

Defined in Codec.Winery

(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f) => Serialise (a, b, c, d, e, f) Source # 
Instance details

Defined in Codec.Winery

Methods

schemaGen :: Proxy (a, b, c, d, e, f) -> SchemaGen Schema Source #

toBuilder :: (a, b, c, d, e, f) -> Builder Source #

extractor :: Extractor (a, b, c, d, e, f) Source #

decodeCurrent :: Decoder (a, b, c, d, e, f) Source #

bundleSerialise :: BundleSerialise (a, b, c, d, e, f) Source #

testSerialise :: forall a. (Eq a, Show a, Serialise a) => a -> Property Source #

Check the integrity of a Serialise instance.

"No tears in the writer, no tears in the reader. No surprise in the writer, no surprise in the reader."

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

Obtain the schema of the datatype.

"Tell me what you drink, and I will tell you what you are."

Standalone serialisation

toBuilderWithSchema :: forall a. Serialise a => a -> Builder Source #

Serialise a value with the schema.

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

Serialise a value along with its schema.

"Write the vision, and make it plain upon tables, that he may run that readeth it."

deserialise :: Serialise a => ByteString -> Either WineryException a Source #

Deserialise a serialised Bytestring.

"Old wood to burn! Old wine to drink! Old friends to trust! Old authors to read!"

writeFileSerialise :: Serialise a => FilePath -> a -> IO () Source #

serialise then write it to a file.

Separate serialisation

serialiseSchema :: Schema -> ByteString Source #

Serialise a schema.

newtype Extractor a Source #

Extractor is a Plan that creates a function to extract a value from Term.

The Applicative instance can be used to build a user-defined extractor. This is also Alternative, meaning that fallback plans may be added.

"Don't get set into one form, adapt it and build your own, and let it grow, be like water."

Constructors

Extractor 

Fields

Instances
Functor Extractor Source # 
Instance details

Defined in Codec.Winery.Base

Methods

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

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

Applicative Extractor Source # 
Instance details

Defined in Codec.Winery.Base

Methods

pure :: a -> Extractor a #

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

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

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

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

Alternative Extractor Source # 
Instance details

Defined in Codec.Winery.Base

Methods

empty :: Extractor a #

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

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

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

type Decoder = State ByteString Source #

The Decoder monad

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

Serialise a value without its schema.

"Any unsaved progress will be lost."

getDecoder :: forall a. Serialise a => Schema -> Either WineryException (Decoder a) Source #

Obtain a decoder from a schema.

"A reader lives a thousand lives before he dies... The man who never reads lives only one."

getDecoderBy :: Extractor a -> Schema -> Either WineryException (Decoder a) Source #

Get a decoder from a Extractor and a schema.

Decoding combinators

data Term Source #

Common representation for any winery data. Handy for prettyprinting winery-serialised data.

Instances
Show Term Source # 
Instance details

Defined in Codec.Winery.Base

Methods

showsPrec :: Int -> Term -> ShowS #

show :: Term -> String #

showList :: [Term] -> ShowS #

ToJSON Term Source # 
Instance details

Defined in Codec.Winery.Base

Pretty Term Source # 
Instance details

Defined in Codec.Winery.Base

Methods

pretty :: Term -> Doc ann #

prettyList :: [Term] -> Doc ann #

newtype Subextractor a Source #

An extractor for individual fields. This distinction is required for handling recursions correctly.

Recommended extension: ApplicativeDo

Constructors

Subextractor 
Instances
Functor Subextractor Source # 
Instance details

Defined in Codec.Winery

Methods

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

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

Applicative Subextractor Source # 
Instance details

Defined in Codec.Winery

Alternative Subextractor Source # 
Instance details

Defined in Codec.Winery

buildExtractor :: Typeable a => Subextractor a -> Extractor a Source #

Build an extractor from a Subextractor.

extractListBy :: Typeable a => Extractor a -> Extractor (Vector a) Source #

Extract a list or an array of values.

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

Extract a field of a record.

extractFieldBy :: Extractor a -> Text -> Subextractor a Source #

Extract a field using the supplied Extractor.

extractConstructor :: Serialise a => (Text, a -> r) -> Subextractor r -> Subextractor r infixr 1 Source #

Tries to match on a constructor. If it doesn't match (or constructor doesn't exist at all), leave it to the successor.

extractor = (Just, Just) extractConstructor (Nothing, () -> Nothing) extractConstructor extractVoid

extractConstructorBy :: Typeable a => (Extractor a, Text, a -> r) -> Subextractor r -> Subextractor r infixr 1 Source #

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

extractVoid :: Typeable r => Subextractor r Source #

No constructors remaining.

data ExtractException Source #

This may be thrown if illegal Term is passed to an extractor.

Constructors

InvalidTerm !Term 

Variable-length quantity

newtype VarInt a Source #

Encoded in variable-length quantity.

Constructors

VarInt 

Fields

Instances
Bounded a => Bounded (VarInt a) Source # 
Instance details

Defined in Codec.Winery

Methods

minBound :: VarInt a #

maxBound :: VarInt a #

Enum a => Enum (VarInt a) Source # 
Instance details

Defined in Codec.Winery

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 # 
Instance details

Defined in Codec.Winery

Methods

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

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

Integral a => Integral (VarInt a) Source # 
Instance details

Defined in Codec.Winery

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 # 
Instance details

Defined in Codec.Winery

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 # 
Instance details

Defined in Codec.Winery

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 # 
Instance details

Defined in Codec.Winery

Real a => Real (VarInt a) Source # 
Instance details

Defined in Codec.Winery

Methods

toRational :: VarInt a -> Rational #

Show a => Show (VarInt a) Source # 
Instance details

Defined in Codec.Winery

Methods

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

show :: VarInt a -> String #

showList :: [VarInt a] -> ShowS #

Bits a => Bits (VarInt a) Source # 
Instance details

Defined in Codec.Winery

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, Bits a, Integral a) => Serialise (VarInt a) Source # 
Instance details

Defined in Codec.Winery

Internal

data SchemaGen a Source #

Schema generator

Instances
Functor SchemaGen Source # 
Instance details

Defined in Codec.Winery

Methods

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

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

Applicative SchemaGen Source # 
Instance details

Defined in Codec.Winery

Methods

pure :: a -> SchemaGen a #

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

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

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

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

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

Obtain a schema on SchemaGen, binding a fixpoint when necessary. If you are hand-rolling a definition of schemaGen, you should call this instead of schemaGen.

newtype Plan a Source #

Plan is a monad for computations which interpret Schema.

Constructors

Plan 

Fields

Instances
Monad Plan Source # 
Instance details

Defined in Codec.Winery.Base

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 # 
Instance details

Defined in Codec.Winery.Base

Methods

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

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

Applicative Plan Source # 
Instance details

Defined in Codec.Winery.Base

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 # 
Instance details

Defined in Codec.Winery.Base

Methods

empty :: Plan a #

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

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

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

mkPlan :: forall a. Typeable a => (Schema -> Strategy' (Term -> a)) -> Plan (Term -> a) Source #

Construct a plan, expanding fixpoints and let bindings.

DerivingVia

newtype WineryRecord a Source #

The Serialise instance is generically defined for records.

"Remember thee! Yea, from the table of my memory I'll wipe away all trivial fond records."

Constructors

WineryRecord 

Fields

newtype WineryVariant a Source #

The Serialise instance is generically defined for variants.

"The one so like the other as could not be distinguish'd but by names."

Constructors

WineryVariant 

Fields

newtype WineryProduct a Source #

Serialise a value as a product (omits field names).

"I get ideas about what's essential when packing my suitcase."

Constructors

WineryProduct 

Fields

Generic implementations (for old GHC / custom instances)

class GSerialiseRecord f Source #

Minimal complete definition

recordSchema, recordExtractor

Instances
GSerialiseRecord f => GSerialiseRecord (D1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

recordSchema :: proxy (D1 c f) -> SchemaGen [(Text, Schema)]

recordExtractor :: Maybe (D1 c f x) -> TransFusion (FieldDecoder Text) ((->) Term) (Term -> D1 c f x)

GSerialiseRecord f => GSerialiseRecord (C1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

recordSchema :: proxy (C1 c f) -> SchemaGen [(Text, Schema)]

recordExtractor :: Maybe (C1 c f x) -> TransFusion (FieldDecoder Text) ((->) Term) (Term -> C1 c f x)

(Serialise a, Selector c) => GSerialiseRecord (S1 c (K1 i a :: k -> Type) :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

recordSchema :: proxy (S1 c (K1 i a)) -> SchemaGen [(Text, Schema)]

recordExtractor :: Maybe (S1 c (K1 i a) x) -> TransFusion (FieldDecoder Text) ((->) Term) (Term -> S1 c (K1 i a) x)

(GSerialiseRecord f, GSerialiseRecord g) => GSerialiseRecord (f :*: g :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

recordSchema :: proxy (f :*: g) -> SchemaGen [(Text, Schema)]

recordExtractor :: Maybe ((f :*: g) x) -> TransFusion (FieldDecoder Text) ((->) Term) (Term -> (f :*: g) x)

gschemaGenRecord :: forall proxy a. (GSerialiseRecord (Rep a), Generic a, Typeable a) => proxy a -> SchemaGen Schema Source #

Generic implementation of schemaGen for a record.

class GEncodeProduct f Source #

Encode all the fields

Minimal complete definition

productEncoder

Instances
GEncodeProduct (U1 :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

productEncoder :: U1 x -> Builder

GEncodeProduct f => GEncodeProduct (D1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

productEncoder :: D1 c f x -> Builder

GEncodeProduct f => GEncodeProduct (C1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

productEncoder :: C1 c f x -> Builder

Serialise a => GEncodeProduct (S1 c (K1 i a :: k -> Type) :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

productEncoder :: S1 c (K1 i a) x -> Builder

(GEncodeProduct f, GEncodeProduct g) => GEncodeProduct (f :*: g :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

productEncoder :: (f :*: g) x -> Builder

gtoBuilderRecord :: (GEncodeProduct (Rep a), Generic a) => a -> Builder Source #

Generic implementation of toBuilder for a record.

gextractorRecord Source #

Arguments

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

default value (optional)

-> Extractor a 

Generic implementation of extractor for a record.

gdecodeCurrentRecord :: (GDecodeProduct (Rep a), Generic a) => Decoder a Source #

class GSerialiseVariant f Source #

Minimal complete definition

variantCount, variantSchema, variantEncoder, variantExtractor, variantDecoder

Instances
GSerialiseVariant f => GSerialiseVariant (D1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

variantCount :: proxy (D1 c f) -> Int

variantSchema :: proxy (D1 c f) -> SchemaGen [(Text, Schema)]

variantEncoder :: Int -> D1 c f x -> Builder

variantExtractor :: [(Text, Schema -> Strategy' (Term -> D1 c f x))]

variantDecoder :: [Decoder (D1 c f x)]

GSerialiseVariant f => GSerialiseVariant (S1 c f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

variantCount :: proxy (S1 c f) -> Int

variantSchema :: proxy (S1 c f) -> SchemaGen [(Text, Schema)]

variantEncoder :: Int -> S1 c f x -> Builder

variantExtractor :: [(Text, Schema -> Strategy' (Term -> S1 c f x))]

variantDecoder :: [Decoder (S1 c f x)]

(GSerialiseRecord f, GEncodeProduct f, GDecodeProduct f, KnownSymbol name) => GSerialiseVariant (C1 (MetaCons name fixity True) f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

variantCount :: proxy (C1 (MetaCons name fixity True) f) -> Int

variantSchema :: proxy (C1 (MetaCons name fixity True) f) -> SchemaGen [(Text, Schema)]

variantEncoder :: Int -> C1 (MetaCons name fixity True) f x -> Builder

variantExtractor :: [(Text, Schema -> Strategy' (Term -> C1 (MetaCons name fixity True) f x))]

variantDecoder :: [Decoder (C1 (MetaCons name fixity True) f x)]

(GSerialiseProduct f, GEncodeProduct f, GDecodeProduct f, KnownSymbol name) => GSerialiseVariant (C1 (MetaCons name fixity False) f :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

variantCount :: proxy (C1 (MetaCons name fixity False) f) -> Int

variantSchema :: proxy (C1 (MetaCons name fixity False) f) -> SchemaGen [(Text, Schema)]

variantEncoder :: Int -> C1 (MetaCons name fixity False) f x -> Builder

variantExtractor :: [(Text, Schema -> Strategy' (Term -> C1 (MetaCons name fixity False) f x))]

variantDecoder :: [Decoder (C1 (MetaCons name fixity False) f x)]

(GSerialiseVariant f, GSerialiseVariant g) => GSerialiseVariant (f :+: g :: k -> Type) Source # 
Instance details

Defined in Codec.Winery

Methods

variantCount :: proxy (f :+: g) -> Int

variantSchema :: proxy (f :+: g) -> SchemaGen [(Text, Schema)]

variantEncoder :: Int -> (f :+: g) x -> Builder

variantExtractor :: [(Text, Schema -> Strategy' (Term -> (f :+: g) x))]

variantDecoder :: [Decoder ((f :+: g) x)]

gschemaGenVariant :: forall proxy a. (GSerialiseVariant (Rep a), Typeable a, Generic a) => proxy a -> SchemaGen Schema Source #

Generic implementation of schemaGen for an ADT.

gtoBuilderVariant :: (GSerialiseVariant (Rep a), Generic a) => a -> Builder Source #

Generic implementation of toBuilder for an ADT.

gextractorVariant :: forall a. (GSerialiseVariant (Rep a), Generic a, Typeable a) => Extractor a Source #

Generic implementation of extractor for an ADT.

gschemaGenProduct :: forall proxy a. (Generic a, GSerialiseProduct (Rep a)) => proxy a -> SchemaGen Schema Source #

gextractorProduct :: forall a. (GSerialiseProduct (Rep a), Generic a, Typeable a) => Extractor a Source #

Generic implementation of extractor for a record.

gdecodeCurrentProduct :: forall a. (GDecodeProduct (Rep a), Generic a) => Decoder a Source #

Generic implementation of extractor for a record.

decodeCurrentDefault :: forall a. Serialise a => Decoder a Source #

decodeCurrent in terms of extractor; note that it's very slow.

Bundles

bundleRecord :: (GEncodeProduct (Rep a), GSerialiseRecord (Rep a), GDecodeProduct (Rep a), Generic a, Typeable a) => (Extractor a -> Extractor a) -> BundleSerialise a Source #

A bundle of generic implementations for records

bundleRecordDefault :: (GEncodeProduct (Rep a), GSerialiseRecord (Rep a), GDecodeProduct (Rep a), Generic a, Typeable a) => a -> (Extractor a -> Extractor a) -> BundleSerialise a Source #

A bundle of generic implementations for records, with a default value

bundleVariant :: (GSerialiseVariant (Rep a), Generic a, Typeable a) => (Extractor a -> Extractor a) -> BundleSerialise a Source #

A bundle of generic implementations for variants

Preset schema

bootstrapSchema :: Word8 -> Either WineryException Schema Source #

Obtain the schema of the schema corresponding to the specified version.