Decode Nil
parent
307da9658d
commit
830981ba5d
|
@ -17,6 +17,8 @@ describe "CBOR helpers on basic types" do
|
|||
Time::Format::RFC_3339.parse("2013-03-21T20:04:00Z")},
|
||||
{Time, Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0], Time.unix(1363896240)},
|
||||
{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},
|
||||
]
|
||||
|
||||
tests.each do |tt|
|
||||
|
|
|
@ -58,6 +58,18 @@ class CBOR::Decoder
|
|||
end
|
||||
end
|
||||
|
||||
def read_nil : Nil
|
||||
read_type(Token::SimpleValueT) do |token|
|
||||
case token.value
|
||||
when SimpleValue::Null,
|
||||
SimpleValue::Undefined
|
||||
nil
|
||||
else
|
||||
unexpected_token(token, "SimpleValue::Null or SimpleValue::Undefined")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private def finish_token!
|
||||
@current_token = @lexer.next_token
|
||||
end
|
||||
|
|
|
@ -23,11 +23,15 @@ def Bool.new(decoder : CBOR::Decoder)
|
|||
decoder.read_bool
|
||||
end
|
||||
|
||||
def Nil.new(decoder : CBOR::Decoder)
|
||||
decoder.read_nil
|
||||
end
|
||||
|
||||
def Slice.new(decoder : CBOR::Decoder)
|
||||
decoder.read_bytes.to_slice
|
||||
end
|
||||
|
||||
# Reads the CBOR values a time. The value must be surrounded by a time tag as
|
||||
# Reads the CBOR values as a time. The value must be surrounded by a time tag as
|
||||
# specified by [Section 2.4.1 of RFC 7049][1].
|
||||
#
|
||||
# [1]: https://tools.ietf.org/html/rfc7049#section-2.4.1
|
||||
|
|
Loading…
Reference in New Issue