Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Direct (de-)serialisation to / from raw memory.
The purpose of the typeclasses in this module is to abstract over data
structures that can expose the data they store as one or more raw Ptr
s,
without any additional memory copying or conversion to intermediate data
structures.
This is useful for transmitting data like KES SignKeys over a socket
connection: by accessing the memory directly and copying it into or out of
a file descriptor, without going through an intermediate ByteString
representation (or other data structure that resides in the GHC heap), we
can more easily assure that the data is never written to disk, including
swap, which is an important requirement for KES.
Synopsis
- data SizeCheckException = SizeCheckException {}
- sizeCheckFailed ∷ Int → Int → m ()
- class DirectDeserialise a where
- directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CChar → CSize → m ()) → m a
- class DirectSerialise a where
- directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CChar → CSize → m ()) → a → m ()
- directSerialiseTo ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → a → m Int
- directSerialiseToChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → a → m ()
- directSerialiseBuf ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → a → m Int
- directSerialiseBufChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → a → m ()
- directDeserialiseFrom ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → m (a, Int)
- directDeserialiseFromChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → m a
- directDeserialiseBuf ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → m (a, Int)
- directDeserialiseBufChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → m a
Documentation
data SizeCheckException Source #
Instances
sizeCheckFailed ∷ Int → Int → m () Source #
class DirectDeserialise a where Source #
Direct deserialization from raw memory.
directDeserialise f
should allocate a new value of type a
, and
call f
with a pointer to the raw memory to be filled. f
may be called
multiple times, for data structures that store their data in multiple
non-contiguous blocks of memory.
The order in which memory blocks are visited matters.
directDeserialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CChar → CSize → m ()) → m a Source #
Instances
class DirectSerialise a where Source #
Direct serialization to raw memory.
directSerialise f x
should call f
to expose the raw memory underyling
x
. For data types that store their data in multiple non-contiguous blocks
of memory, f
may be called multiple times, once for each block.
The order in which memory blocks are visited matters.
directSerialise ∷ (MonadST m, MonadThrow m) ⇒ (Ptr CChar → CSize → m ()) → a → m () Source #
Instances
directSerialiseTo ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → a → m Int Source #
Helper function for bounds-checked serialization. Verifies that no more than the maximum number of bytes are written, and returns the actual number of bytes written.
directSerialiseToChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → a → m () Source #
Helper function for size-checked serialization. Verifies that exactly the specified number of bytes are written.
directSerialiseBuf ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → a → m Int Source #
Helper function for the common use case of serializing to an in-memory buffer. Verifies that no more than the maximum number of bytes are written, and returns the actual number of bytes written.
directSerialiseBufChecked ∷ ∀ m a. DirectSerialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → a → m () Source #
Helper function for size-checked serialization to an in-memory buffer. Verifies that exactly the specified number of bytes are written.
directDeserialiseFrom ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → m (a, Int) Source #
Helper function for size-checked deserialization. Verifies that no more than the maximum number of bytes are read, and returns the actual number of bytes read.
directDeserialiseFromChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ (Int → Ptr CChar → CSize → m ()) → Int → m a Source #
Helper function for size-checked deserialization. Verifies that exactly the specified number of bytes are read.
directDeserialiseBuf ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → m (a, Int) Source #
Helper function for the common use case of deserializing from an in-memory buffer. Verifies that no more than the maximum number of bytes are read, and returns the actual number of bytes read.
directDeserialiseBufChecked ∷ ∀ m a. DirectDeserialise a ⇒ MonadST m ⇒ MonadThrow m ⇒ Ptr CChar → Int → m a Source #
Helper function for size-checked deserialization from an in-memory buffer. Verifies that exactly the specified number of bytes are read.