Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src-tests/suite.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
(deftest test-serialize-deserialize ()
(let* ((original (make-instance 'rpcq::|RPCRequest|
:|method| "test-method"
:|params| (make-hash-table)
:|params| (alexandria:alist-hash-table
'(("one-half" . 1/2)))
:|id| "test-id"))
(cloned (rpcq::deserialize (rpcq::serialize original))))
(is (typep cloned 'rpcq::|RPCRequest|))
(is (string= (rpcq::|RPCRequest-id| original) (rpcq::|RPCRequest-id| cloned)))
(is (string= (rpcq::|RPCRequest-method| original) (rpcq::|RPCRequest-method| cloned)))))
(is (string= (rpcq::|RPCRequest-method| original) (rpcq::|RPCRequest-method| cloned)))
(is (= 0.5 (gethash "one-half" (rpcq::|RPCRequest-params| cloned))))))
3 changes: 3 additions & 0 deletions src/rpcq.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The input strings are assumed to be FORMAT-compatible, so sequences like ~<newli
(defmethod %serialize ((payload string))
payload)

(defmethod %serialize ((payload rational))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about specializing on ratio instead of rational?

(%serialize (float payload)))

(defmethod %serialize ((payload hash-table))
(let ((hash (make-hash-table :test #'equal)))
(loop :for k :being :the :hash-keys :of payload
Expand Down