| Copyright | (c) Justin Le 2015 |
|---|---|
| License | MIT |
| Maintainer | justin@jle.im |
| Stability | unstable |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Binary.Tagged.Internal
Description
Internals for the library, exported in case you should need it. Usually, the parts you would need should be re-exported in Data.Binary.Tagged.
- data Tagged a
- data TagFingerprint
- tag :: Typeable a => a -> Tagged a
- getTagged :: Typeable a => Tagged a -> Maybe a
- tagMatched :: Typeable a => Tagged a -> Bool
- typeFingerprint :: Typeable a => a -> TagFingerprint
- tagFingerprint :: Tagged a -> TagFingerprint
- bsFingerprint :: ByteString -> Maybe TagFingerprint
- emptyTagFP :: TagFingerprint
Data types
A data type tupling together data with a TagFingerprint,
representing data tagged with its type.
It's best to interface directly with data using encodeTagged,
decodeTagged, etc, using tag to tag data and extractTagged to
extract data from valid tagged data. This type is exported mostly when
you want to specifically decode a ByteString into tagged data, and
manually extract it yourself. If you are writing a framework, it is
preferred to handle this for the end user.
data TagFingerprint Source #
A data type representing a fingerprint for a Typeable type.
Ideally, this would be Internal's own Fingerprint
types; however, for some reason, the fingerprints for the same data type
from the same modules differ between different GHC backends. So for
now, it is just a ByteString representation of the name of the type.
This is literally a bad idea, and so two types with the same name but
from different modules will share a non-unique TagFingerprint.
Hopefully in the future when I find out a way to fix this or the GHC
backend maintainers find a way to provide consistent type fingerprints,
this will be fixed.
This type is mostly used for the ability to categorized Tagged items by their type.
emptyTagFP gives a TagFingerprint that will most likely never be
matched by any actual tag from a real type, so can be used as a test if
needed. This replaces functionality that used to come from the
Default instance.
Instances
Tagging and extracting data
tagMatched :: Typeable a => Tagged a -> Bool Source #
Check if the type inside the Tagged matches the fingerprint.
TagFingerprint utilities
typeFingerprint :: Typeable a => a -> TagFingerprint Source #
Compute the Fingerprint representing a type. It is non-strict on
its parameter, so passing in undefined should work if you want to just
get the Fingerprint of a specific type without having data of that
type on hand:
typeFingerprint (undefined :: Int)
tagFingerprint :: Tagged a -> TagFingerprint Source #
Extract the Fingerprint out of a Tagged. Mostly used so that you
can categorize and associate Tagged items; to check if a Tagged is
of a desired typed, getTagged and tagMatched might be more useful.
bsFingerprint :: ByteString -> Maybe TagFingerprint Source #
With a ByteString, expecting tagged data, returns the Fingerprint
that the data is tagged with. Returns Nothing if the data is not
decodable as tagged data. Might accidentally decode untagged data
though!
emptyTagFP :: TagFingerprint Source #
TagFingerprint that is meant to never be matched by any actual
normal type's TagFingerprint.