Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module defines several type classes concerning encoding and decoding values in the capnproto wire format (as well as instances for some basic types).
Note that much of this is unlikely to be used directly by developers. Typically these are either used internally by generated code, or transitively via higher level functions in the API. It is recommended to look elsewhere in the library for what you need, and refer to this module only when trying to understand what the class constraints on a function mean.
Synopsis
- class IsWord a where
- class ListElem msg e where
- data List msg e
- class ListElem (MutMsg s) e => MutListElem s e where
- class IsPtr msg a where
- class FromStruct msg a where
- class ToStruct msg a where
- class Allocate s e where
- class Decerialize a => Marshal a where
- class Decerialize a => Cerialize s a where
- class Decerialize a where
- type Cerial msg a
Documentation
Types that can be converted to and from a 64-bit word.
Anything that goes in the data section of a struct will have an instance of this.
fromWord :: Word64 -> a Source #
Convert from a 64-bit words Truncates the word if the type has less than 64 bits.
toWord :: a -> Word64 Source #
Convert to a 64-bit word.
Instances
IsWord Bool Source # | |
IsWord Double Source # | |
IsWord Float Source # | |
IsWord Int8 Source # | |
IsWord Int16 Source # | |
IsWord Int32 Source # | |
IsWord Int64 Source # | |
IsWord Word8 Source # | |
IsWord Word16 Source # | |
IsWord Word32 Source # | |
IsWord Word64 Source # | |
IsWord Word1 Source # | |
IsWord ElementSize Source # | |
Defined in Capnp.Capnp.Schema fromWord :: Word64 -> ElementSize Source # toWord :: ElementSize -> Word64 Source # | |
IsWord Side Source # | |
IsWord Exception'Type Source # | |
Defined in Capnp.Capnp.Rpc fromWord :: Word64 -> Exception'Type Source # toWord :: Exception'Type -> Word64 Source # |
class ListElem msg e where Source #
Types which may be stored as an element of a capnproto list.
length :: List msg e -> Int Source #
Get the length of a list.
index :: ReadCtx m msg => Int -> List msg e -> m e Source #
gets the index
i listi
th element of a list.
Instances
class ListElem (MutMsg s) e => MutListElem s e where Source #
Types which may be stored as an element of a *mutable* capnproto list.
setIndex :: RWCtx m s => e -> Int -> List (MutMsg s) e -> m () Source #
sets the setIndex
value i listi
th index in list
to @value
newList :: WriteCtx m s => MutMsg s -> Int -> m (List (MutMsg s) e) Source #
allocates and returns a new list of length
newList
msg sizesize
inside msg
.
Instances
class IsPtr msg a where Source #
Types that can be converted to and from an untyped pointer.
Note that this should not involve a marshalling step, and that decoding does not have to succeed, if the pointer is the wrong type.
TODO: split this into FromPtr and ToPtr, for symmetry with FromStruct and ToStruct?
fromPtr :: ReadCtx m msg => msg -> Maybe (Ptr msg) -> m a Source #
Convert an untyped pointer to an a
.
toPtr :: a -> Maybe (Ptr msg) Source #
Convert an a
to an untyped pointer.
Instances
class FromStruct msg a where Source #
Types that can be extracted from a struct.
fromStruct :: ReadCtx m msg => Struct msg -> m a Source #
Extract a value from a struct.
Instances
class ToStruct msg a where Source #
Types that can be converted to a struct.
Instances
class Allocate s e where Source #
Types which may be stored in a capnproto message, and have a fixed size.
This applies to typed structs, but not e.g. lists, because the length must be known to allocate a list.
Instances
class Decerialize a => Marshal a where Source #
Types which may be marshaled into a pre-allocated object in a message.
marshalInto :: RWCtx m s => Cerial (MutMsg s) a -> a -> m () Source #
Marshal a value into the pre-allocated object inside the message.
Note that caller must arrange for the object to be of the correct size. This is is not necessarily guaranteed; for example, list types must coordinate the length of the list.
Instances
class Decerialize a => Cerialize s a where Source #
Types which may be inserted into a message.
cerialize :: RWCtx m s => MutMsg s -> a -> m (Cerial (MutMsg s) a) Source #
Cerialize a value into the supplied message, returning the result.
cerialize :: (RWCtx m s, Marshal a, Allocate s (Cerial (MutMsg s) a)) => MutMsg s -> a -> m (Cerial (MutMsg s) a) Source #
Cerialize a value into the supplied message, returning the result.
Instances
class Decerialize a where Source #
Types which may be extracted from a message.
typically, instances of Decerialize
will be the algebraic data types
defined in generated code for the high-level API.
A variation on a
which is encoded in the message.
For the case of instances in generated high-level API code, this will be the low-level API analouge of the type.
decerialize :: ReadCtx m ConstMsg => Cerial ConstMsg a -> m a Source #
Extract the value from the message.