Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Derive BLen
, Put
, Get
and CBLen
instances generically.
Synopsis
- data Cfg a = Cfg {}
- cfg :: (Eq a, Show a) => (String -> a) -> Cfg a
- cSumTagHex :: forall a. Integral a => (String -> String) -> String -> a
- cSumTagNullTerm :: String -> AsByteString 'C
- cDef :: Cfg (AsByteString 'C)
- cNoSum :: Cfg Void
- data EDerivedSumInstanceWithNonSumCfg = EDerivedSumInstanceWithNonSumCfg
- blenGeneric :: (Generic a, GBLen (Rep a), BLen w) => Cfg w -> a -> BLenT
- putGeneric :: (Generic a, GPut (Rep a), Put w) => Cfg w -> a -> Builder
- getGeneric :: (Generic a, GGetD (Rep a), Get w) => Cfg w -> Getter a
- type CBLenGeneric w a = GCBLen w (Rep a)
Documentation
cSumTagHex :: forall a. Integral a => (String -> String) -> String -> a Source #
Obtain the tag for a sum type value by applying a function to the constructor name, and reading the result as a hexadecimal number.
cSumTagNullTerm :: String -> AsByteString 'C Source #
Obtain the tag for a sum type value using the constructor name directly (with a null terminator).
This is probably not what you want in a binary representation, but it's safe and may be useful for debugging.
The refine force is safe under the assumption that Haskell constructor names are UTF-8 with no null bytes allowed. I haven't confirmed that, but I'm fairly certain.
cDef :: Cfg (AsByteString 'C) Source #
Default generic derivation configuration, using cSumTagNullTerm
.
Special generic derivation configuration you may use for non-sum data types.
When generically deriving binrep instances for a non-sum type, you may like
to ignore sum tag handling. You could use cDef
, but this will silently
change behaviour if your type becomes a sum type. This configuration will
generate clear runtime errors when used with a sum type.
By selecting Void
for the sum tag type, consumption actions (serializing,
getting length in bytes) will runtime error, while generation actions
(parsing) will hit the Void
instance first and always safely error out.
data EDerivedSumInstanceWithNonSumCfg Source #
Instances
type CBLenGeneric w a = GCBLen w (Rep a) Source #