Skip to content

Commit

Permalink
add jsonrpc-stdio-patch.lisp
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Dec 10, 2023
1 parent b44e508 commit adc4243
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions frontends/jsonrpc/jsonrpc-stdio-patch.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(in-package :jsonrpc/transport/stdio)

(defmethod send-message-using-transport ((transport stdio-transport) connection message)
(let ((json (trivial-utf-8:string-to-utf-8-bytes
(with-output-to-string (s)
(yason:encode message s))))
(stream (connection-socket connection)))
(format stream "Content-Length: ~A~C~C~:*~:*~C~C"
(length json)
#\Return
#\Newline)
(write-sequence json stream)
(force-output stream)))

(defmethod receive-message-using-transport ((transport stdio-transport) connection)
(let* ((stream (connection-socket connection))
(headers (read-headers stream))
(length (ignore-errors (parse-integer (gethash "content-length" headers)))))
(when length
(let ((body
(with-output-to-string (out)
(loop
:for c := (read-char stream)
:do (write-char c out)
(decf length (babel:string-size-in-octets (string c)))
(when (<= length 0)
(return))))))
(parse-message body)))))
3 changes: 2 additions & 1 deletion frontends/jsonrpc/lem-jsonrpc.asd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"trivial-utf-8"
"jsonrpc/transport/stdio")
:serial t
:components ((:file "utils")
:components ((:file "jsonrpc-stdio-patch")
(:file "utils")
(:file "view")
(:file "main")))

Expand Down

0 comments on commit adc4243

Please sign in to comment.