Safe Haskell | None |
---|
Logic for dealing with the actual persistence of Stable Trees. The key
exports here are Error
, Store
, load
, and store
. A user needs to
implement the loadTree
, loadValue
, storeTree
and storeValue
parts of
Store
, and make an appropriate Error type to report storage errors, and
then the load
and store
functions can just do their thing. If necessary,
a user can also implement Build
for custom data types.
- data Store m e k v = Store {}
- class Build t where
- class Error e where
- stableTreeError :: Text -> e
- data Id
- encodeId :: Id -> ByteString
- decodeId :: ByteString -> Either String Id
- load :: (Monad m, IsKey k, Ord k, Error e) => Store m e k v -> Id -> m (Either e (StableTree k v))
- store :: (Monad m, Build k, Ord k, Build v) => Store m e k v -> StableTree k v -> m (Either e Id)
- buildBinary :: Binary t => t -> Builder
- buildSerialize :: Serialize t => t -> Builder
Documentation
Write appropriate functions here to load and store primitive parts of trees.
Typeclass to generate unique ByteString
s for StableTree keys and values.
Used to generate the unique identities for values and branches.
Things go wrong with end-user storage, but things can also go wrong with
reconstructing tree values. Implement stableTreeError
to allow load
and
store
to report their own errors.
stableTreeError :: Text -> eSource
The opaque type to identify values and branches of trees.
encodeId :: Id -> ByteStringSource
Convert an Id into a 32-byte ByteString. Useful for actual storage of Ids
decodeId :: ByteString -> Either String IdSource
Convert a stored ByteString back into an Id. Gives a Left err if the given ByteString isn't 32 bytes long
load :: (Monad m, IsKey k, Ord k, Error e) => Store m e k v -> Id -> m (Either e (StableTree k v))Source
Retrieve a tree given its id.
store :: (Monad m, Build k, Ord k, Build v) => Store m e k v -> StableTree k v -> m (Either e Id)Source
buildBinary :: Binary t => t -> BuilderSource
Generate a builder for something that is already a Binary
buildSerialize :: Serialize t => t -> BuilderSource
Generate a builder for something that is already a Serialize