 
 
 (defn read-message [socket]
-  {:uuid (read-until-delimiter socket)
-   :signature (read-blob socket)
-   :header (cheshire/parse-string (read-blob socket) keyword)
+  {:uuid          (read-until-delimiter socket)
+   :signature     (read-blob socket)
+   :header        (cheshire/parse-string (read-blob socket) keyword)
    :parent-header (cheshire/parse-string (read-blob socket) keyword)
-   :metadata (cheshire/parse-string (read-blob socket) keyword)
-   :content (cheshire/parse-string (read-blob socket) keyword)})
+   :metadata      (cheshire/parse-string (read-blob socket) keyword)
+   :content       (cheshire/parse-string (read-blob socket) keyword)})
 
 (defn execute-request-handler [shell-socket iopub-socket executer]
   (let [execution-count (atom 0N)]

           [clj-time.format :as time-format]
           [com.keminglabs.zmq-async.core :refer [register-socket!]]
           [clojure.core.async :refer [sliding-buffer >! <! go chan close!]])
  (:import [org.jeromq ZMQ])
  (:gen-class :main true))

(defn prep-config [args]

(defn address [config service]
  (str (:transport config) "://" (:ip config) ":" (service config)))

(defn uuid [] (str (java.util.UUID/randomUUID)))

(def kernel-info-content
  {:protocol_version [4 1]
   :ipython_version  [3 1 0 "dev"]
   :language_version [1 7 0]
   :language         "clojure"})


(defn now []
  "Returns current ISO 8601 compliant date."
  (let [current-date-time (time/to-time-zone (time/now) (time/default-time-zone))]
    (time-format/unparse
      (time-format/with-zone (time-format/formatters :date-time-no-ms)
                             (.getZone current-date-time))
      current-date-time)))

(defn kernel-info-header [message]
  (let [header (cheshire/generate-string {:date     (get-in message [:header :date])
                                          :msg_id   (uuid)
                                          :username (get-in message [:header :username])
                                          :session  (get-in message [:header :session])
                                          :msg_type "kernel_info_reply"})]
    header))

(defn send-message-piece [socket msg]
  ;  (println "Sending piece " msg)
  (zmq/send socket (.getBytes msg) zmq/send-more))

(defn finish-message [socket msg]
  ;  (println "Sending message " msg)
  (zmq/send socket (.getBytes msg)))

(defn kernel-info-reply [message socket]
  (let [header (kernel-info-header message)
        parent_header (cheshire/generate-string (:header message))
        metadata (cheshire/generate-string {})
        content (cheshire/generate-string kernel-info-content)]
    (send-message-piece socket (get-in message [:header :session]))
    (send-message-piece socket "<IDS|MSG>")
    (send-message-piece socket "")
