From b8229f9ddeb2ee89ea254d8ad286b05745d30617 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 23 Nov 2020 13:55:40 +0100 Subject: [PATCH] Code simplification for writing JSON::Any values. --- src/cbor/encoder.cr | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/cbor/encoder.cr b/src/cbor/encoder.cr index c6d436b..92678b4 100644 --- a/src/cbor/encoder.cr +++ b/src/cbor/encoder.cr @@ -11,34 +11,7 @@ class CBOR::Encoder end def write(j : JSON::Any) - # Test each possible value of JSON::Any - case j - when .as_bool? - write j.as_bool - when .as_i? - write j.as_i - when .as_i64? - write j.as_i64 - when .as_f? - write j.as_f - when .as_f32? - write j.as_f32 - when .as_s? - write j.as_s - when .as_a? - write j.as_a - when .as_h? - write j.as_h - else - # JSON::Any ".as_bool?" function fails. - case j.raw - when Bool - write j.as_bool - when Nil - else - raise "Unknown kind of JSON: #{j.raw}" - end - end + write j.raw end def write(value : Nil | Nil.class, use_undefined : Bool = false)