-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fast binary serialization -- -- Fast binary serialization @package store @version 0.1.0.0 -- | A ByteBuffer is a simple buffer for bytes. It supports two -- operations: refilling with the contents of a ByteString, and -- consuming a fixed number of bytes. -- -- It is implemented as a pointer, together with counters that keep track -- of the offset and the number of bytes in the buffer. Note that the -- counters are simple IORefs, so ByteBuffers are not -- thread-safe! -- -- A ByteBuffer is constructed by new with a given starting -- length, and will grow (by repeatedly multiplying its size by 1.5) -- whenever it is being fed a ByteString that is too large. module System.IO.ByteBuffer type ByteBuffer = IORef BBRef -- | Allocates a new ByteBuffer with a given buffer size filling from the -- given FillBuffer. -- -- Note that ByteBuffers created with new have to be -- deallocated explicitly using free. For automatic deallocation, -- consider using with instead. new :: MonadIO m => Maybe Int -> m ByteBuffer -- | Free a byte buffer. free :: MonadIO m => ByteBuffer -> m () -- | Perform some action with a bytebuffer, with automatic allocation and -- deallocation. with :: (MonadIO m, MonadBaseControl IO m) => Maybe Int -> (ByteBuffer -> m a) -> m a totalSize :: MonadIO m => ByteBuffer -> m Int isEmpty :: MonadIO m => ByteBuffer -> m Bool -- | Number of available bytes in a ByteBuffer (that is, bytes that -- have been copied to, but not yet read from the ByteBuffer. availableBytes :: MonadIO m => ByteBuffer -> m Int -- | Copy the contents of a ByteString to a ByteBuffer. -- -- If necessary, the ByteBuffer is enlarged and/or already -- consumed bytes are dropped. copyByteString :: MonadIO m => ByteBuffer -> ByteString -> m () -- | As unsafeConsume, but instead of returning a Ptr into -- the contents of the ByteBuffer, it returns a ByteString -- containing the next n bytes in the buffer. This involves -- allocating a new ByteString and copying the n bytes to -- it. consume :: MonadIO m => ByteBuffer -> Int -> m (Either Int ByteString) -- | Try to get a pointer to n bytes from the ByteBuffer. -- -- Note that the pointer should be used before any other actions are -- performed on the ByteBuffer. It points to some address within -- the buffer, so operations such as enlarging the buffer or feeding it -- new data will change the data the pointer points to. This is why this -- function is called unsafe. unsafeConsume :: MonadIO m => ByteBuffer -> Int -> m (Either Int (Ptr Word8)) -- | This module exports TH utilities intended to be useful to users. -- -- However, the visible exports do not show the main things that will be -- useful, which is using TH to generate Store instances, via -- TH.Derive. It's used like this: -- --
-- data Foo = Foo Int | Bar Int -- -- $($(derive [d| -- instance Deriving (Store Foo) -- |])) ---- -- One advantage of using this Template Haskell definition of Store -- instances is that in some cases they can be faster than the instances -- defined via Generics. Specifically, sum types which can yield -- ConstSize from size will be faster when used in -- array-like types. The instances generated via generics always use -- VarSize for sum types. module Data.Store.TH -- | Test a Store instance using smallcheck and -- hspec. smallcheckManyStore :: Bool -> Int -> [TypeQ] -> ExpQ -- | Check if a given value succeeds in decoding its encoded -- representation. checkRoundtrip :: (Eq a, Show a, Store a) => Bool -> a -> Bool assertRoundtrip :: (Eq a, Show a, Store a, Monad m, Typeable a) => Bool -> a -> m () module Data.Store.TH.Internal deriveManyStoreFromStorable :: (Type -> Bool) -> Q [Dec] deriveTupleStoreInstance :: Int -> Dec deriveGenericInstance :: Cxt -> Type -> Dec deriveManyStorePrimVector :: Q [Dec] deriveManyStoreUnboxVector :: Q [Dec] deriveStore :: Cxt -> Type -> [DataCon] -> Q Dec getAllInstanceTypes1 :: Name -> Q [Type] isMonoType :: Type -> Bool instance TH.Derive.Internal.Deriver (Data.Store.Impl.Store a) -- | Internal API for the store package. The functions here which are not -- re-exported by Data.Store are less likely to have stable APIs. -- -- This module also defines most of the included Store instances, -- for types from the base package and other commonly used packages -- (bytestring, containers, text, time, etc). module Data.Store.Internal -- | Serializes a value to a ByteString. In order to do this, it -- first allocates a ByteString of the correct size (based on -- size), and then uses poke to fill it. encode :: Store a => a -> ByteString -- | Decodes a value from a ByteString. Returns an exception if -- there's an error while decoding, or if decoding undershoots / -- overshoots the end of the buffer. decode :: Store a => ByteString -> Either PeekException a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeWith :: Peek a -> ByteString -> Either PeekException a -- | Decodes a value from a ByteString, potentially throwing -- exceptions. It is an exception to not consume all input. decodeEx :: Store a => ByteString -> a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeExWith :: Peek a -> ByteString -> a -- | Similar to decodeExWith, but it allows there to be more of the -- buffer remaining. The Offset of the buffer contents immediately -- after the decoded value is returned. decodeExPortionWith :: Peek a -> ByteString -> (Offset, a) -- | Decodes a value from a ByteString, potentially throwing -- exceptions. It is an exception to not consume all input. decodeIO :: Store a => ByteString -> IO a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeIOWith :: Peek a -> ByteString -> IO a -- | Similar to decodeExPortionWith, but runs in the IO -- monad. decodeIOPortionWith :: Peek a -> ByteString -> IO (Offset, a) -- | The Store typeclass provides efficient serialization and -- deserialization to raw pointer addresses. -- -- The peek and poke methods should be defined such that -- decodeEx (encode x) == x . class Store a where size = genericSize poke = genericPoke peek = genericPeek -- | Yields the Size of the buffer, in bytes, required to store the -- encoded representation of the type. -- -- Note that the correctness of this function is crucial for the safety -- of poke, as it does not do any bounds checking. It is the -- responsibility of the invoker of poke (encode and -- similar functions) to ensure that there's enough space in the output -- buffer. If poke writes beyond, then arbitrary memory can be -- overwritten, causing undefined behavior and segmentation faults. size :: Store a => Size a -- | Serializes a value to bytes. It is the responsibility of the caller to -- ensure that at least the number of bytes required by size are -- available. These details are handled by encode and similar -- utilities. poke :: Store a => a -> Poke () -- | Serialized a value from bytes, throwing exceptions if it encounters -- invalid data or runs out of input bytes. peek :: Store a => Peek a data Poke a data Peek a -- | Run the Peek action, with a Ptr to the end of the buffer -- where data is poked, and a Ptr to the current position. The -- result is the Ptr, along with a return value. runPeek :: Peek a -> forall byte. Ptr byte -> Ptr byte -> IO (Ptr byte, a) -- | Exception thrown while running poke. Note that other types of -- exceptions could also be thrown. Invocations of fail in the -- Poke monad causes this exception to be thrown. -- -- PokeExceptions are not expected to occur in ordinary -- circumstances, and usually indicate a programming error. data PokeException PokeException :: Offset -> Text -> PokeException [pokeExByteIndex] :: PokeException -> Offset [pokeExMessage] :: PokeException -> Text pokeException :: Text -> Poke a -- | Exception thrown while running peek. Note that other types of -- exceptions can also be thrown. Invocations of fail in the -- Poke monad causes this exception to be thrown. -- -- PeekException is thrown when the data being decoded is invalid. data PeekException PeekException :: Offset -> Text -> PeekException [peekExBytesFromEnd] :: PeekException -> Offset [peekExMessage] :: PeekException -> Text peekException :: Text -> Peek a tooManyBytes :: Int -> Int -> String -> IO void -- | Info about a type's serialized length. Either the length is known -- independently of the value, or the length depends on the value. data Size a VarSize :: (a -> Int) -> Size a ConstSize :: !Int -> Size a getSize :: Store a => a -> Int getSizeWith :: Size a -> a -> Int contramapSize :: (a -> b) -> Size b -> Size a combineSize :: (Store a, Store b) => (c -> a) -> (c -> b) -> Size c combineSize' :: (c -> a) -> (c -> b) -> Size a -> Size b -> Size c scaleSize :: Int -> Size a -> Size a addSize :: Int -> Size a -> Size a -- | Implement size for an IsSequence of Store -- instances. -- -- Note that many monomorphic containers have more efficient -- implementations (for example, via memcpy). sizeSequence :: (IsSequence t, Store (Element t)) => Size t -- | Implement poke for an IsSequence of Store -- instances. -- -- Note that many monomorphic containers have more efficient -- implementations (for example, via memcpy). pokeSequence :: (IsSequence t, Store (Element t)) => t -> Poke () -- | Implement peek for an IsSequence of Store -- instances. -- -- Note that many monomorphic containers have more efficient -- implementations (for example, via memcpy). peekSequence :: (IsSequence t, Store (Element t), Index t ~ Int) => Peek t -- | Implement size for an IsSet of Store instances. sizeSet :: (IsSet t, Store (Element t)) => Size t -- | Implement poke for an IsSequence of Store -- instances. pokeSet :: (IsSet t, Store (Element t)) => t -> Poke () -- | Implement peek for an IsSequence of Store -- instances. peekSet :: (IsSet t, Store (Element t)) => Peek t -- | Implement size for an IsMap of where both -- ContainerKey and MapValue are Store instances. sizeMap :: (Store (ContainerKey t), Store (MapValue t), IsMap t) => Size t -- | Implement poke for an IsMap of where both -- ContainerKey and MapValue are Store instances. pokeMap :: (Store (ContainerKey t), Store (MapValue t), IsMap t) => t -> Poke () -- | Implement peek for an IsMap of where both -- ContainerKey and MapValue are Store instances. peekMap :: (Store (ContainerKey t), Store (MapValue t), IsMap t) => Peek t -- | Skip n bytes forward. skip :: Int -> Peek () -- | Isolate the input to n bytes, skipping n bytes forward. Fails if -- m advances the offset beyond the isolated region. isolate :: Int -> Peek a -> Peek a class KnownNat n => IsStaticSize n a toStaticSize :: IsStaticSize n a => a -> Maybe (StaticSize n a) newtype StaticSize (n :: Nat) a StaticSize :: a -> StaticSize a [unStaticSize] :: StaticSize a -> a toStaticSizeEx :: IsStaticSize n a => a -> StaticSize n a liftStaticSize :: (KnownNat n, Lift a) => TypeQ -> StaticSize n a -> ExpQ instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Info instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Dec instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Name instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.OccName instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.NameFlavour instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Clause instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Pat instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Lit instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Type instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.TyVarBndr instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.TyLit instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Exp instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Match instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Body instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Guard instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Stmt instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Range instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Con instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Strict instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.FunDep instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Foreign instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Callconv instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Safety instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Fixity instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.FixityDirection instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Pragma instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Inline instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.RuleMatch instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Phases instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.RuleBndr instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.AnnTarget instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.FamFlavour instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.TySynEqn instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Role instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.ModName instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.NameSpace instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.PkgName instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Int.Int16) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Int.Int32) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Int.Int64) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Int.Int8) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Word.Word16) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Word.Word32) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Word.Word64) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Word.Word8) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Types.Char) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Types.Double) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Types.Float) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Types.Int) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector GHC.Types.Word) instance Data.Store.Impl.Store (Data.Vector.Primitive.Vector Data.Primitive.Types.Addr) instance (Foreign.Storable.Storable a0, Data.Typeable.Internal.Typeable a0, Data.Typeable.Internal.Typeable b0) => Data.Store.Impl.Store (Control.Applicative.Const a0 b0) instance (Foreign.Storable.Storable a0, Data.Typeable.Internal.Typeable a0) => Data.Store.Impl.Store (Data.Complex.Complex a0) instance (Foreign.Storable.Storable a0, Data.Typeable.Internal.Typeable a0) => Data.Store.Impl.Store (Data.Functor.Identity.Identity a0) instance Data.Store.Impl.Store Foreign.C.Types.CChar instance Data.Store.Impl.Store Foreign.C.Types.CClock instance Data.Store.Impl.Store Foreign.C.Types.CDouble instance Data.Store.Impl.Store Foreign.C.Types.CFloat instance Data.Store.Impl.Store Foreign.C.Types.CInt instance Data.Store.Impl.Store Foreign.C.Types.CIntMax instance Data.Store.Impl.Store Foreign.C.Types.CIntPtr instance Data.Store.Impl.Store Foreign.C.Types.CLLong instance Data.Store.Impl.Store Foreign.C.Types.CLong instance Data.Store.Impl.Store Foreign.C.Types.CPtrdiff instance Data.Store.Impl.Store Foreign.C.Types.CSChar instance Data.Store.Impl.Store Foreign.C.Types.CSUSeconds instance Data.Store.Impl.Store Foreign.C.Types.CShort instance Data.Store.Impl.Store Foreign.C.Types.CSigAtomic instance Data.Store.Impl.Store Foreign.C.Types.CSize instance Data.Store.Impl.Store Foreign.C.Types.CTime instance Data.Store.Impl.Store Foreign.C.Types.CUChar instance Data.Store.Impl.Store Foreign.C.Types.CUInt instance Data.Store.Impl.Store Foreign.C.Types.CUIntMax instance Data.Store.Impl.Store Foreign.C.Types.CUIntPtr instance Data.Store.Impl.Store Foreign.C.Types.CULLong instance Data.Store.Impl.Store Foreign.C.Types.CULong instance Data.Store.Impl.Store Foreign.C.Types.CUSeconds instance Data.Store.Impl.Store Foreign.C.Types.CUShort instance Data.Store.Impl.Store Foreign.C.Types.CWchar instance Data.Store.Impl.Store Foreign.Ptr.IntPtr instance Data.Store.Impl.Store Foreign.Ptr.WordPtr instance Data.Store.Impl.Store GHC.Int.Int16 instance Data.Store.Impl.Store GHC.Int.Int32 instance Data.Store.Impl.Store GHC.Int.Int64 instance Data.Store.Impl.Store GHC.Int.Int8 instance Data.Typeable.Internal.Typeable a0 => Data.Store.Impl.Store (GHC.Ptr.FunPtr a0) instance Data.Typeable.Internal.Typeable a0 => Data.Store.Impl.Store (GHC.Ptr.Ptr a0) instance Data.Typeable.Internal.Typeable a0 => Data.Store.Impl.Store (GHC.Stable.StablePtr a0) instance Data.Store.Impl.Store GHC.Word.Word16 instance Data.Store.Impl.Store GHC.Word.Word32 instance Data.Store.Impl.Store GHC.Word.Word64 instance Data.Store.Impl.Store GHC.Word.Word8 instance Data.Store.Impl.Store GHC.Types.Char instance Data.Store.Impl.Store GHC.Types.Double instance Data.Store.Impl.Store GHC.Types.Float instance Data.Store.Impl.Store GHC.Types.Int instance Data.Store.Impl.Store GHC.Types.Word instance (Foreign.Storable.Storable a0, Data.Typeable.Internal.Typeable s0, Data.Typeable.Internal.Typeable a0) => Data.Store.Impl.Store (Data.Tagged.Tagged s0 a0) instance (Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector b), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector c), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector d), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector e), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector f)) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (a, b, c, d, e, f)) instance (Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector b), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector c), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector d), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector e)) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (a, b, c, d, e)) instance (Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector b), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector c), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector d)) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (a, b, c, d)) instance (Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector b), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector c)) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (a, b, c)) instance (Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a), Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector b)) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (a, b)) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector a) => Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector (Data.Complex.Complex a)) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Int.Int16) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Int.Int32) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Int.Int64) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Int.Int8) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Word.Word16) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Word.Word32) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Word.Word64) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Word.Word8) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Bool) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Char) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Double) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Float) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Int) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector GHC.Types.Word) instance Data.Store.Impl.Store (Data.Vector.Unboxed.Base.Vector ()) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b) => Data.Store.Impl.Store (a, b) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b, Data.Store.Impl.Store c) => Data.Store.Impl.Store (a, b, c) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b, Data.Store.Impl.Store c, Data.Store.Impl.Store d) => Data.Store.Impl.Store (a, b, c, d) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b, Data.Store.Impl.Store c, Data.Store.Impl.Store d, Data.Store.Impl.Store e) => Data.Store.Impl.Store (a, b, c, d, e) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b, Data.Store.Impl.Store c, Data.Store.Impl.Store d, Data.Store.Impl.Store e, Data.Store.Impl.Store f) => Data.Store.Impl.Store (a, b, c, d, e, f) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b, Data.Store.Impl.Store c, Data.Store.Impl.Store d, Data.Store.Impl.Store e, Data.Store.Impl.Store f, Data.Store.Impl.Store g) => Data.Store.Impl.Store (a, b, c, d, e, f, g) instance Data.Store.Impl.Store Data.Monoid.All instance Data.Store.Impl.Store Data.Monoid.Any instance Data.Store.Impl.Store Data.Void.Void instance Data.Store.Impl.Store GHC.Types.Bool instance GHC.Generics.Selector Data.Store.Internal.S1_0_0StaticSize instance GHC.Generics.Constructor Data.Store.Internal.C1_0StaticSize instance GHC.Generics.Datatype Data.Store.Internal.D1StaticSize instance GHC.Generics.Generic (Data.Store.Internal.StaticSize n a) instance (Data.Data.Data a, Data.Typeable.Internal.Typeable n) => Data.Data.Data (Data.Store.Internal.StaticSize n a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Store.Internal.StaticSize n a) instance GHC.Show.Show a => GHC.Show.Show (Data.Store.Internal.StaticSize n a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Store.Internal.StaticSize n a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Vector.Vector a) instance Foreign.Storable.Storable a => Data.Store.Impl.Store (Data.Vector.Storable.Vector a) instance Data.Store.Impl.Store Data.ByteString.Internal.ByteString instance Data.Store.Impl.Store Data.ByteString.Short.Internal.ShortByteString instance Data.Store.Impl.Store Data.ByteString.Lazy.Internal.ByteString instance Data.Store.Impl.Store Data.Text.Internal.Text instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Data.Store.Internal.StaticSize n a) instance GHC.TypeLits.KnownNat n => Data.Store.Internal.IsStaticSize n Data.ByteString.Internal.ByteString instance GHC.TypeLits.KnownNat n => Data.Store.Impl.Store (Data.Store.Internal.StaticSize n Data.ByteString.Internal.ByteString) instance Data.Store.Impl.Store a => Data.Store.Impl.Store [a] instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.List.NonEmpty.NonEmpty a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Sequence.Seq a) instance (Data.Store.Impl.Store a, GHC.Classes.Ord a) => Data.Store.Impl.Store (Data.Set.Base.Set a) instance Data.Store.Impl.Store Data.IntSet.Base.IntSet instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.IntMap.Base.IntMap a) instance (GHC.Classes.Ord k, Data.Store.Impl.Store k, Data.Store.Impl.Store a) => Data.Store.Impl.Store (Data.Map.Base.Map k a) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k, Data.Store.Impl.Store k, Data.Store.Impl.Store a) => Data.Store.Impl.Store (Data.HashMap.Base.HashMap k a) instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a, Data.Store.Impl.Store a) => Data.Store.Impl.Store (Data.HashSet.HashSet a) instance Data.Store.Impl.Store GHC.Integer.Type.Integer instance Data.Store.Impl.Store (Data.Fixed.Fixed a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (GHC.Real.Ratio a) instance Data.Store.Impl.Store Data.Time.Calendar.Days.Day instance Data.Store.Impl.Store Data.Time.Clock.Scale.DiffTime instance Data.Store.Impl.Store Data.Time.Clock.UTC.UTCTime instance Data.Store.Impl.Store () instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Monoid.Dual a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Monoid.Sum a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Monoid.Product a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Monoid.First a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Monoid.Last a) instance Data.Store.Impl.Store a => Data.Store.Impl.Store (GHC.Base.Maybe a) instance (Data.Store.Impl.Store a, Data.Store.Impl.Store b) => Data.Store.Impl.Store (Data.Either.Either a b) instance Data.Store.Impl.Store GHC.Fingerprint.Type.Fingerprint -- | This is the main public API of the store package. The functions -- exported here are more likely to be stable between versions. -- -- Usually you won't need to write your own Store instances, and -- instead can rely on either using the Generic deriving -- approach or Data.Store.TH for defining Store instances -- for your datatypes. There are some tradeoffs here - the generics -- instances do not require -XTemplateHaskell, but they do not -- optimize as well for sum types that only require a constant number of -- bytes. module Data.Store -- | Serializes a value to a ByteString. In order to do this, it -- first allocates a ByteString of the correct size (based on -- size), and then uses poke to fill it. encode :: Store a => a -> ByteString -- | Decodes a value from a ByteString. Returns an exception if -- there's an error while decoding, or if decoding undershoots / -- overshoots the end of the buffer. decode :: Store a => ByteString -> Either PeekException a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeWith :: Peek a -> ByteString -> Either PeekException a -- | Decodes a value from a ByteString, potentially throwing -- exceptions. It is an exception to not consume all input. decodeEx :: Store a => ByteString -> a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeExWith :: Peek a -> ByteString -> a -- | Similar to decodeExWith, but it allows there to be more of the -- buffer remaining. The Offset of the buffer contents immediately -- after the decoded value is returned. decodeExPortionWith :: Peek a -> ByteString -> (Offset, a) -- | Decodes a value from a ByteString, potentially throwing -- exceptions. It is an exception to not consume all input. decodeIO :: Store a => ByteString -> IO a -- | Decodes a value from a ByteString, potentially throwing -- exceptions, and taking a Peek to run. It is an exception to not -- consume all input. decodeIOWith :: Peek a -> ByteString -> IO a -- | Similar to decodeExPortionWith, but runs in the IO -- monad. decodeIOPortionWith :: Peek a -> ByteString -> IO (Offset, a) -- | The Store typeclass provides efficient serialization and -- deserialization to raw pointer addresses. -- -- The peek and poke methods should be defined such that -- decodeEx (encode x) == x . class Store a where size = genericSize poke = genericPoke peek = genericPeek -- | Yields the Size of the buffer, in bytes, required to store the -- encoded representation of the type. -- -- Note that the correctness of this function is crucial for the safety -- of poke, as it does not do any bounds checking. It is the -- responsibility of the invoker of poke (encode and -- similar functions) to ensure that there's enough space in the output -- buffer. If poke writes beyond, then arbitrary memory can be -- overwritten, causing undefined behavior and segmentation faults. size :: Store a => Size a -- | Serializes a value to bytes. It is the responsibility of the caller to -- ensure that at least the number of bytes required by size are -- available. These details are handled by encode and similar -- utilities. poke :: Store a => a -> Poke () -- | Serialized a value from bytes, throwing exceptions if it encounters -- invalid data or runs out of input bytes. peek :: Store a => Peek a -- | Info about a type's serialized length. Either the length is known -- independently of the value, or the length depends on the value. data Size a VarSize :: (a -> Int) -> Size a ConstSize :: !Int -> Size a data Poke a data Peek a -- | Exception thrown while running peek. Note that other types of -- exceptions can also be thrown. Invocations of fail in the -- Poke monad causes this exception to be thrown. -- -- PeekException is thrown when the data being decoded is invalid. data PeekException PeekException :: Offset -> Text -> PeekException [peekExBytesFromEnd] :: PeekException -> Offset [peekExMessage] :: PeekException -> Text peekException :: Text -> Peek a -- | For efficiency reasons, Store does not provide facilities for -- incrementally consuming input. In order to avoid partial input, this -- module introduces Messages that wrap values of instances of -- Store. -- -- In addition to the serialisation of a value, the serialised message -- also contains the length of the serialisation. This way, instead of -- consuming input incrementally, more input can be demanded before -- serialisation is attempted in the first place. module Data.Store.Streaming -- | If a is an instance of Store, Message a can -- be serialised and deserialised in a streaming fashion. newtype Message a Message :: a -> Message a [fromMessage] :: Message a -> a -- | Encode a Message to a ByteString. encodeMessage :: Store a => Message a -> ByteString -- | The result of peeking at the next message can either be a successfully -- deserialised Message, or a request for more input. data PeekMessage m a Done :: (Message a) -> PeekMessage m a NeedMoreInput :: (ByteString -> m (PeekMessage m a)) -> PeekMessage m a -- | Decode some Message from a ByteBuffer, by first reading -- its size, and then the actual Message. peekMessage :: (MonadIO m, Store a) => ByteBuffer -> m (PeekMessage m a) -- | Decode a Message from a ByteBuffer and an action that -- can get additional ByteStrings to refill the buffer when -- necessary. -- -- The only conditions under which this function will give -- Nothing, is when the ByteBuffer contains zero bytes, and -- refilling yields Nothing. If there is some data available, but -- not enough to decode the whole Message, a PeekException -- will be thrown. decodeMessage :: (MonadIO m, Store a) => ByteBuffer -> m (Maybe ByteString) -> m (Maybe (Message a)) -- | Conduit for encoding Messages to ByteStrings. conduitEncode :: (Monad m, Store a) => Conduit (Message a) m ByteString -- | Conduit for decoding Messages from ByteStrings. conduitDecode :: (MonadIO m, MonadResource m, Store a) => Maybe Int -> Conduit ByteString m (Message a) instance GHC.Show.Show a => GHC.Show.Show (Data.Store.Streaming.Message a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Store.Streaming.Message a) module Data.Store.TypeHash.Internal newtype Tagged a Tagged :: a -> Tagged a [unTagged] :: Tagged a -> a newtype TypeHash TypeHash :: StaticSize 20 ByteString -> TypeHash [unTypeHash] :: TypeHash -> StaticSize 20 ByteString reifyManyTyDecls :: ((Name, Info) -> Q (Bool, [Name])) -> [Name] -> Q [(Name, Info)] -- | At compiletime, this yields a hash of the specified datatypes. Not -- only does this cover the datatypes themselves, but also all transitive -- dependencies. -- -- The resulting expression is a literal of type Int. typeHashForNames :: [Name] -> Q Exp -- | At compiletime, this yields a cryptographic hash of the specified -- Type, including the definition of things it references -- (transitively). -- -- The resulting expression is a literal of type Int. hashOfType :: Type -> Q Exp getTypeInfosRecursively :: [Name] -> Q [(Name, Info)] getConNames :: Data a => a -> [Name] getVarNames :: Data a => a -> [Name] class HasTypeHash a typeHash :: HasTypeHash a => Proxy a -> TypeHash mkHasTypeHash :: Type -> Q [Dec] mkManyHasTypeHash :: [Q Type] -> Q [Dec] combineTypeHashes :: [TypeHash] -> TypeHash instance GHC.Generics.Selector Data.Store.TypeHash.Internal.S1_0_0TypeHash instance GHC.Generics.Constructor Data.Store.TypeHash.Internal.C1_0TypeHash instance GHC.Generics.Datatype Data.Store.TypeHash.Internal.D1TypeHash instance GHC.Generics.Selector Data.Store.TypeHash.Internal.S1_0_0Tagged instance GHC.Generics.Constructor Data.Store.TypeHash.Internal.C1_0Tagged instance GHC.Generics.Datatype Data.Store.TypeHash.Internal.D1Tagged instance GHC.Generics.Generic Data.Store.TypeHash.Internal.TypeHash instance Data.Store.Impl.Store Data.Store.TypeHash.Internal.TypeHash instance GHC.Show.Show Data.Store.TypeHash.Internal.TypeHash instance GHC.Classes.Ord Data.Store.TypeHash.Internal.TypeHash instance GHC.Classes.Eq Data.Store.TypeHash.Internal.TypeHash instance GHC.Generics.Generic (Data.Store.TypeHash.Internal.Tagged a) instance Data.Data.Data a => Data.Data.Data (Data.Store.TypeHash.Internal.Tagged a) instance GHC.Show.Show a => GHC.Show.Show (Data.Store.TypeHash.Internal.Tagged a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Store.TypeHash.Internal.Tagged a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Store.TypeHash.Internal.Tagged a) instance Data.Data.Data Data.Store.TypeHash.Internal.TypeHash instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Data.Store.TypeHash.Internal.Tagged a) instance (Data.Store.Impl.Store a, Data.Store.TypeHash.Internal.HasTypeHash a) => Data.Store.Impl.Store (Data.Store.TypeHash.Internal.Tagged a) instance Control.DeepSeq.NFData Data.Store.TypeHash.Internal.TypeHash instance Language.Haskell.TH.Syntax.Lift Data.Store.TypeHash.Internal.TypeHash module Data.Store.TypeHash newtype Tagged a Tagged :: a -> Tagged a [unTagged] :: Tagged a -> a data TypeHash class HasTypeHash a typeHash :: HasTypeHash a => Proxy a -> TypeHash mkHasTypeHash :: Type -> Q [Dec] mkManyHasTypeHash :: [Q Type] -> Q [Dec]