Time added for CBOR::Any and CBOR::Encoder.

remotes/dev/pr-cbor-any-and-time
Karchnu 2020-11-25 23:35:18 +01:00
parent 0f25c5da9f
commit 199c8c0d79
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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