-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fast binary serialization -- -- Fast binary serialization @package store @version 0.3 -- | 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 (Either ByteBufferException 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 () -- | Will read at most n bytes from the given Fd, in a non-blocking -- fashion. This function is intended to be used with non-blocking -- Sockets, such the ones created by the network -- package. -- -- Returns how many bytes could be read non-blockingly. fillFromFd :: MonadIO m => ByteBuffer -> Fd -> Int -> m Int -- | 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)) -- | Exception that is thrown when an invalid ByteBuffer is being -- used that is no longer valid. -- -- A ByteBuffer is considered to be invalid if -- --
-- 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. -- -- Safety of this function depends on correctness of the Store -- instance. If size returns a. The good news is that this isn't -- an issue if you use well-tested manual instances (such as those from -- this package) combined with auomatic definition of instances. 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 -- | 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, Generic a, GStoreSize (Rep 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, Generic a, GStorePoke (Rep a)) => a -> Poke () -- | Serialized a value from bytes, throwing exceptions if it encounters -- invalid data or runs out of input bytes. peek :: (Store a, Generic a, GStorePeek (Rep a)) => Peek a -- | Poke actions are useful for building sequential serializers. -- -- They are actions which write values to bytes into memory specified by -- a Ptr base. The Applicative and Monad instances -- make it easy to write serializations, by keeping track of the -- Offset of the current byte. They allow you to chain Poke -- action such that subsequent Pokes write into subsequent -- portions of the output. data Poke a :: * -> * -- | Peek actions are useful for building sequential deserializers. -- -- They are actions which read from memory and construct values from it. -- The Applicative and Monad instances make it easy to -- chain these together to get more complicated deserializers. This -- machinery keeps track of the current Ptr and end-of-buffer -- Ptr. 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. -- -- May throw a PeekException if the memory contains invalid -- values. runPeek :: Peek a -> PeekState -> Ptr Word8 -> IO (Ptr Word8, 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 -- | Throws a PokeException. These should be avoided when possible, -- they usually indicate a programming error. 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 -- | Throws a PeekException. peekException :: Text -> Peek a -- | Throws a PeekException about an attempt to read too many bytes. 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 -- | Get the number of bytes needed to store the given value. See -- size. getSize :: Store a => a -> Int -- | Given a Size value and a value of the type a, returns -- its Int size. getSizeWith :: Size a -> a -> Int -- | This allows for changing the type used as an input when the -- Size is VarSize. contramapSize :: (a -> b) -> Size b -> Size a -- | Create an aggregate Size by providing functions to split the -- input into two pieces. -- -- If both of the types are ConstSize, the result is -- ConstSize and the functions will not be used. combineSize :: forall a b c. (Store a, Store b) => (c -> a) -> (c -> b) -> Size c -- | Create an aggregate Size by providing functions to split the -- input into two pieces, as well as Size values to use to measure -- the results. -- -- If both of the input Size values are ConstSize, the -- result is ConstSize and the functions will not be used. combineSizeWith :: forall a b c. (c -> a) -> (c -> b) -> Size a -> Size b -> Size c -- | Adds a constant amount to a Size value. 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 :: forall t. (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 :: forall t. (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 :: forall t. (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 sizeArray :: (Ix i, IArray a e, Store i, Store e) => Size (a i e) pokeArray :: (Ix i, IArray a e, Store i, Store e) => a i e -> Poke () peekArray :: (Ix i, IArray a e, Store i, Store e) => Peek (a i e) class GStoreSize f genericSize :: (Generic a, GStoreSize (Rep a)) => Size a class GStorePoke f genericPoke :: (Generic a, GStorePoke (Rep a)) => a -> Poke () class GStorePeek f genericPeek :: (Generic a, GStorePeek (Rep a)) => Peek a -- | 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 :: forall n a. (KnownNat n, Lift a) => TypeQ -> StaticSize n a -> ExpQ staticByteStringExp :: ByteString -> 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.Bang instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.SourceUnpackedness instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.SourceStrictness instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.FunDep instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.Overlap 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.TySynEqn instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.TypeFamilyHead instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.FamilyResultSig instance Data.Store.Impl.Store Language.Haskell.TH.Syntax.InjectivityAnn 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.Store.Impl.Store (Data.Complex.Complex a0) instance Foreign.Storable.Storable a0 => Data.Store.Impl.Store (Data.Functor.Const.Const a0 b0) instance Foreign.Storable.Storable 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.Fingerprint.Type.Fingerprint 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.Store.Impl.Store (GHC.Ptr.FunPtr a0) instance Data.Store.Impl.Store (GHC.Ptr.Ptr a0) instance 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 System.Posix.Types.CCc instance Data.Store.Impl.Store System.Posix.Types.CDev instance Data.Store.Impl.Store System.Posix.Types.CGid instance Data.Store.Impl.Store System.Posix.Types.CIno instance Data.Store.Impl.Store System.Posix.Types.CMode instance Data.Store.Impl.Store System.Posix.Types.CNlink instance Data.Store.Impl.Store System.Posix.Types.COff instance Data.Store.Impl.Store System.Posix.Types.CPid instance Data.Store.Impl.Store System.Posix.Types.CRLim instance Data.Store.Impl.Store System.Posix.Types.CSpeed instance Data.Store.Impl.Store System.Posix.Types.CSsize instance Data.Store.Impl.Store System.Posix.Types.CTcflag instance Data.Store.Impl.Store System.Posix.Types.CUid instance Data.Store.Impl.Store System.Posix.Types.Fd 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 (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.Generic (Data.Store.Internal.StaticSize n a) instance (Data.Data.Data a, GHC.TypeLits.KnownNat 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 (GHC.Arr.Ix i, Data.Store.Impl.Store i, Data.Store.Impl.Store e) => Data.Store.Impl.Store (GHC.Arr.Array i e) instance (GHC.Arr.Ix i, Data.Array.Base.IArray Data.Array.Base.UArray e, Data.Store.Impl.Store i, Data.Store.Impl.Store e) => Data.Store.Impl.Store (Data.Array.Base.UArray i e) 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) -- | This module provides utilities which help ensure that we aren't -- attempting to de-serialize data that is an older or newer version. The -- WithVersion utility wraps up a datatype along with a version -- tag. This version tag can either be provided by the user -- (namedVersionConfig), or use a computed hash -- (hashedVersionConfig). -- -- The magic here is using an SYB traversal (Data) to get the -- structure of all the data-types involved. This info is rendered to -- text and hashed to yield a hash which describes it. -- -- NOTE that this API is still quite new and so is likely to break -- compatibility in the future. It should also be expected that the -- computed hashes may change between major version bumps, though this -- will be minimized when directly feasible. module Data.Store.Version newtype StoreVersion StoreVersion :: ByteString -> StoreVersion [unStoreVersion] :: StoreVersion -> ByteString data WithVersion a WithVersion :: a -> StoreVersion -> WithVersion a -- | Configuration for the version checking of a particular type. data VersionConfig a VersionConfig :: Maybe String -> Maybe String -> Set String -> Map String String -> VersionConfig a -- | When set, specifies the hash which is expected to be computed. [vcExpectedHash] :: VersionConfig a -> Maybe String -- | When set, specifies the name to instead use to tag the data. [vcManualName] :: VersionConfig a -> Maybe String -- | DataTypes to ignore. [vcIgnore] :: VersionConfig a -> Set String -- | Allowed renamings of datatypes, useful when they move. [vcRenames] :: VersionConfig a -> Map String String hashedVersionConfig :: String -> VersionConfig a namedVersionConfig :: String -> String -> VersionConfig a wrapVersion :: Data a => VersionConfig a -> Q Exp checkVersion :: Data a => VersionConfig a -> Q Exp data VersionCheckException VersionCheckException :: StoreVersion -> StoreVersion -> VersionCheckException [expectedVersion] :: VersionCheckException -> StoreVersion [receivedVersion] :: VersionCheckException -> StoreVersion instance GHC.Show.Show Data.Store.Version.VersionCheckException instance GHC.Generics.Generic (Data.Store.Version.VersionConfig a) instance Data.Data.Data a => Data.Data.Data (Data.Store.Version.VersionConfig a) instance GHC.Show.Show (Data.Store.Version.VersionConfig a) instance GHC.Classes.Eq (Data.Store.Version.VersionConfig a) instance GHC.Generics.Generic (Data.Store.Version.WithVersion a) instance Data.Data.Data a => Data.Data.Data (Data.Store.Version.WithVersion a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Store.Version.WithVersion a) instance GHC.Show.Show a => GHC.Show.Show (Data.Store.Version.WithVersion a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Store.Version.WithVersion a) instance Data.Store.Impl.Store Data.Store.Version.StoreVersion instance GHC.Generics.Generic Data.Store.Version.StoreVersion instance Data.Data.Data Data.Store.Version.StoreVersion instance GHC.Classes.Ord Data.Store.Version.StoreVersion instance GHC.Show.Show Data.Store.Version.StoreVersion instance GHC.Classes.Eq Data.Store.Version.StoreVersion instance Data.Store.Impl.Store a => Data.Store.Impl.Store (Data.Store.Version.WithVersion a) instance GHC.Exception.Exception Data.Store.Version.VersionCheckException -- | 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. -- -- Safety of this function depends on correctness of the Store -- instance. If size returns a. The good news is that this isn't -- an issue if you use well-tested manual instances (such as those from -- this package) combined with auomatic definition of instances. 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 -- | 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, Generic a, GStoreSize (Rep 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, Generic a, GStorePoke (Rep a)) => a -> Poke () -- | Serialized a value from bytes, throwing exceptions if it encounters -- invalid data or runs out of input bytes. peek :: (Store a, Generic a, GStorePeek (Rep 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 -- | Poke actions are useful for building sequential serializers. -- -- They are actions which write values to bytes into memory specified by -- a Ptr base. The Applicative and Monad instances -- make it easy to write serializations, by keeping track of the -- Offset of the current byte. They allow you to chain Poke -- action such that subsequent Pokes write into subsequent -- portions of the output. data Poke a :: * -> * -- | Peek actions are useful for building sequential deserializers. -- -- They are actions which read from memory and construct values from it. -- The Applicative and Monad instances make it easy to -- chain these together to get more complicated deserializers. This -- machinery keeps track of the current Ptr and end-of-buffer -- Ptr. data Peek a :: * -> * class GStoreSize f class GStorePoke f class GStorePeek f -- | 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 -- | Throws a PeekException. 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. -- -- Each message starts with a fixed magic number, in order to detect -- (randomly) invalid data. 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 object, or a request for more input. type PeekMessage i m a = FT ((->) i) m a -- | Given some sort of input, fills the ByteBuffer with it. -- -- The Int is how many bytes we'd like: this is useful when the -- filling function is fillFromFd, where we can specify a max -- size. type FillByteBuffer i m = ByteBuffer -> Int -> i -> m () -- | Decode some object from a ByteBuffer, by first reading its -- header, and then the actual data. peekMessage :: (MonadIO m, Store a) => FillByteBuffer i m -> ByteBuffer -> PeekMessage i m (Message a) -- | Decode a Message from a ByteBuffer and an action that -- can get additional inputs 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 :: (Store a, MonadIO m) => FillByteBuffer i m -> ByteBuffer -> m (Maybe i) -> m (Maybe (Message a)) -- | Decode some Message from a ByteBuffer, by first reading -- its header, and then the actual Message. peekMessageBS :: (MonadIO m, Store a) => ByteBuffer -> PeekMessage ByteString m (Message a) decodeMessageBS :: (MonadIO m, Store a) => ByteBuffer -> m (Maybe ByteString) -> m (Maybe (Message a)) -- | We use this type as a more descriptive unit to signal that more input -- should be read from the Fd. -- -- This data-type is only available on POSIX systems (essentially, -- non-windows) data ReadMoreData ReadMoreData :: ReadMoreData -- | Peeks a message from a _non blocking_ Fd. -- -- This function is only available on POSIX systems (essentially, -- non-windows) peekMessageFd :: (MonadIO m, Store a) => ByteBuffer -> Fd -> PeekMessage ReadMoreData m (Message a) -- | Decodes all the message using registerFd to find out when a -- Socket is ready for reading. -- -- This function is only available on POSIX systems (essentially, -- non-windows) decodeMessageFd :: (MonadIO m, Store a) => ByteBuffer -> Fd -> m (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 Data.Store.Streaming.ReadMoreData instance GHC.Classes.Eq Data.Store.Streaming.ReadMoreData 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 TypeHash. 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 TypeHash. 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 -- | Deprecated: Use of Data.Store.TypeHash isn't recommended, as the -- hashes are too unstable for most uses. Please instead consider using -- Data.Store.Version. See -- https://github.com/fpco/store/issues/53 mkHasTypeHash :: Type -> Q [Dec] -- | Deprecated: Use of Data.Store.TypeHash isn't recommended, as the -- hashes are too unstable for most uses. Please instead consider using -- Data.Store.Version. See -- https://github.com/fpco/store/issues/53 mkManyHasTypeHash :: [Q Type] -> Q [Dec] combineTypeHashes :: [TypeHash] -> TypeHash 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 -- | Deprecated: Use of Data.Store.TypeHash isn't recommended, as the -- hashes are too unstable for most uses. Please instead consider using -- Data.Store.Version. See -- https://github.com/fpco/store/issues/53 mkHasTypeHash :: Type -> Q [Dec] -- | Deprecated: Use of Data.Store.TypeHash isn't recommended, as the -- hashes are too unstable for most uses. Please instead consider using -- Data.Store.Version. See -- https://github.com/fpco/store/issues/53 mkManyHasTypeHash :: [Q Type] -> Q [Dec]