Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
Crystal bindings for libcbor.
to_cbor
)from_cbor
)JSON.mapping
-style APIMake sure you have libcbor
installed. Your package manager probably provides it.
Add the dependency to your shard.yml
:
dependencies:
CBOR:
github: woodruffw/cbor.cr
Run shards install
require "CBOR"
# Note: These print binary data!
puts -1.to_cbor
puts nil.to_cbor
puts true.to_cbor
puts 3.14.to_cbor
puts "abc".to_cbor
puts [1, 2, 3, "four"].to_cbor
puts Hash{"key" => "value"}.to_cbor
puts Time.now.to_cbor
CBOR.cr does not currently provide a mapping-style API, like the core JSON or YAML modules.
To serialize custom objects to CBOR, define #to_h
on them and use to_h.to_cbor
.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)