pukkamustard/guile-cbor - Codeberg.org
pukkamustard
guile-cbor
Fork
You've already forked guile-cbor
Code
Issues
Pull requests
Projects
Releases
Packages
Wiki
Activity
No description
10
commits
branch
tag
96
KiB
Scheme
88.9%
Makefile
7.5%
M4
3.6%
Find a file
2021-03-01 12:08:44 +01:00
.reuse
initial commit.
2020-12-31 15:29:58 +01:00
build-aux
cbor: basic encoder and decoder
2021-01-02 18:46:38 +01:00
doc
info: initial info doc
2021-02-28 15:05:41 +01:00
LICENSES
initial commit.
2020-12-31 15:29:58 +01:00
tests
(cbor): Move everyhing to a single module
2021-02-28 14:39:54 +01:00
.gitignore
initial commit.
2020-12-31 15:29:58 +01:00
AUTHORS
cbor: basic encoder and decoder
2021-01-02 18:46:38 +01:00
cbor.scm
info: initial info doc
2021-02-28 15:05:41 +01:00
ChangeLog
cbor: basic encoder and decoder
2021-01-02 18:46:38 +01:00
configure.ac
tree-wide: Add SPDX headers
2021-01-14 10:36:45 +01:00
COPYING
initial commit.
2020-12-31 15:29:58 +01:00
guix.scm
guix.scm: fix indent and rewrite description
2021-03-01 12:08:44 +01:00
HACKING
initial commit.
2020-12-31 15:29:58 +01:00
hall.scm
(cbor): Move everyhing to a single module
2021-02-28 14:39:54 +01:00
Makefile.am
(cbor): Move everyhing to a single module
2021-02-28 14:39:54 +01:00
NEWS
cbor: basic encoder and decoder
2021-01-02 18:46:38 +01:00
pre-inst-env.in
cbor: basic encoder and decoder
2021-01-02 18:46:38 +01:00
README
initial commit.
2020-12-31 15:29:58 +01:00
README.org
README: better example
2021-03-01 11:48:33 +01:00
README.org
guile-cbor
Usage
Native Scheme Values <-> CBOR data items
Todos
Extended Generic Data Models
IEEE 754 Half-Precision Floats
null and undefined
Indefinite Length Byte Strings and Text Strings
Indefinite Length Arrays and Maps with streaming support
License
- mode: org; coding: utf-8; -
guile-cbor is a Guile implementation of CBOR (Concise Binary Object Representation) as specified by
RFC8949
Usage
The
(cbor)
module provides
scm->cbor
and
cbor->scm
that can be used to encode native Scheme values to CBOR and vice-versa:
use-modules
cbor
rnrs
bytevectors
))
scm->cbor
42
#vu8(24 42)
cbor->scm
scm->cbor
42
))
42
A more complete example of all the things that can be encoded:
define
cbor-encoded
scm->cbor
vector
((
"a"
"b"
3.141
))
string->utf8
"Hello CBOR!"
make-cbor-tag
32
"https://example.com"
vector
2.1
3.2
"Hi"
#t
#f
))))
cbor-encoded
#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)
cbor->scm
cbor-encoded
#(1 2 3 ((1 . "a") (2 . "b") (3 . 3.141)) #vu8(72 101 108 108 111 32 67 66 79 82 33) #< number: 32 content: "https://example.com"> #(2.1 3.2 "Hi" #t #f))
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
Native Scheme
CBOR
Note
positive integer
unsigned integer (major type 0)
negative integer
negative integer (major type 0)
bytevector
byte string (major type 2)
string
text string (major type 3)
vector
array (major type 4)
See also how
guile-json
maps arrays
alist
map (major type 5)

tagged data item (major type 6)
A Scheme record is used for CBOR tags
IEEE 754 Half-Precision Float (major type 7)
Can not be parsed (FIXME)
real
IEEE 754 Double-Precision Float (major type 7)
Scheme reals are always encoded as CBOR double precision floats
real
IEEE 754 Single-Precision Float (major type 7)
CBOR single precision floats are parsed as Scheme real numbers
#f
false (major type 7, simple value 20)
#t
true (major type 7, simple value 21)
#nil
empty array (major type 4)
This should be encoded to null (major type 7, simple value 22) (FIXME)

Indefinite-Length Arrays and Maps
A Scheme record is used to encode indefinite-length arrays and maps. Arrays or maps of indefinite length are decoded to simple vectors or alists.
Note that IEEE 754 Half-Precision Floats can currently not be parsed as there is no native Guile support.
Todos
TODO
Extended Generic Data Models
Currently not the full "extended generic data model" is supported (only simple values
#f
#t
are supported).
It might be nice to support the full extended generic data model (bignums, decimal fractions, bigfloats and date/time tags).
TODO
IEEE 754 Half-Precision Floats
Currenlty there is no support for encoding or decoding IEEE 754 Half-precision floats. This is due to the fact that there is no support for half-precision floats in Guile.
TODO
null and undefined
Currentlly guile-cbor can not properly encode null and undefined.
TODO
Indefinite Length Byte Strings and Text Strings
Currently no support.
TODO
Indefinite Length Arrays and Maps with streaming support
Currently guile-cbor uses the

record type to encode arrays/maps as indefinite length CBOR values. This does not enable encoding streams of CBOR values. It would be nice to have an interface to SRFI-158 generators.
License
GPL-3.0-or-later see
/pukkamustard/guile-cbor/src/branch/main/COPYING