diff --git a/spec/cbor/from_cbor_spec.cr b/spec/cbor/from_cbor_spec.cr index a19b252..ffd4d49 100644 --- a/spec/cbor/from_cbor_spec.cr +++ b/spec/cbor/from_cbor_spec.cr @@ -19,6 +19,8 @@ describe "CBOR helpers on basic types" do {Time, Bytes[0xc1, 0xfb, 0x41, 0xd4, 0x52, 0xd9, 0xec, 0x20, 0x00, 0x00], Time.unix_ms((BigFloat.new(1363896240.5) * 1000).to_u64)}, {Nil, Bytes[0xf6], nil}, {Nil, Bytes[0xf7], nil}, + {Float32, Bytes[0xfb, 0x3f, 0xf1, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9a], 1.1_f32}, + {Float64, Bytes[0xfa, 0x47, 0xc3, 0x50, 0x00], 100000.0_f64}, ] tests.each do |tt| diff --git a/src/cbor/from_cbor.cr b/src/cbor/from_cbor.cr index a4bad61..6855e41 100644 --- a/src/cbor/from_cbor.cr +++ b/src/cbor/from_cbor.cr @@ -19,6 +19,14 @@ end {% end %} +{% for size in [32, 64] %} + + def Float{{size.id}}.new(decoder : CBOR::Decoder) + decoder.read_float.to_f{{size.id}} + end + +{% end %} + def Bool.new(decoder : CBOR::Decoder) decoder.read_bool end