Closed twigbranch closed 5 years ago
Yes! There are a number of CBOR tags that aren't very well meshed with the data types available in Ruby yet. We are actually in the process of filling that matrix in at this very moment, please see https://github.com/cbor-wg/CBORbis/wiki/Implementation-matrix
(Question: Would you prefer CBOR tag 0 or tag 1 for objects of Ruby type Date
?)
I'll have to think about the question (new to CBOR). But, yes, ultimately, it would be great if it could act as a drop in replacement for to_json.
I would prefer CBOR tag 1 in most cases, but for the cases where I'd prefer the string (tag 0), I don't know how I'd say so.
Basically, you add a to_cbor
method to the object that you want to encode in CBOR. This can be done by adding the method to its class (Date or Time), or by adding a method just to the object (e.g., by extending it with a Module that has the desired method). I probably should write some example code into the docs...
https://gist.github.com/cabo/fb2f6ea30f1158b63e6c5649beabfc75 has some examples.
NoMethodError: undefined method
to_cbor' for Fri, 30 Aug 2013:Date`Shouldn't Date be supported?