Simon Danisch / Feb 27 2019
with Andrea Amantini
CBOR
CBOR
pkg"add https://github.com/JuliaIO/CBOR.jl.git#sd-round_trip"
using CBOR
using Plots; plotly()
Custom Julia Types
println(CBOR.decode(read(cbor_pair↩)))
CBOR.decode(read(cbor_point↩)) == Point2f0(0, 1)
Closures:
a = 42 f = (x)-> a + x f(22)
f2 = CBOR.decode(CBOR.encode(f)) f2(22)
Dict with closure:
d = CBOR.decode(CBOR.encode(Dict("myclosure" => f))) d["myclosure"](22)
Random type containing Closure (TODO: doesn't yet work because of type missmatch)
d = CBOR.decode(CBOR.encode(f)) typeof(d)
using Serialization io = IOBuffer(); serialize(io, "asd" => f); seekstart(io); typeof(deserialize(io)) |> println
isbitstype(typeof("asd" => f))
pip install cbor2
import cbor2
bs = open(cbor_array↩, "rb"); result = cbor.loads(bs.read()); bs.close() result
bs = open(cbor_dict↩, "rb"); result = cbor.loads(bs.read()); bs.close() result
bs = open(cbor_string↩, "rb"); result = cbor.loads(bs.read()); bs.close() result
bs = open(cbor_tag↩, "rb"); result = cbor.loads(bs.read()); bs.close() result
result = cbor.loads(cbor.dumps((2,3,4))) type(result)
bs = open(nil↩, "rb"); result = cbor.loads(bs.read()); bs.close() result
bs = open(cbor_point↩, "rb"); result = cbor2.loads(bs.read()); bs.close() result
1. CBOR + Clojure
1.
CBOR + Clojure
{:deps { org.clojure/clojure {:mvn/version "1.10.0"} mvxcvi/clj-cbor {:mvn/version "0.7.1"} } }
deps.edn
Clojure
(require '[clj-cbor.core :as cbor])
(cbor/slurp cbor_array↩)
4[2,3,4,5]
(cbor/slurp cbor_dict↩)
2{"a"22"b"33}
(print (cbor/slurp cbor_point↩))