Decode floats

dev
Alberto Restifo 2020-04-24 22:57:24 +02:00
parent 830981ba5d
commit 839a41dd84
2 changed files with 10 additions and 0 deletions

View File

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

View File

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