Decode simple value (Bool or Nil).
parent
0c8baf1ccd
commit
a058ab3ccf
|
@ -47,6 +47,14 @@ class CBOR::Decoder
|
||||||
end
|
end
|
||||||
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
|
def read_string : String
|
||||||
case token = @current_token
|
case token = @current_token
|
||||||
when Token::StringT
|
when Token::StringT
|
||||||
|
|
|
@ -218,13 +218,22 @@ end
|
||||||
def Union.new(decoder : CBOR::Decoder)
|
def Union.new(decoder : CBOR::Decoder)
|
||||||
{% begin %}
|
{% begin %}
|
||||||
case decoder.current_token
|
case decoder.current_token
|
||||||
{% if T.includes? Nil %}
|
{% if T.includes? Nil || T.includes? Bool %}
|
||||||
when CBOR::Token::SimpleValueT
|
when CBOR::Token::SimpleValueT
|
||||||
return decoder.read_nil
|
# This value could be either a boolean or nil.
|
||||||
{% end %}
|
value = decoder.read_simple_value
|
||||||
|
case value
|
||||||
{% if T.includes? Bool %}
|
{% if T.includes? Bool %}
|
||||||
when CBOR::Token::SimpleValueT
|
when Bool
|
||||||
return decoder.read_bool
|
return value
|
||||||
|
{% end %}
|
||||||
|
{% if T.includes? Nil %}
|
||||||
|
when Nil
|
||||||
|
return nil
|
||||||
|
{% end %}
|
||||||
|
else
|
||||||
|
raise "value is neither Bool or Nil"
|
||||||
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
{% if T.includes? String %}
|
{% if T.includes? String %}
|
||||||
when CBOR::Token::StringT
|
when CBOR::Token::StringT
|
||||||
|
|
Loading…
Reference in New Issue