Decode simple value (Bool or Nil).

remotes/dev/pr-bools
Karchnu 2020-11-26 17:05:22 +01:00
parent b0c62f89c8
commit ac1d67d60e
2 changed files with 23 additions and 6 deletions

View File

@ -42,6 +42,14 @@ class CBOR::Decoder
end
end
def read_simple_value : Bool?
case token = @current_token
when Token::SimpleValueT
finish_token!
token.value.to_t
end
end
def read_string : String
case token = @current_token
when Token::StringT

View File

@ -208,13 +208,22 @@ end
def Union.new(decoder : CBOR::Decoder)
{% begin %}
case decoder.current_token
{% if T.includes? Nil %}
{% if T.includes? Nil || T.includes? Bool %}
when CBOR::Token::SimpleValueT
return decoder.read_nil
{% end %}
# This value could be either a boolean or nil.
value = decoder.read_simple_value
case value
{% if T.includes? Bool %}
when CBOR::Token::SimpleValueT
return decoder.read_bool
when Bool
return value
{% end %}
{% if T.includes? Nil %}
when Nil
return nil
{% end %}
else
raise "value is neither Bool or Nil"
end
{% end %}
{% if T.includes? String %}
when CBOR::Token::StringT