-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters