mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 07:41:37 -05:00
jupyter-encode-message: Refactor
* jupyter-messages.el (jupyter-encode-message): Do it. (jupyter--message-header): Require MSG-ID argument. Given by `jupyter-encode-message'.
This commit is contained in:
parent
344e7b72ce
commit
0fb39492e3
1 changed files with 18 additions and 21 deletions
|
@ -78,16 +78,15 @@ Return a cons cell (IDENTS . REST-PARTS)."
|
||||||
else collect part into idents)
|
else collect part into idents)
|
||||||
(error "Message delimiter not in message list")))
|
(error "Message delimiter not in message list")))
|
||||||
|
|
||||||
(defun jupyter--message-header (session msg-type &optional msg-id)
|
(defun jupyter--message-header (session msg-type msg-id)
|
||||||
"Return a message header.
|
"Return a message header.
|
||||||
The `:session' key of the header will have its value set to
|
The `:session' key of the header will have its value set to
|
||||||
SESSION's ID, and its `:msg_type' will be set to MSG-TYPE. If
|
SESSION's ID, and its `:msg_type' will be set to MSG-TYPE. MSG-ID
|
||||||
MSG-ID is non-nil it is set to the value of the `:msg_id' key,
|
will be set to the value of the `:msg_id' key. The other fields
|
||||||
otherwise a new message ID is generated. The other fields of the
|
of the returned plist are `:version', `:username', and `:date'.
|
||||||
returned plist are `:version', `:username', and `:date'. They are
|
They are all set to appropriate default values."
|
||||||
all set to appropriate default values."
|
|
||||||
(list
|
(list
|
||||||
:msg_id (or msg-id (jupyter-new-uuid))
|
:msg_id msg-id
|
||||||
:msg_type msg-type
|
:msg_type msg-type
|
||||||
:version jupyter-protocol-version
|
:version jupyter-protocol-version
|
||||||
:username user-login-name
|
:username user-login-name
|
||||||
|
@ -202,7 +201,7 @@ The returned object has the same form as the object returned by
|
||||||
type
|
type
|
||||||
&key idents
|
&key idents
|
||||||
content
|
content
|
||||||
msg-id
|
(msg-id (jupyter-new-uuid))
|
||||||
parent-header
|
parent-header
|
||||||
metadata
|
metadata
|
||||||
buffers
|
buffers
|
||||||
|
@ -216,20 +215,18 @@ The returned object has the same form as the object returned by
|
||||||
(or content (setq content jupyter--empty-dict))
|
(or content (setq content jupyter--empty-dict))
|
||||||
(or parent-header (setq parent-header jupyter--empty-dict))
|
(or parent-header (setq parent-header jupyter--empty-dict))
|
||||||
(or metadata (setq metadata jupyter--empty-dict))
|
(or metadata (setq metadata jupyter--empty-dict))
|
||||||
|
(and (stringp idents) (setq idents (list idents)))
|
||||||
|
|
||||||
(let* ((header (jupyter--message-header session type msg-id))
|
(let ((parts (mapcar #'jupyter--encode
|
||||||
(msg-id (plist-get header :msg_id))
|
(list (jupyter--message-header session type msg-id)
|
||||||
(parts (mapcar #'jupyter--encode (list header
|
parent-header
|
||||||
parent-header
|
metadata
|
||||||
metadata
|
content))))
|
||||||
content))))
|
(nconc (cl-list* msg-id idents)
|
||||||
(cons msg-id
|
(cl-list* jupyter-message-delimiter
|
||||||
(append
|
(jupyter-sign-message session parts signer)
|
||||||
(when idents (if (stringp idents) (list idents) idents))
|
parts)
|
||||||
(list jupyter-message-delimiter
|
buffers)))
|
||||||
(jupyter-sign-message session parts signer))
|
|
||||||
parts
|
|
||||||
buffers))))
|
|
||||||
|
|
||||||
|
|
||||||
(cl-defun jupyter-decode-message (session parts &key (signer #'jupyter-hmac-sha256))
|
(cl-defun jupyter-decode-message (session parts &key (signer #'jupyter-hmac-sha256))
|
||||||
|
|
Loading…
Add table
Reference in a new issue