Capnp.GenHelpers.Pure

Description

This module provides various helpers used by generated code; developers are not expected to invoke them directly.

These helpers are only used by the high-level api. Capnp.GenHelpers defines helpers used by the low-level api.

Synopsis

# Documentation

A valid implementation for Default for any type that meets the given constraints.

getRoot :: (FromStruct msg a, ReadCtx m msg) => msg -> m a Source #

getRoot returns the root object of a message.

createPure :: (MonadThrow m, Thaw a) => WordCount -> (forall s. PureBuilder s (Mutable s a)) -> m a Source #

createPure limit m creates a capnproto value in pure code according to m, then freezes it without copying. If m calls throwM then createPure rethrows the exception in the specified monad.

toPurePtrConst :: Decerialize a => Cerial ConstMsg a -> a Source #

convert a low-level value to a high-level one. This is not safe against malicious or invalid input; it is used for declaring top-level constants.

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.