New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a Transit transport #61

Closed
bbatsov opened this Issue Oct 22, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@bbatsov
Copy link
Contributor

bbatsov commented Oct 22, 2018

That's a pretty similar issue to #60.

Having a Transit transport would simplify the lives of people using Clojure/ClojureScript/Java clients for nREPL. It's main advantage over an EDN transport would be that Transit defines a more flexible format that's also JSON friendly.

It should be pretty easy to create a transport based on the default bencode transport that simply uses Transit instead of bencode. Here's the implementation of the bencode transport as a reference:

(defn bencode
  "Returns a Transport implementation that serializes messages
   over the given Socket or InputStream/OutputStream using bencode."
  ([^Socket s] (bencode s s s))
  ([in out & [^Socket s]]
   (let [in (PushbackInputStream. (io/input-stream in))
         out (io/output-stream out)]
     (fn-transport
      #(let [payload (rethrow-on-disconnection s (bencode/read-bencode in))
             unencoded (<bytes (payload "-unencoded"))
             to-decode (apply dissoc payload "-unencoded" unencoded)]
         (merge (dissoc payload "-unencoded")
                (when unencoded {"-unencoded" unencoded})
                (<bytes to-decode)))
      #(rethrow-on-disconnection s
                                 (locking out
                                   (doto out
                                     (bencode/write-bencode %)
                                     .flush)))
      (fn []
        (if s
          (.close s)
          (do
            (.close in)
            (.close out))))))))

As this transport will require an extra dep it'd be best to implement it as a tiny separate library in the nREPL org.

@pfeodrippe

This comment has been minimized.

Copy link
Contributor

pfeodrippe commented Dec 12, 2018

Let's close this o/

@bbatsov bbatsov closed this Dec 12, 2018

@bbatsov

This comment has been minimized.

Copy link
Contributor Author

bbatsov commented Dec 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment