cl-bson

https://github.com/EuAndreh/cl-bson.git

git clone 'https://github.com/EuAndreh/cl-bson.git'

(ql:quickload :cl-bson)
4

cl-BSON

Quicklisp Build Status Circle CI Coverage Status

Inspired by cl-mongo and mongo-cl-driver.

API and documentation generated by the (awesome) Codex.

Usage

Setup

* (ql:quickload :cl-bson)
; => (:CL-BSON)
* (in-package :cl-bson)
; => #<PACKAGE "CL-BSON">
* (named-readtables:in-readtable bson-syntax)
; => big alist of readtables...
* (enable-printers)
; => NIL

;; Obs.: all read macros are just optional ;)

Main API

The main functions are encode and decode: ```lisp * (decode (encode (make-document))) ; ⇒ #d(“_id” #i(057DCB554D4143C13A5FBB91)) * (encode #d(:a-key 'a-value)) ; ⇒ #(24 0 0 0 2 65 45 75 69 89 0 7 0 0 0 65 45 86 65 76 85 69 0 0) * (decode *) ; ⇒ #d(“A-KEY” “A-VALUE”)

Examples from the FAQ: ```lisp ;; Original: {“hello”: “world”} * (encode #d(“hello” “world”)) ; ⇒ #(22 0 0 0 2 104 101 108 108 111 0 5 0 0 0 119 111 114 108 100 0 0)

;; Since the example is in hexadecimal base: * (map 'vector (lambda (_) (let ((print-base 16)) (princ-to-string _))) *)

;; Output:

(“16” “0” “0” “0”

“2” “68” “65” “6C” “6C” “6F” “0” “6” “0” “0” “0” “77” “6F” “72” “6C” “64” “0” “0”)

\x16\x00\x00\x00 // total document size \x02 // 0x02 = type String hello\x00 // field name \x06\x00\x00\x00world\x00 // field value \x00 // 0x00 = type EOO (‘end of object’)

;; Original: {“BSON”: [“awesome”, 5.05, 1986]} * (encode #d(“BSON” #(“awesome” 5.05d0 1986)))

(49 0 0 0 4 66 83 79 78 0 38 0 0 0 2 48 0 8 0 0 0 97 119 101 115 111 109 101 0 1 49 0 51 51 51 51 51 51 20 64 16 50 0 194 7 0 0 0 0)

;; To hexadecimal: * (map 'vector (lambda (_) (let ((print-base 16)) (princ-to-string _))) *)

;; Output:

(“31” “0” “0” “0”

“4” “42” “53” “4F” “4E” “0” “26” “0” “0” “0” “2” “30” “0” “8” “0” “0” “0” “61” “77” “65” “73” “6F” “6D” “65” “0” “1” “31” “0” “33” “33” “33” “33” “33” “33” “14” “40” “10” “32” “0” “C2” “7” “0” “0” “0” “0”)

\x31\x00\x00\x00 \x04BSON\x00 \x26\x00\x00\x00 \x02\x30\x00\x08\x00\x00\x00awesome\x00 \x01\x31\x00\x33\x33\x33\x33\x33\x33\x14\x40 \x10\x32\x00\xc2\x07\x00\x00 \x00 \x00 ```

Check the detailed explanation of the last example.

Dependencies

This library depends on: + arrow-macros + babel + cl-intbytes + fast-io + ieee-floats + let-over-lambda + local-time + named-readtables + rutils + trivial-shell

The test package uses the prove test library, and the documentation uses the Codex documentation library.

Installation

(ql:quickload :cl-bson)

Bugs

If you find any bug or inconsistency in the code, or if you find it too hard to use, please, feel free to open an issue.

Tests

This library is tested under SBCL and CCL Common Lisp implementations.

To run all the defined tests, use: lisp * (asdf:test-system :cl-bson) ; prints lots of (colorful) stuff... ; => T Tests are ran with Travis CI and Circle CI using cl-travis, CIM, cl-coveralls and Roswell. Check it out!

Author

License

LLGPL.