From 2b90d41087a5bcd3447932e62dbfd57ac02d66e4 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Mon, 22 Jul 2019 10:46:24 -0700 Subject: [PATCH] Allow (de)serialization of the :false value --- src-tests/suite.lisp | 10 +++++++++- src/rpcq.lisp | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src-tests/suite.lisp b/src-tests/suite.lisp index 2eb312f..590a44d 100644 --- a/src-tests/suite.lisp +++ b/src-tests/suite.lisp @@ -96,4 +96,12 @@ (is (string= (rpcq::|RPCWarning-body| warning) (rpcq::|RPCWarning-body| cloned-warning))) (is (string= (rpcq::|RPCWarning-kind| warning) - (rpcq::|RPCWarning-kind| cloned-warning))))))) + (rpcq::|RPCWarning-kind| cloned-warning)))))) + + (let ((rpcq::*use-false* nil)) + (is (null (rpcq:deserialize (rpcq:serialize :false)))) + (is (null (rpcq:deserialize (rpcq:serialize nil))))) + + (let ((rpcq::*use-false* t)) + (is (eql :false (rpcq:deserialize (rpcq:serialize :false)))) + (is (null (rpcq:deserialize (rpcq:serialize nil)))))) diff --git a/src/rpcq.lisp b/src/rpcq.lisp index 1989e0a..339e586 100644 --- a/src/rpcq.lisp +++ b/src/rpcq.lisp @@ -43,6 +43,10 @@ ;; store all messages defined thus far in their namespace (defvar *messages* (make-hash-table :test 'equal)) +;; Wrapper for messagepack's treatment of false/nil. +(defvar *use-false* t + "Discriminate between a false value and a nil value. If set to NIL both :FALSE and NIL with serialize and deserialize into NIL.") + (defun clear-messages () "Clear the stored message definitions." (clrhash *messages*)) @@ -70,7 +74,8 @@ The input strings are assumed to be FORMAT-compatible, so sequences like ~