Skip to content

Instantly share code, notes, and snippets.

@tazjin
Created August 7, 2013 20:45
Show Gist options
  • Select an option

  • Save tazjin/6178474 to your computer and use it in GitHub Desktop.

Select an option

Save tazjin/6178474 to your computer and use it in GitHub Desktop.
(defun zeph-message-json (message-id receiver-id method-name &optional args)
"Creates the JSON array for a Zephyros message"
(json-encode `(,message-id ,receiver-id ,method-name ,(if args args))))
(defun zeph-send-msg (receiver-id method-name &optional args)
"Sends a message to the Zephyros connection and return the
message ID. The ID will always be an integer, if a string
is returned an error has occured."
(let* ((zephconn (get-process "zephconn"))
(msg-id (get-next-msg-id))
(msg-json (zeph-message-json msg-id
receiver-id
method-name
args))
(msg-length (number-to-string (length msg-json)))
(payload (concat msg-length "\n" msg-json )))
(if (eq (process-status (get-process "zephconn")) 'open)
(progn (process-send-string (get-process "zephconn") payload)
msg-id)
"zeph.el: Connection is not open"
)
msg-id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment