From df25f8269fb0a0859a1c7b893a8c1bd973962cac Mon Sep 17 00:00:00 2001 From: Karchnu Date: Wed, 25 Nov 2020 23:35:18 +0100 Subject: [PATCH] Time added for CBOR::Any and CBOR::Encoder. --- src/cbor/any.cr | 5 ++++- src/cbor/encoder.cr | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cbor/any.cr b/src/cbor/any.cr index f6a551b..36c2db9 100644 --- a/src/cbor/any.cr +++ b/src/cbor/any.cr @@ -28,7 +28,8 @@ struct CBOR::Any Int8 | UInt8 | Int16 | UInt16 | Int32 | UInt32 | Int64 | UInt64 | Int128 | Float32 | Float64 | Array(Any) | - Hash(String, Any) | Hash(Any, Any) + Hash(String, Any) | Hash(Any, Any) | + Time # Reads a `CBOR::Any` from a JSON::Any structure. def self.new(json : JSON::Any) @@ -47,6 +48,8 @@ struct CBOR::Any new value when String new value + when Time + new value when Array(Type) ary = [] of CBOR::Any diff --git a/src/cbor/encoder.cr b/src/cbor/encoder.cr index b355a59..67bf1c4 100644 --- a/src/cbor/encoder.cr +++ b/src/cbor/encoder.cr @@ -11,7 +11,6 @@ class CBOR::Encoder end def write(cbor : CBOR::Any) - # Test each possible value of CBOR::Any write cbor.raw end @@ -45,6 +44,12 @@ class CBOR::Encoder write(value.to_s) end + def write(value : Time) + write(CBOR::Tag::RFC3339Time) + write(value.to_rfc3339) + end + + def write(value : Float32 | Float64) case value when Float32