Skip to content

Commit

Permalink
Merge pull request #24 from jsulmont/use-null-for-xc0
Browse files Browse the repository at this point in the history
setting *use-null* to t decodes xc0 to 'null
  • Loading branch information
phmarek committed Jul 5, 2023
2 parents b305346 + e517d08 commit 8ff2060
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -16,7 +16,7 @@ for some Lisp data types (see below), simple tests.

### (C0) 'NIL'

This translates to `NIL` in Lisp directly, but see `C2` (`False`) below, too.
If `*use-null*` is kept `NIL`, `C0` translates to `NIL` in Lisp; else it translates to `'NULL` (symbol). Also see `C2` (`False`) below, too.

### (C2) 'False'

Expand Down
3 changes: 2 additions & 1 deletion cl-messagepack.lisp
Expand Up @@ -102,6 +102,7 @@
collect `(write-byte (ldb (byte 8 ,(* 8 i)) ,g-number) ,g-stream)))))

(defvar *use-false* nil)
(defvar *use-null* nil)
(defvar *symbol->int* nil)
(defvar *int->symbol* nil)
(defvar *symbol->int* nil)
Expand Down Expand Up @@ -374,7 +375,7 @@
(typed-data (read-byte stream)
(decode-byte-array len stream))))
((= #xc0 byte)
nil)
(if *use-null* 'null nil))
((= #xc3 byte)
t)
((= #xc2 byte)
Expand Down
1 change: 1 addition & 0 deletions package.lisp
Expand Up @@ -33,6 +33,7 @@
(:export encode encode-stream
decode decode-stream
write-hex
*use-null*
*symbol->int*
*int->symbol*
get-symbol-int-table
Expand Down
4 changes: 3 additions & 1 deletion tests.lisp
Expand Up @@ -164,7 +164,9 @@ encode properly."
(test decoding-bools
"Test that (equalp (decode (encode data)) data) for bools."
(is (eql t (mpk:decode (mpk:encode t))))
(is (eql nil (mpk:decode (mpk:encode nil)))))
(is (eql nil (mpk:decode (mpk:encode nil))))
(is (eql 'null (let ((mpk:*use-null* t))
(mpk:decode (mpk:encode nil))))))

(test decoding-floats
"Test that (equalp (decode (encode data)) data) for floats."
Expand Down

0 comments on commit 8ff2060

Please sign in to comment.