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
- class ListElem (MutMsg s) e => MutListElem s e where
- class FromPtr msg a where
- class ToPtr s a where
- class FromStruct msg a where
- fromStruct :: ReadCtx m msg => Struct msg -> m a
- class ToStruct msg a where
- class Allocate s e where
- class Decerialize a => Marshal a where
- marshalInto :: RWCtx m s => Cerial (MutMsg s) a -> a -> m ()
- class Decerialize a => Cerialize a where
- class Decerialize a where
- cerializeBasicVec :: (RWCtx m s, MutListElem s (Cerial (MutMsg s) a), Cerialize a) => MutMsg s -> Vector a -> m (List (MutMsg s) (Cerial (MutMsg s) a))
- cerializeCompositeVec :: (RWCtx m s, MutListElem s (Cerial (MutMsg s) a), Marshal a) => MutMsg s -> Vector a -> m (List (MutMsg s) (Cerial (MutMsg s) 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.Gen.Capnp.Schema fromWord :: Word64 -> ElementSize Source # toWord :: ElementSize -> Word64 Source # | |
IsWord Side Source # | |
IsWord Exception'Type Source # | |
Defined in Capnp.Gen.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.
listFromPtr :: ReadCtx m msg => msg -> Maybe (Ptr msg) -> m (List msg e) Source #
Convert an untyped list to a list of this type. May fail
with a SchemaViolationError
if the list does not have the
correct representation.
TODO: this is basically just fromPtr; refactor so this is less redundant.
toUntypedList :: List msg e -> List msg Source #
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 FromPtr msg a where Source #
Types that can be converted from an untyped pointer.
Note that decoding do not have to succeed, if the pointer is the wrong type.
fromPtr :: ReadCtx m msg => msg -> Maybe (Ptr msg) -> m a Source #
Convert an untyped pointer to an a
.
Instances
class ToPtr s a where Source #
Types that can be converted to an untyped pointer.
toPtr :: WriteCtx m s => MutMsg s -> a -> m (Maybe (Ptr (MutMsg s))) 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 a where Source #
Types which may be inserted into a message.
Nothing
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.
Instances
cerializeBasicVec :: (RWCtx m s, MutListElem s (Cerial (MutMsg s) a), Cerialize a) => MutMsg s -> Vector a -> m (List (MutMsg s) (Cerial (MutMsg s) a)) Source #
A valid implementation of cerialize
, which just cerializes the
elements of a list individually and puts them in the list.
Note that while this is *correct* for composite lists, it is inefficient,
since it will separately allocate the elements and then copy them into
the list, doing extra work and leaking space. See cerializeCompositeVec
.
cerializeCompositeVec :: (RWCtx m s, MutListElem s (Cerial (MutMsg s) a), Marshal a) => MutMsg s -> Vector a -> m (List (MutMsg s) (Cerial (MutMsg s) a)) Source #
A valid implementation of cerialize
, which allocates a list of the
correct size and then marshals the elements of a vector into the elements
of the list. This is more efficient for composite types than
cerializeBasicVec
, hence the name.