@@ -39,6 +39,79 @@ import Streamly.Internal.Data.Unbox.TH
39 , reifyDataType
39 , reifyDataType
42+--------------------------------------------------------------------------------
44+--------------------------------------------------------------------------------
46+-- | Config to control how the 'Serialize' instance is generated.
49+ { unconstrained :: [String]
50+ -- ^ Type variables that should not have the 'Serialize' constraint.
53+ -- data CustomDataType a b c d = CustomDataType a c
57+ -- conf = defaultConf {unconstrained = ["b", "d"]}
58+ -- \$(deriveSerializeWith conf ''CustomDataType)
62+ -- instance (Serialize a, Serialize c) => Serialize (CustomDataType a b c d) where
65+ , specializations :: [(String, Type)]
66+ -- ^ Specialize the type variable with the given type. All type
67+ -- variables listed here will not have the 'Serialize' constriant as
68+ -- they are specialized.
71+ -- data CustomDataType f a = CustomDataType (f a)
75+ -- conf = defaultConf {specializations = [("f", ''Identity)]}
76+ -- \$(deriveSerializeWith conf ''CustomDataType)
80+ -- instance (Serialize a) => Serialize (CustomDataType Identity a) where
84+ -- @f@ is replaced with 'Identity' and becomes unconstrained.
85+ , inlineSize :: Inline
86+ -- ^ Inline value for 'size'. Default is Inline.
87+ , inlineSerialize :: Inline
88+ -- ^ Inline value for 'serialize'. Default is Inline.
89+ , inlineDeserialize :: Inline
90+ -- ^ Inline value for 'deserialize'. Default is Inline.
91+ , constructorTagAsString :: Bool
92+ -- ^ __Experimental__
94+ -- If True, encode constructors using the constructor names as Latin-1
96+ , recordSyntaxWithHeader :: Bool
97+ -- ^ __Experimental__
99+ -- If True, encode the keys of the record as a header and then
100+ -- serialize the data.
103+defaultConfig :: Config
106+ { unconstrained = []
107+ , specializations = []
108+ , inlineSize = Inline
109+ , inlineSerialize = Inline
110+ , inlineDeserialize = Inline
111+ , constructorTagAsString = False
112+ , recordSyntaxWithHeader = False
42--------------------------------------------------------------------------------
115--------------------------------------------------------------------------------
43-- Helpers
116-- Helpers
44--------------------------------------------------------------------------------
117--------------------------------------------------------------------------------
@@ -633,75 +706,6 @@ deriveSerializeInternal (Config{..}) preds headTy cons = do
634 return [plainInstanceD preds (AppT (ConT ''Serialize) headTy) methods]
707 return [plainInstanceD preds (AppT (ConT ''Serialize) headTy) methods]
636−-- | Config to control how the 'Serialize' instance is generated.
639− { unconstrained :: [String]
640− -- ^ Type variables that should not have the 'Serialize' constraint.
643− -- data CustomDataType a b c d = CustomDataType a c
647− -- conf = defaultConf {unconstrained = ["b", "d"]}
648− -- \$(deriveSerializeWith conf ''CustomDataType)
652− -- instance (Serialize a, Serialize c) => Serialize (CustomDataType a b c d) where
655− , specializations :: [(String, Type)]
656− -- ^ Specialize the type variable with the given type. All type
657− -- variables listed here will not have the 'Serialize' constriant as
658− -- they are specialized.
661− -- data CustomDataType f a = CustomDataType (f a)
665− -- conf = defaultConf {specializations = [("f", ''Identity)]}
666− -- \$(deriveSerializeWith conf ''CustomDataType)
670− -- instance (Serialize a) => Serialize (CustomDataType Identity a) where
674− -- @f@ is replaced with 'Identity' and becomes unconstrained.
675− , inlineSize :: Inline
676− -- ^ Inline value for 'size'. Default is Inline.
677− , inlineSerialize :: Inline
678− -- ^ Inline value for 'serialize'. Default is Inline.
679− , inlineDeserialize :: Inline
680− -- ^ Inline value for 'deserialize'. Default is Inline.
681− , constructorTagAsString :: Bool
682− -- ^ __Experimental__
684− -- If True, encode constructors using the constructor names as Latin-1
686− , recordSyntaxWithHeader :: Bool
687− -- ^ __Experimental__
689− -- If True, encode the keys of the record as a header and then
690− -- serialize the data.
693−defaultConfig :: Config
696− { unconstrained = []
697− , specializations = []
698− , inlineSize = Inline
699− , inlineSerialize = Inline
700− , inlineDeserialize = Inline
701− , constructorTagAsString = False
702− , recordSyntaxWithHeader = False
705-- | Similar to 'deriveSerialize,' but take a 'Config' to control how
709-- | Similar to 'deriveSerialize,' but take a 'Config' to control how
706-- the instance is generated.
710-- the instance is generated.