Copyright | (c) Andrew Gibiansky, 2016 |
---|---|
License | MIT |
Maintainer | andrew.gibiansky@gmail.com |
Stability | stable |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module contains type and class definitions pertaining to handling Jupyter messages
internally. The types defined here are generally useful for the jupyter
library
but will not be useful for users of the library.
- data MessageHeader = MessageHeader {}
- newtype Username = Username Text
- newtype MessageType = MessageType {}
- class ToJSON v => IsMessage v where
- getMessageType :: v -> MessageType
- parseMessageContent :: MessageType -> Maybe (Object -> Parser v)
Message Metadata
data MessageHeader Source
A message header with some metadata.
The metadata has a variety of important information that pertains to the session maintained between the client and the frontend. In addition to metadata, the message headers are used to establish relationships between the messages: in particular, the message parent is used to determine which request a reply corresponds to.
In addition, the message type is sent as a string with the message header.
For more information about the message headers, read the section of the Jupyter messaging protocol about the wire protocol.
MessageHeader | |
|
A username represented as Text
, part of the MessageHeader
.
newtype MessageType Source
The type of a message, internally stored as a string.
Examples include execute_request
, comm_open
, and display_data
.
class ToJSON v => IsMessage v where Source
Jupyter messages are represented as a variety of datatypes, depending on where in the messaging
protocol the message is used (for instance, ClientRequest
or
Comm
).
Given any message, however, you need to be able to get a MessageType
for it, so that when
encoding the message onto the wire you can include the message type in the header. The
IsMessage
typeclass provides a single method, getMessageType
, which gets the message type of
any Jupyter message.
getMessageType :: v -> MessageType Source
Get the message type for a Jupyter message.
parseMessageContent :: MessageType -> Maybe (Object -> Parser v) Source
Get a parser for this message type.
If this message type does not correspond to one of the constructors for the data type v
, then
return Nothing
. Otherwise, return a parser that parses the message body into the given
datatype.
This is a slightly unusual but necessary interface, because the message type and the message body come in separate bytestrings, as they are separate blobs sent on the communication sockets. Thus, we must look first at the message type, and choose the JSON parser based on the message type.
IsMessage Comm Source | |
IsMessage KernelOutput Source | |
IsMessage ClientReply Source | |
IsMessage KernelRequest Source | |
IsMessage KernelReply Source | |
IsMessage ClientRequest Source | |
(IsMessage v1, IsMessage v2) => IsMessage (Either v1 v2) Source | Provide an This is particularly useful for dealing with the shell and iopub socket, where kernels and
clients can receive different types of messages on one socket (kernels can receive |