Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Working with capnproto lists
- Working with capnproto Text and Data values.
- Working with messages
- Manipulating the root object of a message
- Marshalling data into and out of messages
- IO
- Type aliases for common contexts
- Converting between messages, Cap'N Proto values, and raw bytes
- Managing resource limits
- Freezing and thawing values
- Building messages in pure code
- Re-exported from Data.Default, for convienence.
This module re-exports the most commonly used functionality from other modules in the library.
Users getting acquainted with the library are *strongly* encouraged to read the Data.Capnp.Tutorial module before anything else.
Synopsis
- class ListElem msg e where
- data List msg e
- class ListElem (MutMsg s) e => MutListElem s e where
- data Data msg
- dataBytes :: ReadCtx m msg => Data msg -> m ByteString
- data Text msg
- textBytes :: ReadCtx m msg => Text msg -> m ByteString
- data ConstMsg
- class Monad m => Message m msg where
- data Segment msg
- data MutMsg s
- newMessage :: WriteCtx m s => m (MutMsg s)
- getRoot :: (FromStruct msg a, ReadCtx m msg) => msg -> m a
- newRoot :: (ToStruct (MutMsg s) a, Allocate s a, WriteCtx m s) => MutMsg s -> m a
- setRoot :: (ToStruct (MutMsg s) a, WriteCtx m s) => a -> m ()
- class Decerialize a where
- type Cerial msg a
- class Decerialize a => Cerialize s a where
- module Data.Capnp.IO
- type WriteCtx m s = (PrimMonad m, s ~ PrimState m, MonadThrow m)
- type ReadCtx m msg = (Message m msg, MonadThrow m, MonadLimit m)
- type RWCtx m s = (ReadCtx m (MutMsg s), WriteCtx m s)
- module Data.Capnp.Convert
- module Data.Capnp.TraversalLimit
- module Data.Mutable
- data PureBuilder s a
- createPure :: Thaw a => Int -> (forall s. PureBuilder s (Mutable s a)) -> Either SomeException a
- def :: Default a => a
Working with capnproto lists
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
Working with capnproto Text and Data values.
A blob of bytes (Data
in capnproto's schema language). The argument
to the data constructor is a slice into the message, containing the raw
bytes.
dataBytes :: ReadCtx m msg => Data msg -> m ByteString Source #
Convert a Data
to a ByteString
.
A textual string (Text
in capnproto's schema language). On the wire,
this is NUL-terminated. The encoding should be UTF-8, but the library
does not verify this; users of the library must do validation themselves, if
they care about this.
Rationale: validation would require doing an up-front pass over the data, which runs counter to the overall design of capnproto.
textBytes :: ReadCtx m msg => Text msg -> m ByteString Source #
Convert a Text
to a ByteString
, comprising the raw bytes of the text
(not counting the NUL terminator).
Working with messages
A read-only capnproto message.
ConstMsg
is an instance of the generic Message
type class. its
implementations of toByteString
and fromByteString
are O(1);
the underlying bytes are not copied.
Instances
class Monad m => Message m msg where Source #
A Message
is a (possibly read-only) capnproto message. It is
parameterized over a monad in which operations are performed.
numSegs :: msg -> m Int Source #
numSegs
gets the number of segments in a message.
internalGetSeg :: msg -> Int -> m (Segment msg) Source #
gets the segment at index internalGetSeg
message indexindex
in message
. Most callers should use the getSegment
wrapper, instead
of calling this directly.
numWords :: Segment msg -> m Int Source #
Get the length of the segment, in units of 64-bit words.
slice :: Int -> Int -> Segment msg -> m (Segment msg) Source #
extracts a sub-section of the segment,
starting at index slice
start length segmentstart
, of length length
.
read :: Segment msg -> Int -> m Word64 Source #
reads a 64-bit word from the segement at the
given index. Consider using read
segment indexgetWord
on the message, instead of
calling this directly.
fromByteString :: ByteString -> m (Segment msg) Source #
Convert a ByteString to a segment.
toByteString :: Segment msg -> m ByteString Source #
Convert a segment to a byte string.
Instances
Monad m => Message m ConstMsg Source # | |
Defined in Data.Capnp.Message numSegs :: ConstMsg -> m Int Source # internalGetSeg :: ConstMsg -> Int -> m (Segment ConstMsg) Source # numWords :: Segment ConstMsg -> m Int Source # slice :: Int -> Int -> Segment ConstMsg -> m (Segment ConstMsg) Source # read :: Segment ConstMsg -> Int -> m Word64 Source # fromByteString :: ByteString -> m (Segment ConstMsg) Source # toByteString :: Segment ConstMsg -> m ByteString Source # | |
(PrimMonad m, s ~ PrimState m) => Message m (MutMsg s) Source # | |
Defined in Data.Capnp.Message numSegs :: MutMsg s -> m Int Source # internalGetSeg :: MutMsg s -> Int -> m (Segment (MutMsg s)) Source # numWords :: Segment (MutMsg s) -> m Int Source # slice :: Int -> Int -> Segment (MutMsg s) -> m (Segment (MutMsg s)) Source # read :: Segment (MutMsg s) -> Int -> m Word64 Source # fromByteString :: ByteString -> m (Segment (MutMsg s)) Source # toByteString :: Segment (MutMsg s) -> m ByteString Source # |
A MutMsg
is a mutable capnproto message. The type parameter s
is the
state token for the instance of PrimMonad
in which the message may be
modified.
Due to mutabilty, the implementations of toByteString
and fromByteString
must make full copies, and so are O(n) in the length of the segment.
Instances
newMessage :: WriteCtx m s => m (MutMsg s) Source #
Allocate a new empty message.
Manipulating the root object of a message
getRoot :: (FromStruct msg a, ReadCtx m msg) => msg -> m a Source #
getRoot
returns the root object of a message.
newRoot :: (ToStruct (MutMsg s) a, Allocate s a, WriteCtx m s) => MutMsg s -> m a Source #
newRoot
allocates and returns a new value inside the message, setting
it as the root object of the message.
setRoot :: (ToStruct (MutMsg s) a, WriteCtx m s) => a -> m () Source #
setRoot
sets its argument to be the root object in its message.
Marshalling data into and out of messages
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
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
IO
module Data.Capnp.IO
Type aliases for common contexts
type WriteCtx m s = (PrimMonad m, s ~ PrimState m, MonadThrow m) Source #
WriteCtx
is the context needed for most write operations.
type ReadCtx m msg = (Message m msg, MonadThrow m, MonadLimit m) Source #
Type (constraint) synonym for the constraints needed for most read operations.
Converting between messages, Cap'N Proto values, and raw bytes
module Data.Capnp.Convert
Managing resource limits
module Data.Capnp.TraversalLimit
Freezing and thawing values
module Data.Mutable
Building messages in pure code
data PureBuilder s a Source #
PureBuilder
is a monad transformer stack with the instnaces needed
manipulate mutable messages.
is morally equivalent
to PureBuilder
s a'LimitT (
CatchT
(ST
s)) a
Instances
createPure :: Thaw a => Int -> (forall s. PureBuilder s (Mutable s a)) -> Either SomeException a Source #
creates a capnproto value in pure code according
to createPure
limit mm
, then freezes it without copying. If m
calls throwM
then
createPure
returns a Left
with the exception.