use_cbor_discriminator: now works with imbricated classes.
parent
a058ab3ccf
commit
bdc14a1d20
|
@ -2,9 +2,17 @@ class CBOR::Decoder
|
||||||
@lexer : Lexer
|
@lexer : Lexer
|
||||||
getter current_token : Token::T?
|
getter current_token : Token::T?
|
||||||
|
|
||||||
def reset
|
# Decode until a certain point in the history (use_cbor_discriminator helper).
|
||||||
|
def reset(value : Int32 | Int64 = 0)
|
||||||
@lexer.reset
|
@lexer.reset
|
||||||
@current_token = @lexer.next_token
|
while pos < value
|
||||||
|
@current_token = @lexer.next_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Give the current position in the decoder (use_cbor_discriminator helper).
|
||||||
|
def pos
|
||||||
|
@lexer.io.pos
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(input)
|
def initialize(input)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class CBOR::Lexer
|
class CBOR::Lexer
|
||||||
|
property io : IO
|
||||||
def self.new(slice : Bytes)
|
def self.new(slice : Bytes)
|
||||||
new IO::Memory.new(slice)
|
new IO::Memory.new(slice)
|
||||||
end
|
end
|
||||||
|
@ -8,8 +9,8 @@ class CBOR::Lexer
|
||||||
def initialize(@io : IO)
|
def initialize(@io : IO)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
def reset(value : Int32 | Int64 = 0)
|
||||||
@io.seek 0
|
@io.seek value
|
||||||
@eof = false
|
@eof = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -353,8 +353,9 @@ module CBOR
|
||||||
|
|
||||||
# SLOW. Read everything, get the type, read everything again.
|
# SLOW. Read everything, get the type, read everything again.
|
||||||
def self.new(decoder : ::CBOR::Decoder)
|
def self.new(decoder : ::CBOR::Decoder)
|
||||||
|
current_offset = decoder.pos
|
||||||
if v = decoder.read_value
|
if v = decoder.read_value
|
||||||
decoder.reset
|
decoder.reset current_offset
|
||||||
case v
|
case v
|
||||||
when Hash(CBOR::Type, CBOR::Type)
|
when Hash(CBOR::Type, CBOR::Type)
|
||||||
discriminator_value = v[{{field.id.stringify}}]?
|
discriminator_value = v[{{field.id.stringify}}]?
|
||||||
|
|
Loading…
Reference in New Issue