summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-03-01 11:48:33 +0100
committerpukkamustard <pukkamustard@posteo.net>2021-03-01 11:48:33 +0100
commit59c7daee451ed06fc242cb7784380e8c94282813 (patch)
treeb93b5dd76d9b32d65557b05ffdd5216ecd8b5864
parente669f5083d051cb2d19d033a01b493fdd6c53fa6 (diff)
README: better example
-rw-r--r--README.org29
1 files changed, 22 insertions, 7 deletions
diff --git a/README.org b/README.org
index 986394d..8b411be 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,5 @@
-*- mode: org; coding: utf-8; -*-
+#+PROPERTY: header-args:scheme :session *guile-cbor-repl* :eval never-export
#+TITLE: guile-cbor
@@ -9,7 +10,8 @@ guile-cbor is a Guile implementation of CBOR (Concise Binary Object Representati
The ~(cbor)~ module provides ~scm->cbor~ and ~cbor->scm~ that can be used to encode native Scheme values to CBOR and vice-versa:
#+BEGIN_SRC scheme
-(use-modules (cbor))
+(use-modules (cbor)
+ (rnrs bytevectors))
(scm->cbor 42)
#+END_SRC
@@ -19,8 +21,6 @@ The ~(cbor)~ module provides ~scm->cbor~ and ~cbor->scm~ that can be used to enc
#+BEGIN_SRC scheme
-(use-modules (cbor))
-
(cbor->scm
(scm->cbor 42))
#+END_SRC
@@ -28,16 +28,31 @@ The ~(cbor)~ module provides ~scm->cbor~ and ~cbor->scm~ that can be used to enc
#+RESULTS:
: 42
+A more complete example of all the things that can be encoded:
+
#+BEGIN_SRC scheme
-(use-modules (cbor))
+(define cbor-encoded
+ (scm->cbor
+ (vector 1 2 3
+ '((1 . "a") (2 . "b") (3 . 3.141))
+ (string->utf8 "Hello CBOR!")
+ (make-cbor-tag 32 "https://example.com")
+ (vector 2.1 3.2 "Hi" #t #f))))
+
+cbor-encoded
+#+END_SRC
-(scm->cbor (vector 1 2 3 4))
+#+RESULTS:
+: #vu8(135 1 2 3 163 1 97 97 2 97 98 3 251 64 9 32 196 155 165 227 84 75 72 101 108 108 111 32 67 66 79 82 33 216 32 115 104 116 116 112 115 58 47 47 101 120 97 109 112 108 101 46 99 111 109 133 251 64 0 204 204 204 204 204 205 251 64 9 153 153 153 153 153 154 98 72 105 245 244)
+
+#+BEGIN_SRC scheme
+(cbor->scm cbor-encoded)
#+END_SRC
#+RESULTS:
-: #vu8(132 1 2 3 4)
+: #(1 2 3 ((1 . "a") (2 . "b") (3 . 3.141)) #vu8(72 101 108 108 111 32 67 66 79 82 33) #<<cbor-tag> number: 32 content: "https://example.com"> #(2.1 3.2 "Hi" #t #f))
-See also the Info documentation.
+~guile-cbor~ also provides procedures for directly reading and writing CBOR from and to ports. See the info documentation.
** Native Scheme Values <-> CBOR data items