0.0
No commit activity in last 3 years
No release in over 3 years
Basic but extensible CBOR implementation for ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

CBOR Simple

gem 'cbor-simple'

A basic but extensible implementation of CBOR (RFC7049) in plain ruby.

Use just like JSON or YAML:

CBOR.dump(42)           # => "\x18\x2a"
CBOR.load("\x18\x2a")   # => 42

You can add custom tags like this:

CBOR.register_tag 0 do |raw|
  Time.iso8601(raw)
end

And add classes for dumping:

CBOR.register_class Time, 0 do |val|
  val.iso8601(6)
end

Custom tags can also be given as second parameter to load, however this should be considered unstable and might change in the future.

# Invert values tagged with 0x26 (nonstandard!)
CBOR.load("\xd8\x26\xf5", {0x26 => -> (raw) { !raw }})  # => false

Currently supported classes:

  • (Unsigned) Integers
  • Floats (single and double)
  • Byte / Textstring (also symbols)
  • Arrays
  • Hashes
  • BigDecimals
  • UUIDs (if the gem uuidtools is visible)
  • Times